stackchain-dashboard/tests/test_health.py
timmy 610b659fd4
All checks were successful
CI / lint (pull_request) Successful in 9s
CI / build-frontend (pull_request) Successful in 5s
feat: add Gitea readiness probe
2026-08-05 10:02:54 +00:00

40 lines
1.2 KiB
Python

import pytest
from src import main
def test_health_endpoint_reports_service_liveness_without_gitea_access():
assert any(getattr(route, "path", None) == "/healthz" for route in main.app.routes)
assert main.health() == {"status": "ok", "service": "stackchain-dashboard"}
@pytest.mark.anyio
async def test_readiness_endpoint_reports_connected_gitea_user(monkeypatch):
async def connected_user():
return {"login": "timmy"}
monkeypatch.setattr(main, "current_user", connected_user)
response = await main.readiness()
assert any(getattr(route, "path", None) == "/readyz" for route in main.app.routes)
assert response == {
"status": "ready",
"service": "stackchain-dashboard",
"gitea_user": "timmy",
}
@pytest.mark.anyio
async def test_readiness_endpoint_returns_503_when_gitea_is_unavailable(monkeypatch):
async def unavailable_user():
raise RuntimeError("connection refused")
monkeypatch.setattr(main, "current_user", unavailable_user)
response = await main.readiness()
assert response.status_code == 503
assert b'"status":"not_ready"' in response.body
assert b'"error":"connection refused"' in response.body