-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_test.py
More file actions
99 lines (87 loc) · 2.55 KB
/
quick_test.py
File metadata and controls
99 lines (87 loc) · 2.55 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
95
96
97
98
99
#!/usr/bin/env python3
"""
Quick test for API endpoints
"""
import requests
import time
import subprocess
import sys
import os
def test_endpoints():
"""Test all endpoints"""
base_url = "http://localhost:10000"
# Test health endpoint
try:
response = requests.get(f"{base_url}/health", timeout=5)
print(f"✅ Health: {response.status_code}")
except Exception as e:
print(f"❌ Health failed: {e}")
return False
# Test free API key endpoint
try:
data = {
"email": "test@example.com",
"name": "Test User",
"company": "Test Company"
}
response = requests.post(
f"{base_url}/api/v1/request-free-api-key",
json=data,
timeout=10
)
print(f"✅ Free API Key: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f" Response: {result.get('message', 'Success')}")
else:
print(f" Error: {response.text}")
except Exception as e:
print(f"❌ Free API Key failed: {e}")
# Test auth endpoint
try:
data = {
"email": "test@example.com",
"name": "Test User",
"company": "Test Company"
}
response = requests.post(
f"{base_url}/auth/request-free-api-key",
json=data,
timeout=10
)
print(f"✅ Auth Free API Key: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f" Response: {result.get('message', 'Success')}")
else:
print(f" Error: {response.text}")
except Exception as e:
print(f"❌ Auth Free API Key failed: {e}")
return True
def main():
# Start server
print("🚀 Starting server...")
env = os.environ.copy()
env['PATH'] = "/home/husni/project-permit-api/venv/bin:" + env.get('PATH', '')
server = subprocess.Popen(
["python", "start.py"],
cwd="/home/husni/project-permit-api",
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# Wait for server
print("⏳ Waiting for server to start...")
time.sleep(5)
# Test endpoints
print("🧪 Testing endpoints...")
success = test_endpoints()
# Stop server
print("🛑 Stopping server...")
server.terminate()
server.wait()
print("✅ Test completed!")
return success
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)