#!/usr/bin/env python3 """ Test script to verify the dashboard implementation works correctly. """ import requests import time import sys def test_dashboard_endpoints(base_url="http://localhost:7860"): """Test all dashboard-related endpoints.""" print("Testing Seamo Species Dashboard") print("=" * 50) print(f"Base URL: {base_url}") tests = [ { "name": "Dashboard HTML", "url": f"{base_url}/", "expected_content": ["Seamo Species", "Upload Image", "dashboard.js"] }, { "name": "Static CSS", "url": f"{base_url}/static/css/main.css", "expected_content": [":root", "--primary-blue", ".btn"] }, { "name": "Static JS", "url": f"{base_url}/static/js/main.js", "expected_content": ["MarineAPI", "utils", "showNotification"] }, { "name": "API Health (existing)", "url": f"{base_url}/api/v1/health", "expected_json": ["status", "model_loaded"] }, { "name": "API Info (existing)", "url": f"{base_url}/api/v1/info", "expected_json": ["name", "version", "model_info"] } ] results = [] for test in tests: print(f"\n๐Ÿงช Testing: {test['name']}") print(f" URL: {test['url']}") try: response = requests.get(test['url'], timeout=10) if response.status_code == 200: print(f" โœ… Status: {response.status_code}") # Check content if 'expected_content' in test: content = response.text missing = [] for expected in test['expected_content']: if expected not in content: missing.append(expected) if missing: print(f" โŒ Missing content: {missing}") results.append(False) else: print(f" โœ… Content check passed") results.append(True) elif 'expected_json' in test: try: json_data = response.json() missing = [] for expected in test['expected_json']: if expected not in json_data: missing.append(expected) if missing: print(f" โŒ Missing JSON fields: {missing}") results.append(False) else: print(f" โœ… JSON structure check passed") results.append(True) except Exception as e: print(f" โŒ JSON parsing failed: {e}") results.append(False) else: results.append(True) else: print(f" โŒ Status: {response.status_code}") results.append(False) except requests.exceptions.ConnectionError: print(f" โŒ Connection failed - is the server running?") results.append(False) except Exception as e: print(f" โŒ Error: {e}") results.append(False) # Summary print("\n" + "=" * 50) print("๐ŸŽฏ Test Summary:") passed = sum(results) total = len(results) print(f" Passed: {passed}/{total}") print(f" Success Rate: {(passed/total)*100:.1f}%") if passed == total: print("All tests passed! Dashboard is ready.") return True else: print("Some tests failed. Check the implementation.") return False def main(): """Main test function.""" # Test with local server first print("Testing local development server...") local_success = test_dashboard_endpoints("http://localhost:7860") if len(sys.argv) > 1: # Test with provided URL test_url = sys.argv[1] print(f"\nTesting provided URL: {test_url}") remote_success = test_dashboard_endpoints(test_url) if remote_success: print(f"\nDashboard is live at: {test_url}") else: print(f"\nDashboard has issues at: {test_url}") print("\nNext steps:") print(" 1. Start the API: python start_api.py") print(" 2. Open browser: http://localhost:7860") print(" 3. Test with marine species images") print(" 4. Deploy to production") if __name__ == "__main__": main()