|
|
|
|
|
""" |
|
|
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}") |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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.""" |
|
|
|
|
|
|
|
|
print("Testing local development server...") |
|
|
local_success = test_dashboard_endpoints("http://localhost:7860") |
|
|
|
|
|
if len(sys.argv) > 1: |
|
|
|
|
|
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() |
|
|
|