-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_token.py
More file actions
75 lines (60 loc) · 2.13 KB
/
Copy pathtest_token.py
File metadata and controls
75 lines (60 loc) · 2.13 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
#!/usr/bin/env python3
"""
Test script for token generation API
"""
import requests
import json
# API base URL
BASE_URL = "http://localhost:8000"
def test_generate_token():
"""Test the token generation endpoint"""
url = f"{BASE_URL}/api/tokens/generate-token"
# Test data
test_data = {
"patient_id": "patient_123"
}
try:
print(f"Testing token generation for patient: {test_data['patient_id']}")
response = requests.post(
url,
json=test_data,
headers={"Content-Type": "application/json"}
)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
result = response.json()
print("✅ Token generated successfully!")
print(f"Token Code: {result['token_code']}")
print(f"Patient ID: {result['patient_id']}")
print(f"Created At: {result['created_at']}")
print(f"Expires At: {result['expires_at']}")
else:
print("❌ Token generation failed!")
print(f"Error: {response.text}")
except requests.exceptions.ConnectionError:
print("❌ Connection error! Make sure the API server is running.")
except Exception as e:
print(f"❌ Error: {str(e)}")
def test_health_check():
"""Test the health check endpoint"""
url = f"{BASE_URL}/health"
try:
response = requests.get(url)
print(f"Health Check Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"✅ Health Check: {result['status']}")
else:
print("❌ Health check failed!")
except requests.exceptions.ConnectionError:
print("❌ Connection error! Make sure the API server is running.")
except Exception as e:
print(f"❌ Error: {str(e)}")
if __name__ == "__main__":
print("OneAI Backend API Test")
print("=" * 30)
# Test health check first
test_health_check()
print()
# Test token generation
test_generate_token()