This repository was archived by the owner on Apr 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_prod.py
More file actions
80 lines (66 loc) · 2.38 KB
/
Copy pathtest_prod.py
File metadata and controls
80 lines (66 loc) · 2.38 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
import requests
import json
import time
API_URL = "http://localhost:8001/chat"
test_cases = [
{
"description": "Test 1: Sapaan Umum",
"payload": {"query": "Halo, selamat siang kak?"}
},
{
"description": "Test 2: Pertanyaan Troubleshooting",
"payload": {"query": "Permisi kak, ini wifi saya lagi gangguan ya?"}
},
{
"description": "Test 3: Pertanyaan Harga",
"payload": {"query": "Berapa harga paket internetnya?"}
},
{
"description": "Test 4: Kueri Kosong (Penanganan Error)",
"payload": {"query": ""}
},
{
"description": "Test 5: Pertanyaan Teknis (RAG)",
"payload": {"query": "Dimna lokasi kantor wifinya?"}
}
]
def run_all_tests():
"""
Sends a series of test requests to the /chat endpoint and prints the responses.
"""
print(f"--- Starting Chatbot Backend Test ---")
all_tests_passed = True
for test in test_cases:
print(f"\nRunning: {test['description']}...")
try:
response = requests.post(API_URL, json=test["payload"])
response.raise_for_status()
print("Status: SUCCESS")
print("Server Response:")
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except requests.exceptions.HTTPError as e:
print(f"Status: FAILED (HTTP Error)")
print(f"Response Code: {e.response.status_code}")
print("Server Response:")
print(json.dumps(e.response.json(), indent=2, ensure_ascii=False))
if test["payload"]["query"] == "":
print("(This is expected for an empty query test)")
else:
all_tests_passed = False
except requests.exceptions.RequestException as e:
print(f"Status: FAILED (Connection Error)")
print(f"Details: {e}")
print("Please ensure the FastAPI backend is running at the correct address.")
all_tests_passed = False
break
except Exception as e:
print(f"An unexpected error occurred: {e}")
all_tests_passed = False
time.sleep(1)
print("\n--- Test Run Finished ---")
if all_tests_passed:
print("✅ All tests completed successfully.")
else:
print("❌ Some tests failed.")
if __name__ == "__main__":
run_all_tests()