-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_api.py
More file actions
executable file
·94 lines (85 loc) · 2.89 KB
/
test_api.py
File metadata and controls
executable file
·94 lines (85 loc) · 2.89 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
#!/usr/bin/env python3
"""
Quick test script for the Estimation Bot API
Run this after starting the server to test endpoints
"""
import requests
import json
BASE_URL = "http://localhost:8000"
def test_health():
"""Test health endpoint"""
print("Testing /api/v1/health...")
response = requests.get(f"{BASE_URL}/api/v1/health")
print(f"Status: {response.status_code}")
print(f"Response: {json.dumps(response.json(), indent=2)}")
print()
def test_features():
"""Test features endpoint"""
print("Testing /api/v1/features...")
response = requests.get(f"{BASE_URL}/api/v1/features")
print(f"Status: {response.status_code}")
data = response.json()
print(f"Total Features: {data.get('total_count', 0)}")
print(f"Features: {json.dumps(data.get('features', [])[:2], indent=2)}...")
print()
def test_estimate():
"""Test estimate endpoint"""
print("Testing /api/v1/estimate...")
payload = {
"requirements": "I need a client onboarding system with user authentication, dashboard, and payment processing",
"hourly_rate": 100.0,
"include_breakdown": True
}
response = requests.post(
f"{BASE_URL}/api/v1/estimate",
json=payload,
headers={"Content-Type": "application/json"}
)
print(f"Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Total Time: {data.get('total_time_hours')} hours")
print(f"Total Cost: ${data.get('total_cost'):.2f}")
print(f"Timeline: {data.get('timeline')}")
print(f"Breakdown Items: {len(data.get('breakdown', []))}")
print(f"Summary Preview: {data.get('summary', '')[:200]}...")
else:
print(f"Error: {response.text}")
print()
def test_chat():
"""Test chat endpoint"""
print("Testing /api/v1/chat...")
payload = {
"message": "What would it cost to build a simple client onboarding system?",
"conversation_history": []
}
response = requests.post(
f"{BASE_URL}/api/v1/chat",
json=payload,
headers={"Content-Type": "application/json"}
)
print(f"Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"Response Preview: {data.get('response', '')[:300]}...")
else:
print(f"Error: {response.text}")
print()
if __name__ == "__main__":
print("=" * 60)
print("Estimation Bot API Test Suite")
print("=" * 60)
print()
try:
test_health()
test_features()
test_estimate()
test_chat()
print("=" * 60)
print("All tests completed!")
print("=" * 60)
except requests.exceptions.ConnectionError:
print("ERROR: Could not connect to API.")
print("Make sure the server is running: uvicorn app.main:app --reload")
except Exception as e:
print(f"ERROR: {e}")