M16: isolate acceptance and harden readiness
This commit is contained in:
@@ -7,3 +7,35 @@ def test_health() -> None:
|
||||
response = TestClient(app).get("/health")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"status": "ok", "service": "mobilityops-api"}
|
||||
|
||||
|
||||
def test_liveness_is_process_only() -> None:
|
||||
response = TestClient(app).get("/health/live")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "ok"
|
||||
|
||||
|
||||
def test_readiness_checks_the_canonical_database() -> None:
|
||||
response = TestClient(app).get("/health/ready")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {
|
||||
"status": "ready",
|
||||
"service": "mobilityops-api",
|
||||
"database": "up",
|
||||
}
|
||||
|
||||
|
||||
def test_readiness_degrades_when_database_is_unavailable(monkeypatch) -> None:
|
||||
import app.main as main_module
|
||||
|
||||
class BrokenSession:
|
||||
def __enter__(self):
|
||||
raise ConnectionError("database unavailable")
|
||||
|
||||
def __exit__(self, *_args):
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(main_module, "SessionLocal", BrokenSession)
|
||||
response = TestClient(app).get("/health/ready")
|
||||
assert response.status_code == 503
|
||||
assert response.json()["database"] == "down"
|
||||
|
||||
Reference in New Issue
Block a user