scholarr/tests/unit/test_healthz.py
2026-02-17 15:21:08 +01:00

25 lines
756 B
Python

from unittest.mock import AsyncMock
from fastapi.testclient import TestClient
from app.main import app
def test_healthz_returns_200_when_database_is_available(monkeypatch) -> None:
monkeypatch.setattr("app.main.check_database", AsyncMock(return_value=True))
client = TestClient(app)
response = client.get("/healthz")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
def test_healthz_returns_500_when_database_is_unavailable(monkeypatch) -> None:
monkeypatch.setattr("app.main.check_database", AsyncMock(return_value=False))
client = TestClient(app)
response = client.get("/healthz")
assert response.status_code == 500
assert response.json()["detail"] == "database unavailable"