File size: 2,615 Bytes
3acb982
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b32fbe0
3acb982
b32fbe0
 
 
 
 
3acb982
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
Knowledge Universe - Basic API Tests
"""
import pytest
from httpx import AsyncClient
from src.api.main import app


@pytest.mark.asyncio
async def test_health_check():
    """Test health endpoint"""
    async with AsyncClient(app=app, base_url="http://test") as client:
        response = await client.get("/health")
        
        assert response.status_code == 200
        data = response.json()
        assert data["status"] in ["healthy", "degraded"]
        assert "version" in data


@pytest.mark.asyncio
async def test_readiness_check():
    """Test readiness endpoint"""
    async with AsyncClient(app=app, base_url="http://test") as client:
        response = await client.get("/ready")
        
        assert response.status_code in [200, 503]


@pytest.mark.asyncio
async def test_root_endpoint():
    """Test root endpoint"""
    async with AsyncClient(app=app, base_url="http://test") as client:
        response = await client.get("/")
        
        assert response.status_code == 200
        data = response.json()
        assert "name" in data
        assert "version" in data


@pytest.mark.asyncio
async def test_discover_endpoint_validation():
    """Test discovery endpoint with invalid data"""
    async with AsyncClient(app=app, base_url="http://test") as client:
        # Missing required field
        response = await client.post(
            "/v1/discover",
            json={"difficulty": 2}
        )
        assert response.status_code == 422
        
        # Invalid difficulty
        response = await client.post(
            "/v1/discover",
            json={
                "topic": "test",
                "difficulty": 10  # Invalid: must be 1-5
            }
        )
        assert response.status_code == 422


@pytest.mark.asyncio
async def test_list_formats():
    """Test formats listing endpoint"""
    async with AsyncClient(app=app, base_url="http://test") as client:
        response = await client.get("/v1/formats")

        assert response.status_code == 200
        data = response.json()
        assert isinstance(data, dict)          # endpoint returns a dict
        assert "formats" in data
        assert isinstance(data["formats"], list)
        assert "pdf" in data["formats"]


@pytest.mark.asyncio
async def test_list_crawlers():
    """Test crawlers listing endpoint"""
    async with AsyncClient(app=app, base_url="http://test") as client:
        response = await client.get("/v1/crawlers")
        
        assert response.status_code == 200
        data = response.json()
        assert "crawlers" in data
        assert "total" in data