-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_test.py
More file actions
64 lines (52 loc) · 1.56 KB
/
simple_test.py
File metadata and controls
64 lines (52 loc) · 1.56 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
#!/usr/bin/env python3
"""
Simple test for free API key endpoint
"""
import subprocess
import time
import requests
import sys
import os
def test_endpoint():
"""Test the endpoint"""
try:
# Test the endpoint
url = "http://localhost:10000/auth/request-free-api-key"
data = {
"email": "test@example.com",
"name": "Test User",
"company": "Test Company"
}
print("Testing endpoint...")
response = requests.post(url, json=data, timeout=10)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
return response.status_code == 200
except Exception as e:
print(f"Error: {e}")
return False
if __name__ == "__main__":
# Start server in background
print("Starting server...")
env = os.environ.copy()
env['PATH'] = "/home/husni/project-permit-api/venv/bin:" + env.get('PATH', '')
server = subprocess.Popen(
["uvicorn", "app.api_server:app", "--host", "0.0.0.0", "--port", "10000"],
cwd="/home/husni/project-permit-api",
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# Wait for server to start
print("Waiting for server to start...")
time.sleep(5)
# Test endpoint
success = test_endpoint()
# Stop server
server.terminate()
server.wait()
if success:
print("✅ Test successful!")
else:
print("❌ Test failed!")
sys.exit(0 if success else 1)