Aoun-Ai / tests /test_chat_api.py
MuhammadMahmoud's picture
feat: clean deployment with bug fixes and stability improvements
18b8b90
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