Repository navigation
Expand file tree
/
Copy pathtest_api_quick.py
More file actions
66 lines (54 loc) · 2.28 KB
/
Copy pathtest_api_quick.py
File metadata and controls
66 lines (54 loc) · 2.28 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
#!/usr/bin/env python3
"""
Quick test for the snapshot API - for manual testing.
Run this after starting the server with: python main.py
"""
import requests
import json
BASE_URL = "http://localhost:8000"
def test_api():
print("🧪 Testing Snapshot API...")
# Test data
test_html = """<!DOCTYPE html>
<html>
<head><title>Fixed Test</title></head>
<body><h1>Database Fix Test</h1><p>This should work now!</p></body>
</html>"""
test_url = "https://www.example.com/fixed-test"
try:
# Test POST /api/snapshots
print("\n1️⃣ Testing POST /api/snapshots...")
response = requests.post(
f"{BASE_URL}/api/snapshots",
json={
"htmlContent": test_html,
"originalUrl": test_url
},
headers={"Content-Type": "application/json"}
)
if response.status_code == 201:
result = response.json()
snapshot_id = result.get("snapshotId")
print(f"✅ Created snapshot: {snapshot_id}")
# Test GET /api/snapshots/{snapshot_id}
print(f"\n2️⃣ Testing GET /api/snapshots/{snapshot_id}...")
get_response = requests.get(f"{BASE_URL}/api/snapshots/{snapshot_id}")
if get_response.status_code == 200:
get_result = get_response.json()
print("✅ Retrieved snapshot successfully")
print(f" - ID: {get_result.get('snapshotId')}")
print(f" - URL: {get_result.get('originalUrl')}")
print(f" - Created: {get_result.get('createdAt')}")
print(f" - HTML matches: {get_result.get('htmlContent') == test_html}")
else:
print(f"❌ Failed to retrieve snapshot: {get_response.status_code}")
print(f" Response: {get_response.text}")
else:
print(f"❌ Failed to create snapshot: {response.status_code}")
print(f" Response: {response.text}")
except requests.exceptions.ConnectionError:
print("❌ Could not connect to server. Make sure it's running on localhost:8000")
except Exception as e:
print(f"❌ Test failed: {e}")
if __name__ == "__main__":
test_api()