rag-chatbot / tests /test_api.py
Abeshith's picture
Fix CI tests: add environment variable defaults and skip integration tests
c4a4657
import pytest
from httpx import AsyncClient
from unittest.mock import patch, MagicMock
@pytest.mark.integration
class TestHealthEndpoint:
@pytest.mark.asyncio
async def test_health_check(self, client: AsyncClient):
with patch('app.db.redis_client.redis_client.ping', return_value=True), \
patch('app.db.mongodb.mongodb.client.admin.command', return_value={'ok': 1}), \
patch('app.db.vector_store.vector_store.client.get_collections', return_value=MagicMock()):
response = await client.get("/health/")
assert response.status_code in [200, 503]
data = response.json()
assert "status" in data
@pytest.mark.integration
class TestChatEndpoints:
@pytest.mark.asyncio
async def test_chat_without_rag(self, client: AsyncClient, clear_cache):
payload = {
"message": "Hello, how are you?",
"use_rag": False
}
response = await client.post("/chat/stream", json=payload)
assert response.status_code == 200
@pytest.mark.asyncio
@pytest.mark.slow
async def test_chat_with_rag(self, client: AsyncClient, clear_cache):
payload = {
"message": "What is attention mechanism?",
"use_rag": True,
"session_id": "test-session"
}
response = await client.post("/chat/stream", json=payload)
assert response.status_code == 200