-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
119 lines (102 loc) · 4.35 KB
/
test_api.py
File metadata and controls
119 lines (102 loc) · 4.35 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
"""
Quick API test for HelixFlow Platform
Tests both HTTPS with TLS verification disabled and HTTP fallback
"""
import requests
import json
import sys
from urllib3.exceptions import InsecureRequestWarning
# Suppress TLS warnings for self-signed certificates
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
def test_api_gateway():
"""Test API Gateway endpoints"""
base_urls = [
"https://localhost:8443", # HTTPS with self-signed cert
"http://localhost:8080", # HTTP fallback if TLS fails
]
for base_url in base_urls:
print(f"\nTesting API Gateway at {base_url}")
try:
# Test health endpoint
print(" Testing health endpoint...")
response = requests.get(f"{base_url}/health", verify=False, timeout=5)
if response.status_code == 200:
print(f" ✅ Health: {response.status_code} - {response.text.strip()}")
else:
print(f" ❌ Health: {response.status_code}")
continue
# Test models endpoint
print(" Testing models endpoint...")
response = requests.get(f"{base_url}/v1/models", verify=False, timeout=5)
if response.status_code == 200:
models_data = response.json()
print(f" ✅ Models: {response.status_code} - Found {len(models_data.get('data', []))} models")
else:
print(f" ❌ Models: {response.status_code}")
# Test chat completion endpoint
print(" Testing chat completion...")
chat_data = {
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}],
"max_tokens": 50
}
response = requests.post(
f"{base_url}/v1/chat/completions",
json=chat_data,
verify=False,
timeout=10
)
if response.status_code == 200:
result = response.json()
message = result.get('choices', [{}])[0].get('message', {}).get('content', 'No content')
print(f" ✅ Chat: {response.status_code} - Response: {message[:50]}...")
else:
print(f" ❌ Chat: {response.status_code} - {response.text}")
print(f" 🎯 API Gateway working at {base_url}")
return True
except requests.exceptions.SSLError as e:
print(f" ⚠️ SSL Error: {e}")
continue
except requests.exceptions.ConnectionError as e:
print(f" ⚠️ Connection Error: {e}")
continue
except Exception as e:
print(f" ❌ Error: {e}")
continue
print(" ❌ Failed to connect to API Gateway on any endpoint")
return False
def test_auth_service():
"""Test Auth Service endpoints"""
print(f"\nTesting Auth Service at http://localhost:8082")
try:
# Test health endpoint
response = requests.get("http://localhost:8082/health", timeout=5)
if response.status_code == 200:
print(f" ✅ Auth Service Health: {response.status_code}")
else:
print(f" ❌ Auth Service Health: {response.status_code}")
return False
# Test login
login_data = {"username": "testuser", "password": "testpass"}
response = requests.post("http://localhost:8082/login", json=login_data, timeout=5)
if response.status_code in [200, 401]: # 401 is expected for invalid credentials
print(f" ✅ Auth Service Login: {response.status_code}")
else:
print(f" ❌ Auth Service Login: {response.status_code}")
return True
except Exception as e:
print(f" ❌ Auth Service Error: {e}")
return False
if __name__ == "__main__":
print("🚀 Testing HelixFlow Platform Services")
print("=" * 50)
api_success = test_api_gateway()
auth_success = test_auth_service()
print("\n" + "=" * 50)
if api_success and auth_success:
print("🎉 All services are working correctly!")
sys.exit(0)
else:
print("❌ Some services are not working properly")
sys.exit(1)