File size: 1,501 Bytes
64d7fdf
 
c4a4657
64d7fdf
 
 
 
 
 
 
c4a4657
 
 
 
 
 
 
 
64d7fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
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