forked from ShaikNagurShareef/AURA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agents.py
More file actions
86 lines (70 loc) · 2.54 KB
/
test_agents.py
File metadata and controls
86 lines (70 loc) · 2.54 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
import requests
import time
import json
import base64
BASE_URL = "http://localhost:8000"
def run_tests():
print("Starting Agent API Tests...")
# 1. Login to get token
print("\n[1] Logging in...")
login_data = {
"email": "test@example.com",
"password": "testpassword"
}
# Let's try to register first just in case
requests.post(f"{BASE_URL}/auth/register", json={
"email": "test@example.com",
"password": "testpassword",
"full_name": "Test User"
})
response = requests.post(f"{BASE_URL}/auth/login", json=login_data)
if response.status_code != 200:
print(f"❌ Login failed: {response.status_code} - {response.text}")
return
token = response.json().get("access_token")
headers = {"Authorization": f"Bearer {token}"}
print("✅ Login successful")
agents = [
"wellbeing",
"diagnostic",
"virtual_doctor",
"dietary",
"insurance",
"visualisation",
"orchestrator"
]
for agent in agents:
print(f"\n[{agent.upper()}] Testing Agent API...")
# Create session
session_resp = requests.post(
f"{BASE_URL}/sessions",
json={"agent_type": agent},
headers=headers
)
if session_resp.status_code != 201:
print(f"❌ Failed to create session for {agent}: {session_resp.status_code} - {session_resp.text}")
continue
session_id = session_resp.json().get("id")
print(f" ✅ Session created: {session_id}")
# Send chat message
chat_payload = {
"session_id": session_id,
"message": "Hello, this is an automated functional test. Please respond with a short confirmation message."
}
print(f" -> Sending message...")
start_time = time.time()
chat_resp = requests.post(
f"{BASE_URL}/agents/{agent}/chat",
json=chat_payload,
headers=headers
)
elapsed = time.time() - start_time
if chat_resp.status_code == 200:
resp_data = chat_resp.json()
reply_text = resp_data.get('reply') or resp_data.get('response') or str(resp_data)
print(f" ✅ Chat successful ({elapsed:.2f}s)")
print(f" -> Response: {reply_text[:100]}...")
else:
print(f" ❌ Chat failed: {chat_resp.status_code} - {chat_resp.text}")
if __name__ == "__main__":
run_tests()