You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
2.0 KiB

"""
Integration tests for API endpoints
"""
import pytest
from fastapi.testclient import TestClient
from unittest.mock import patch, Mock
class TestAPIIntegration:
"""Integration tests for API"""
@pytest.fixture
def client(self):
"""Test client fixture"""
# Import here to avoid circular imports
from src.main import app
return TestClient(app)
def test_health_endpoint(self, client):
"""Test health check endpoint"""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert "status" in data
assert data["status"] == "healthy"
@patch('src.api.routes.IslamicScholarAgent')
def test_chat_endpoint_success(self, mock_agent_class, client):
"""Test successful chat endpoint"""
# Mock the agent
mock_agent_instance = Mock()
mock_response = Mock()
mock_response.content = "Test Islamic knowledge response"
mock_agent_instance.run.return_value = mock_response
mock_agent_instance.get_agent.return_value = mock_agent_instance
mock_agent_class.return_value = mock_agent_instance
response = client.post("/chat", json={"message": "What is Islamic knowledge?"})
assert response.status_code == 200
data = response.json()
assert "response" in data
assert data["response"] == "Test Islamic knowledge response"
@patch('src.api.routes.IslamicScholarAgent')
def test_chat_endpoint_error(self, mock_agent_class, client):
"""Test chat endpoint with error"""
# Mock the agent to raise exception
mock_agent_instance = Mock()
mock_agent_instance.run.side_effect = Exception("Test error")
mock_agent_instance.get_agent.return_value = mock_agent_instance
mock_agent_class.return_value = mock_agent_instance
response = client.post("/chat", json={"message": "Test message"})
assert response.status_code == 500
data = response.json()
assert "detail" in data