Spaces:
Running
Running
File size: 1,342 Bytes
18b8b90 | 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 | from fastapi.testclient import TestClient
# Mock settings BEFORE importing the app
from unittest.mock import patch
with patch("app.core.config.settings.API_KEY", "test-api-key"):
from main import app
import pytest
client = TestClient(app)
def test_chat_response():
"""Test basic chatbot response and identity."""
response = client.post(
"/api/ai/chat",
json={"message": "ู
ุฑุญุจุงูุ ู
ู ุฃูุชุ"},
headers={"X-API-Key": "test-api-key"}
)
assert response.status_code == 200
data = response.json()
assert "ุนูู" in data["response"] # Should identify as Aoun assistant
assert "history" in data
assert len(data["history"]) >= 2
def test_chat_with_history():
"""Test chatbot response with history context."""
history = [
{"role": "user", "content": "ุงุณู
ู ู
ุญู
ุฏ"},
{"role": "model", "content": "ุฃููุงู ุจู ูุง ู
ุญู
ุฏ ูู ู
ูุตุฉ ุนููุ ููู ูู
ูููู ู
ุณุงุนุฏุชูุ"}
]
response = client.post(
"/api/ai/chat",
json={
"message": "ู
ุง ูู ุงุณู
ูุ",
"history": history
},
headers={"X-API-Key": "test-api-key"}
)
assert response.status_code == 200
data = response.json()
assert "ู
ุญู
ุฏ" in data["response"]
assert len(data["history"]) == 4
|