Spaces:
Paused
Paused
Update intent_test_runner.py
Browse files- intent_test_runner.py +17 -9
intent_test_runner.py
CHANGED
@@ -2,8 +2,8 @@ import os
|
|
2 |
import requests
|
3 |
from log import log
|
4 |
|
5 |
-
|
6 |
-
|
7 |
|
8 |
test_results = []
|
9 |
|
@@ -30,31 +30,39 @@ def summarize_tests():
|
|
30 |
def run_all_tests():
|
31 |
try:
|
32 |
log("🚀 Test süreci başlatıldı.")
|
|
|
|
|
33 |
response = requests.post(f"{BASE_URL}/start_chat?project_name=project1")
|
|
|
|
|
|
|
34 |
session_id = response.json().get("session_id")
|
|
|
|
|
|
|
35 |
headers = {"X-Session-ID": session_id}
|
36 |
|
37 |
-
# 1
|
38 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "bilinmeyen bir soru"}, headers=headers)
|
39 |
assert_test("LLM fallback", r.json(), "maalesef")
|
40 |
|
41 |
-
# 2
|
42 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "döviz kuru nedir"}, headers=headers)
|
43 |
assert_test("Eksik parametre — currency", r.json(), "Lütfen currency")
|
44 |
|
45 |
-
# 3
|
46 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "dolar"}, headers=headers)
|
47 |
assert_test("Parametre tamamlandı — dolar", r.json(), "dolar kuru şu an")
|
48 |
|
49 |
-
# 4
|
50 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yenidolar kuru nedir"}, headers=headers)
|
51 |
assert_test("Geçersiz parametre — currency", r.json(), "geçerli bir döviz")
|
52 |
|
53 |
-
# 5
|
54 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "hava nasıl"}, headers=headers)
|
55 |
assert_test("Konu değişikliği sonrası fallback", r.json(), "maalesef")
|
56 |
|
57 |
-
# 6
|
58 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yol durumu"}, headers=headers)
|
59 |
assert_test("Eksik parametre — from_location", r.json(), "Lütfen from_location")
|
60 |
|
@@ -67,4 +75,4 @@ def run_all_tests():
|
|
67 |
summarize_tests()
|
68 |
|
69 |
except Exception as e:
|
70 |
-
log(f"❌ run_all_tests sırasında hata oluştu: {e}")
|
|
|
2 |
import requests
|
3 |
from log import log
|
4 |
|
5 |
+
# 🌐 Ortam değişkeninden veya local default
|
6 |
+
BASE_URL = os.environ.get("BASE_URL", "http://localhost:7860")
|
7 |
|
8 |
test_results = []
|
9 |
|
|
|
30 |
def run_all_tests():
|
31 |
try:
|
32 |
log("🚀 Test süreci başlatıldı.")
|
33 |
+
|
34 |
+
# ✅ Yeni session başlatırken project_name gönderiyoruz
|
35 |
response = requests.post(f"{BASE_URL}/start_chat?project_name=project1")
|
36 |
+
if response.status_code != 200:
|
37 |
+
raise Exception(f"Start chat başarısız: {response.status_code}, {response.text}")
|
38 |
+
|
39 |
session_id = response.json().get("session_id")
|
40 |
+
if not session_id:
|
41 |
+
raise Exception("Session ID alınamadı.")
|
42 |
+
|
43 |
headers = {"X-Session-ID": session_id}
|
44 |
|
45 |
+
# 1️⃣ LLM fallback testi
|
46 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "bilinmeyen bir soru"}, headers=headers)
|
47 |
assert_test("LLM fallback", r.json(), "maalesef")
|
48 |
|
49 |
+
# 2️⃣ Eksik parametre testi (döviz kuru)
|
50 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "döviz kuru nedir"}, headers=headers)
|
51 |
assert_test("Eksik parametre — currency", r.json(), "Lütfen currency")
|
52 |
|
53 |
+
# 3️⃣ Eksik parametre tamamlanınca tekrar deneme
|
54 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "dolar"}, headers=headers)
|
55 |
assert_test("Parametre tamamlandı — dolar", r.json(), "dolar kuru şu an")
|
56 |
|
57 |
+
# 4️⃣ Geçersiz parametre validasyonu
|
58 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yenidolar kuru nedir"}, headers=headers)
|
59 |
assert_test("Geçersiz parametre — currency", r.json(), "geçerli bir döviz")
|
60 |
|
61 |
+
# 5️⃣ Konu değişikliği → awaiting reset
|
62 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "hava nasıl"}, headers=headers)
|
63 |
assert_test("Konu değişikliği sonrası fallback", r.json(), "maalesef")
|
64 |
|
65 |
+
# 6️⃣ Yol durumu testi (eksik from_location)
|
66 |
r = requests.post(f"{BASE_URL}/chat", json={"user_input": "yol durumu"}, headers=headers)
|
67 |
assert_test("Eksik parametre — from_location", r.json(), "Lütfen from_location")
|
68 |
|
|
|
75 |
summarize_tests()
|
76 |
|
77 |
except Exception as e:
|
78 |
+
log(f"❌ run_all_tests sırasında hata oluştu: {e}")
|