File size: 4,829 Bytes
32aa8db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/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()