Repository navigation
Expand file tree
/
Copy pathverify_server.py
More file actions
58 lines (53 loc) · 2.18 KB
/
Copy pathverify_server.py
File metadata and controls
58 lines (53 loc) · 2.18 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
import urllib.request
import json
import sys
BASE_URL = "http://localhost:8000"
def test_health():
try:
url = f"{BASE_URL}/health"
print(f"Testing {url}...")
with urllib.request.urlopen(url) as response:
data = json.load(response)
print(f"Health Response: {data}")
if data.get("status") == "ok":
print("✅ Health Check Passed")
return True
except Exception as e:
print(f"❌ Health Check Failed: {e}")
return False
def test_start_hi():
try:
url = f"{BASE_URL}/api/decision/start"
print(f"Testing {url} with query 'hi'...")
data = json.dumps({"query": "hi"}).encode('utf-8')
req = urllib.request.Request(url, data=data, headers={'Content-Type': 'application/json'})
with urllib.request.urlopen(req) as response:
result = json.load(response)
print(f"Start 'hi' Response: {result}")
# We assume it should succeed now based on code allowing len >= 2
print("✅ Start 'hi' Handled")
except urllib.error.HTTPError as e:
print(f"ℹ️ Start 'hi' returned HTTP {e.code}: {e.read().decode()}")
if e.code == 400:
print("✅ Start 'hi' Rejected as expected (if logic changed)")
except Exception as e:
print(f"❌ Start 'hi' Failed: {e}")
def test_start_valid():
try:
url = f"{BASE_URL}/api/decision/start"
print(f"Testing {url} with valid query...")
data = json.dumps({"query": "Should I move to a new city?"}).encode('utf-8')
req = urllib.request.Request(url, data=data, headers={'Content-Type': 'application/json'})
with urllib.request.urlopen(req) as response:
result = json.load(response)
print(f"Start Valid Response Keys: {list(result.keys())}")
if "session_id" in result and "questions" in result:
print("✅ Start Valid Passed")
else:
print("❌ Start Valid verification failed")
except Exception as e:
print(f"❌ Start Valid Failed: {e}")
if __name__ == "__main__":
if test_health():
test_start_hi()
test_start_valid()