""" 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