-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_api.py
More file actions
129 lines (108 loc) Β· 4.4 KB
/
validate_api.py
File metadata and controls
129 lines (108 loc) Β· 4.4 KB
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
#!/usr/bin/env python3
"""
API Endpoint Validator
Validates that all required API endpoints exist and work correctly.
Run this after any changes to the web app to ensure frontend integration works.
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from fastapi.testclient import TestClient
from skysolve_next.web.app import app
def validate_endpoints():
"""Validate all critical API endpoints"""
client = TestClient(app)
results = []
endpoints_to_test = [
# Core endpoints that JavaScript depends on
("GET", "/", "Root page"),
("GET", "/status", "Application status"),
("POST", "/mode", "Mode switching", {"mode": "test"}),
("GET", "/logs", "Log retrieval"),
("GET", "/settings", "Settings retrieval"),
("POST", "/settings", "Settings update", {"solver": {"solve_radius": 20.0}}),
("GET", "/worker-status", "Worker status"),
("POST", "/solve", "Image solving"),
("GET", "/solve", "Solve status"),
("POST", "/auto-solve", "Auto-solve toggle", {"enabled": False}),
("POST", "/auto-push", "Auto-push toggle", {"enabled": False}),
]
print("π Validating API endpoints...")
print("=" * 50)
for test_data in endpoints_to_test:
method = test_data[0]
endpoint = test_data[1]
description = test_data[2]
payload = test_data[3] if len(test_data) > 3 else None
try:
if method == "GET":
response = client.get(endpoint)
elif method == "POST":
response = client.post(endpoint, json=payload)
else:
response = None
if response and response.status_code != 404:
status = "β
PASS"
results.append(True)
else:
status = "β FAIL (404 Not Found)"
results.append(False)
except Exception as e:
status = f"β ERROR: {str(e)[:50]}..."
results.append(False)
print(f"{method:4} {endpoint:15} - {description:20} - {status}")
print("=" * 50)
passed = sum(results)
total = len(results)
print(f"Results: {passed}/{total} endpoints working")
if passed == total:
print("π All endpoints are working!")
return True
else:
print("β οΈ Some endpoints are missing or broken")
print(" This may cause frontend JavaScript errors")
return False
def validate_frontend_dependencies():
"""Check that specific endpoints the frontend JavaScript needs are working"""
client = TestClient(app)
print("\nπ― Validating frontend JavaScript dependencies...")
print("=" * 50)
# Test the exact workflow the frontend JavaScript performs
critical_tests = [
("Status Check", lambda: client.get("/status")),
("Mode Change", lambda: client.post("/mode", json={"mode": "test"})),
("Status Verification", lambda: client.get("/status")),
("Settings Load", lambda: client.get("/settings")),
("Log Retrieval", lambda: client.get("/logs?count=10")),
]
all_passed = True
for test_name, test_func in critical_tests:
try:
response = test_func()
if response.status_code in [200, 202]: # Accept both OK and Accepted
print(f"β
{test_name:20} - Status {response.status_code}")
else:
print(f"β {test_name:20} - Status {response.status_code}")
all_passed = False
except Exception as e:
print(f"β {test_name:20} - ERROR: {str(e)[:30]}...")
all_passed = False
print("=" * 50)
if all_passed:
print("π All frontend dependencies are working!")
print(" The web UI mode switching should work now")
else:
print("β οΈ Some frontend dependencies are broken")
print(" The web UI may not function correctly")
return all_passed
if __name__ == "__main__":
print("SkySolve Next API Endpoint Validator")
print("=" * 50)
basic_check = validate_endpoints()
frontend_check = validate_frontend_dependencies()
if basic_check and frontend_check:
print("\nπ All validations passed!")
sys.exit(0)
else:
print("\nπ₯ Some validations failed!")
sys.exit(1)