-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_scraper.py
More file actions
executable file
·46 lines (39 loc) · 1.5 KB
/
test_scraper.py
File metadata and controls
executable file
·46 lines (39 loc) · 1.5 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
#!/usr/bin/env python3
import requests
import json
import sys
BASE_URL = "http://localhost:8800"
USERNAME = "klu2200031641"
def test_endpoint(endpoint, name):
print(f"\n{'='*60}")
print(f"Testing: {name}")
print(f"{'='*60}")
try:
response = requests.get(f"{BASE_URL}{endpoint}", timeout=30)
print(f"Status: {response.status_code}")
data = response.json()
print(json.dumps(data, indent=2))
return response.status_code == 200 and data.get('success', False)
except Exception as e:
print(f"Error: {e}")
return False
if __name__ == "__main__":
print(f"Testing CodeChef Scraper for user: {USERNAME}")
results = {
"Health Check": test_endpoint("/health", "Health Check"),
"Profile": test_endpoint(f"/api/profile/{USERNAME}", "Profile Data"),
"Ratings": test_endpoint(f"/api/ratings/{USERNAME}", "Ratings History"),
"Recent": test_endpoint(f"/api/recent/{USERNAME}", "Recent Submissions"),
"Whole Profile": test_endpoint(f"/api/whole/{USERNAME}", "Complete Profile"),
"Upcoming Contests": test_endpoint("/api/upcoming", "Upcoming Contests")
}
print(f"\n{'='*60}")
print("SUMMARY")
print(f"{'='*60}")
for test, passed in results.items():
status = "✓ PASS" if passed else "✗ FAIL"
print(f"{test:20} {status}")
total = len(results)
passed = sum(results.values())
print(f"\nTotal: {passed}/{total} tests passed")
sys.exit(0 if passed == total else 1)