2026-07-01 23:15:35 +02:00
|
|
|
"""Health endpoint test — AC1-2: Extended health check with DB, Redis, storage, worker."""
|
2026-06-03 23:52:05 +00:00
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-06-29 00:10:10 +02:00
|
|
|
import pytest
|
2026-06-03 23:52:05 +00:00
|
|
|
from httpx import AsyncClient
|
|
|
|
|
|
|
|
|
|
|
2026-06-29 00:10:10 +02:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
class TestHealth:
|
2026-07-01 23:15:35 +02:00
|
|
|
"""AC1: GET /api/v1/health -> 200 without auth, with extended checks."""
|
2026-06-03 23:52:05 +00:00
|
|
|
|
2026-06-29 00:10:10 +02:00
|
|
|
async def test_health_returns_200_without_auth(self, client: AsyncClient):
|
2026-07-01 23:15:35 +02:00
|
|
|
"""AC1: GET /api/v1/health -> 200 without auth."""
|
2026-06-29 00:10:10 +02:00
|
|
|
resp = await client.get("/api/v1/health")
|
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
data = resp.json()
|
2026-07-01 23:15:35 +02:00
|
|
|
assert "status" in data
|
2026-06-29 00:10:10 +02:00
|
|
|
assert "version" in data
|
2026-07-01 23:15:35 +02:00
|
|
|
assert "checks" in data
|
|
|
|
|
|
|
|
|
|
async def test_health_has_database_check(self, client: AsyncClient):
|
|
|
|
|
"""AC1: Health response includes checks.database."""
|
|
|
|
|
resp = await client.get("/api/v1/health")
|
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
data = resp.json()
|
|
|
|
|
assert "database" in data["checks"]
|
|
|
|
|
assert "status" in data["checks"]["database"]
|
|
|
|
|
|
|
|
|
|
async def test_health_has_redis_check(self, client: AsyncClient):
|
|
|
|
|
"""AC1: Health response includes checks.redis."""
|
|
|
|
|
resp = await client.get("/api/v1/health")
|
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
data = resp.json()
|
|
|
|
|
assert "redis" in data["checks"]
|
|
|
|
|
assert "status" in data["checks"]["redis"]
|
|
|
|
|
|
|
|
|
|
async def test_health_has_storage_check(self, client: AsyncClient):
|
|
|
|
|
"""AC1: Health response includes checks.storage."""
|
|
|
|
|
resp = await client.get("/api/v1/health")
|
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
data = resp.json()
|
|
|
|
|
assert "storage" in data["checks"]
|
|
|
|
|
assert "status" in data["checks"]["storage"]
|
|
|
|
|
|
|
|
|
|
async def test_health_has_worker_check(self, client: AsyncClient):
|
|
|
|
|
"""AC1: Health response includes checks.worker."""
|
|
|
|
|
resp = await client.get("/api/v1/health")
|
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
data = resp.json()
|
|
|
|
|
assert "worker" in data["checks"]
|
|
|
|
|
assert "status" in data["checks"]["worker"]
|
|
|
|
|
|
|
|
|
|
async def test_health_status_is_valid_value(self, client: AsyncClient):
|
|
|
|
|
"""Health status should be 'healthy' or 'degraded'."""
|
|
|
|
|
resp = await client.get("/api/v1/health")
|
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
data = resp.json()
|
|
|
|
|
assert data["status"] in ("healthy", "degraded")
|