-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_full_system.py
More file actions
151 lines (132 loc) Β· 5.13 KB
/
test_full_system.py
File metadata and controls
151 lines (132 loc) Β· 5.13 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
"""
Full system test for the MCP Chatbot application
Tests both backend API and verifies frontend is accessible
"""
import requests
import time
import json
import sys
def test_backend():
"""Test backend API endpoints"""
print("π§ Testing Backend API...")
# Test 1: Ping endpoint
try:
response = requests.get("http://localhost:8000/ping", timeout=5)
if response.status_code == 200:
print("β
Ping endpoint: PASS")
print(f" Response: {response.json()}")
else:
print(f"β Ping endpoint: FAIL (status {response.status_code})")
return False
except Exception as e:
print(f"β Ping endpoint: FAIL ({e})")
return False
# Test 2: API Documentation
try:
response = requests.get("http://localhost:8000/docs", timeout=5)
if response.status_code == 200:
print("β
API Documentation: PASS")
else:
print(f"β API Documentation: FAIL (status {response.status_code})")
except Exception as e:
print(f"β API Documentation: FAIL ({e})")
# Test 3: OpenAPI Spec
try:
response = requests.get("http://localhost:8000/openapi.json", timeout=5)
if response.status_code == 200:
openapi_data = response.json()
endpoints = list(openapi_data.get("paths", {}).keys())
print(f"β
OpenAPI Spec: PASS ({len(endpoints)} endpoints)")
print(f" Available endpoints: {', '.join(endpoints)}")
else:
print(f"β OpenAPI Spec: FAIL (status {response.status_code})")
except Exception as e:
print(f"β OpenAPI Spec: FAIL ({e})")
# Test 4: Chat endpoint (simple test)
try:
payload = {
"message": "Hello, this is a test message",
"conversation_id": "test-conv-123"
}
response = requests.post(
"http://localhost:8000/chat",
json=payload,
timeout=10,
headers={"Content-Type": "application/json"}
)
print(f"β
Chat endpoint: Response status {response.status_code}")
if response.status_code == 200:
print(" Chat endpoint is responding")
else:
print(f" Response: {response.text[:200]}...")
except Exception as e:
print(f"β Chat endpoint: FAIL ({e})")
return True
def test_frontend():
"""Test frontend accessibility"""
print("\nπ¨ Testing Frontend...")
# Test frontend accessibility
try:
response = requests.get("http://localhost:5173", timeout=5)
if response.status_code == 200:
html_content = response.text
if "react" in html_content.lower() or "vite" in html_content.lower():
print("β
Frontend: PASS (React app accessible)")
return True
else:
print("β Frontend: FAIL (unexpected content)")
return False
else:
print(f"β Frontend: FAIL (status {response.status_code})")
return False
except Exception as e:
print(f"β Frontend: FAIL ({e})")
return False
def test_cors():
"""Test CORS configuration"""
print("\nπ Testing CORS Configuration...")
try:
# Simulate a CORS preflight request
response = requests.options(
"http://localhost:8000/ping",
headers={
"Origin": "http://localhost:5173",
"Access-Control-Request-Method": "POST",
"Access-Control-Request-Headers": "Content-Type"
},
timeout=5
)
cors_headers = {
"access-control-allow-origin": response.headers.get("access-control-allow-origin"),
"access-control-allow-methods": response.headers.get("access-control-allow-methods"),
"access-control-allow-headers": response.headers.get("access-control-allow-headers")
}
if cors_headers["access-control-allow-origin"]:
print("β
CORS: PASS (properly configured)")
print(f" Allowed origins: {cors_headers['access-control-allow-origin']}")
else:
print("β CORS: FAIL (not properly configured)")
except Exception as e:
print(f"β CORS: FAIL ({e})")
def main():
print("π Starting Full System Test for MCP Chatbot")
print("=" * 50)
backend_ok = test_backend()
frontend_ok = test_frontend()
test_cors()
print("\n" + "=" * 50)
print("π Test Summary:")
print(f" Backend: {'β
PASS' if backend_ok else 'β FAIL'}")
print(f" Frontend: {'β
PASS' if frontend_ok else 'β FAIL'}")
if backend_ok and frontend_ok:
print("\nπ All systems are GO! Your ChatGPT-inspired MCP Chatbot is ready!")
print(" Frontend: http://localhost:5173")
print(" Backend API: http://localhost:8000")
print(" API Docs: http://localhost:8000/docs")
return 0
else:
print("\nβ οΈ Some issues detected. Check the logs above.")
return 1
if __name__ == "__main__":
sys.exit(main())