Spaces:
Running
Running
File size: 2,052 Bytes
734b937 60e34d7 734b937 60e34d7 734b937 | 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 | """Test HTTP endpoints of the running server."""
import json
import requests
BASE = "http://127.0.0.1:8000"
print("=" * 50)
print(" HTTP Endpoint Tests")
print("=" * 50)
# 1. Health
r = requests.get(f"{BASE}/health")
assert r.status_code == 200
print(f"GET /health β {r.status_code} {r.json()}")
# 2. Tasks
r = requests.get(f"{BASE}/tasks")
assert r.status_code == 200
data = r.json()
assert data["total_tasks"] == 4
print(f"GET /tasks β {r.status_code}, {data['total_tasks']} tasks")
for t in data["tasks"]:
print(f" - {t['id']}: {t['name']} ({t['difficulty']})")
# 3. Reset
r = requests.post(f"{BASE}/reset", json={"task_id": "expense_audit", "seed": 42})
assert r.status_code == 200
obs = r.json()["observation"]
print(f"POST /reset β task={obs['task_id']}, docs={len(obs['documents']['expenses'])} expenses")
# 4. Step with findings
r = requests.post(f"{BASE}/step", json={
"action": {
"findings": [
{
"document_id": "EXP-010",
"error_type": "over_limit",
"description": "Meal 4500 exceeds 1500 limit",
},
{
"document_id": "EXP-011",
"error_type": "wrong_category",
"description": "Personal earbuds as Office Supplies",
}
],
"submit_final": True,
}
})
assert r.status_code == 200
result = r.json()
print(f"POST /step β done={result['done']}, reward={result['reward']}")
# 5. Grader
r = requests.get(f"{BASE}/grader")
assert r.status_code == 200
grader = r.json()
print(f"GET /grader β score={grader['score']}, P={grader['precision']}, R={grader['recall']}")
# 6. Test all 4 tasks work
for task_id in ["expense_audit", "invoice_match", "gst_reconciliation", "fraud_detection"]:
r = requests.post(f"{BASE}/reset", json={"task_id": task_id, "seed": 42})
assert r.status_code == 200
print(f"POST /reset({task_id}) β {r.status_code} β")
# 7. Rate limit test (should not be limited at 7 requests)
print("\nAll endpoint tests passed β")
|