Spaces:
Running
Running
| 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 | |