Files
transcription/tests/api/test_health.py
T

45 lines
1.4 KiB
Python

"""Tests for transcription.api.health."""
from fastapi import FastAPI
from fastapi.testclient import TestClient
from transcription.api.health import router
from transcription.worker import WorkerHealthSnapshot
class TestHealthEndpoint:
"""Verify /healthz endpoint behavior."""
def test_healthz_returns_ok_status_with_unknown_worker_when_uninitialized(self):
"""GET /healthz returns a healthy status payload."""
app = FastAPI()
app.include_router(router)
client = TestClient(app)
response = client.get("/healthz")
assert response.status_code == 200
assert response.json() == {"status": "ok", "worker": {"state": "unknown"}}
def test_healthz_returns_worker_failure_metadata_when_available(self):
app = FastAPI()
app.state.worker_health = WorkerHealthSnapshot(
state="failed",
error_id="abc12345",
error_category="internal_unexpected_error",
)
app.include_router(router)
client = TestClient(app)
response = client.get("/healthz")
assert response.status_code == 200
assert response.json() == {
"status": "ok",
"worker": {
"state": "failed",
"error_id": "abc12345",
"error_category": "internal_unexpected_error",
},
}