-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_backend.py
More file actions
56 lines (49 loc) · 1.91 KB
/
Copy pathtest_backend.py
File metadata and controls
56 lines (49 loc) · 1.91 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
import requests
import json
def test_endpoints():
base_url = "http://localhost:8000/api"
print("Testing backend endpoints...")
# Test health check first
try:
response = requests.get(f"{base_url}/health")
print(f"Health check: {response.status_code}")
if response.status_code == 200:
print(f"Health data: {response.json()}")
except Exception as e:
print(f"Failed to connect to health endpoint: {e}")
# Test modules endpoint
try:
response = requests.get(f"{base_url}/modules")
print(f"Modules endpoint: {response.status_code}")
if response.status_code == 200:
print(f"Modules data: {response.json()}")
else:
print(f"Error: {response.text}")
except Exception as e:
print(f"Failed to connect to modules endpoint: {e}")
# Test question generation
try:
response = requests.post(f"{base_url}/practice/question",
json={"module_id": 1})
print(f"\nQuestion endpoint: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Question data keys: {list(data.keys())}")
print(f"Question text: {data.get('question', 'No question found')[:100]}...")
else:
print(f"Error: {response.text}")
except Exception as e:
print(f"Failed to connect to question endpoint: {e}")
# Test user progress
try:
response = requests.get(f"{base_url}/practice/progress")
print(f"\nProgress endpoint: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Progress data: {data}")
else:
print(f"Error: {response.text}")
except Exception as e:
print(f"Failed to connect to progress endpoint: {e}")
if __name__ == "__main__":
test_endpoints()