34 lines
820 B
Python
34 lines
820 B
Python
"""Testy healthcheck endpointu GET /healthz."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sqlite3
|
|
|
|
from flask.testing import FlaskClient
|
|
|
|
from poznavacky import db as db_module
|
|
|
|
|
|
def test_healthz_returns_200_when_db_is_healthy(client: FlaskClient) -> None:
|
|
response = client.get("/healthz")
|
|
|
|
assert response.status_code == 200
|
|
assert response.is_json
|
|
assert response.get_json() == {"status": "ok"}
|
|
|
|
|
|
def test_healthz_returns_503_when_db_fails(
|
|
client: FlaskClient,
|
|
monkeypatch,
|
|
) -> None:
|
|
def _broken_db():
|
|
raise sqlite3.OperationalError("databáze nedostupná")
|
|
|
|
monkeypatch.setattr(db_module, "get_db", _broken_db)
|
|
|
|
response = client.get("/healthz")
|
|
|
|
assert response.status_code == 503
|
|
assert response.is_json
|
|
assert response.get_json() == {"status": "error"}
|