forked from garvnn/meetup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
94 lines (79 loc) · 3.08 KB
/
Copy pathtest_api.py
File metadata and controls
94 lines (79 loc) · 3.08 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
#!/usr/bin/env python3
"""
Test script for the PennApps Meetup API
Run this to test the backend functionality
"""
from typing import Dict, Any
import requests # type: ignore
API_BASE = "http://localhost:8000"
TIMEOUT = 10 # seconds
def test_health() -> None:
"""Test the health endpoint"""
print("🔍 Testing health endpoint...")
response = requests.get(f"{API_BASE}/health", timeout=TIMEOUT)
print(f"Status: {response.status_code}")
print(f"Response: {response.json()}")
print()
def test_accept_invite() -> None:
"""Test accepting an invite"""
print("🔍 Testing accept invite endpoint...")
# Test with demo token
data: Dict[str, str] = {
"token": "demo123abc",
"user_id": "test-user-123"
}
response = requests.post(f"{API_BASE}/accept_invite", json=data, timeout=TIMEOUT)
print(f"Status: {response.status_code}")
print(f"Response: {response.json()}")
print()
def test_soft_ban() -> None:
"""Test soft-ban functionality"""
print("🔍 Testing soft-ban endpoint...")
data: Dict[str, str] = {
"meetup_id": "demo-meetup-123",
"target_user_id": "bad-user-456",
"enacted_by": "moderator-789",
"reason": "Test soft-ban"
}
response = requests.post(f"{API_BASE}/soft_ban", json=data, timeout=TIMEOUT)
print(f"Status: {response.status_code}")
print(f"Response: {response.json()}")
print()
def test_debug_data() -> None:
"""Test debug endpoint to see mock data"""
print("🔍 Testing debug endpoint...")
response = requests.get(f"{API_BASE}/debug/mock-data", timeout=TIMEOUT)
print(f"Status: {response.status_code}")
if response.status_code == 200:
data: Dict[str, Any] = response.json()
print(f"Mock meetups: {len(data.get('meetups', {}))}")
print(f"Mock invite tokens: {len(data.get('invite_tokens', {}))}")
print(f"Mock memberships: {len(data.get('memberships', {}))}")
else:
print(f"Response: {response.json()}")
print()
if __name__ == "__main__":
print("🚀 Testing PennApps Meetup API")
print("=" * 50)
try:
test_health()
test_accept_invite()
test_soft_ban()
test_debug_data()
print("✅ All tests completed!")
print("\n📱 Next steps:")
print("1. Open Expo Go on your phone")
print("2. Scan the QR code from 'npx expo start'")
print("3. Test the deep link: pennapps://join/demo123abc")
print("4. Try creating a meetup and sharing the link")
except requests.exceptions.ConnectionError:
print("❌ Could not connect to API. Make sure the backend is running:")
print(" cd python-backend && source venv/bin/activate && uvicorn main:app --reload")
except requests.exceptions.Timeout:
print("❌ Request timed out. The API might be slow or unresponsive.")
except requests.exceptions.RequestException as e:
print(f"❌ Request error: {e}")
except ValueError as e:
print(f"❌ JSON parsing error: {e}")
except KeyError as e:
print(f"❌ Missing key in response: {e}")