-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_debug.py
More file actions
65 lines (55 loc) · 2.33 KB
/
Copy pathtest_api_debug.py
File metadata and controls
65 lines (55 loc) · 2.33 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
#!/usr/bin/env python3
"""
Test script to check the API endpoints and data flow
"""
import requests
import json
def test_api_endpoints():
base_url = "http://127.0.0.1:8000"
print("Testing API endpoints...")
# Test 1: Get modules
print("\n1. Testing GET /api/modules")
try:
response = requests.get(f"{base_url}/api/modules")
print(f"Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Modules found: {len(data) if isinstance(data, list) else 'Invalid data'}")
if isinstance(data, list) and data:
print(f"First module: {data[0].get('name', 'No name')} (ID: {data[0].get('id', 'No ID')})")
else:
print(f"Error: {response.text}")
except Exception as e:
print(f"Error testing modules: {e}")
# Test 2: Get user progress with a test user ID
test_user_id = "user_test_123456789_abcdefghi"
print(f"\n2. Testing GET /api/user-progress/{test_user_id}")
try:
response = requests.get(f"{base_url}/api/user-progress/{test_user_id}")
print(f"Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Progress entries: {len(data) if isinstance(data, list) else 'Invalid data'}")
if isinstance(data, list):
print(f"Progress data: {json.dumps(data, indent=2)}")
else:
print(f"Error: {response.text}")
except Exception as e:
print(f"Error testing user progress: {e}")
# Test 3: Test with actual browser user ID format
import time
import random
browser_user_id = f"user_{int(time.time() * 1000)}_{random.randint(100000000, 999999999)}"
print(f"\n3. Testing with browser-like user ID: {browser_user_id}")
try:
response = requests.get(f"{base_url}/api/user-progress/{browser_user_id}")
print(f"Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Progress entries: {len(data) if isinstance(data, list) else 'Invalid data'}")
else:
print(f"Error: {response.text}")
except Exception as e:
print(f"Error testing browser user ID: {e}")
if __name__ == "__main__":
test_api_endpoints()