from __future__ import annotations import pytest from django.test import override_settings from apps.core.health import readiness pytestmark = pytest.mark.django_db @override_settings(HEALTHCHECK_REQUIRE_CACHE=True) def test_readiness_checks_database_and_shared_cache(): result = readiness() assert result.ok is True assert result.checks == {"database": "ok", "cache": "ok"} @override_settings(HEALTHCHECK_REQUIRE_CACHE=True) def test_readiness_reports_cache_failure(monkeypatch): def fail_cache(*args, **kwargs): raise ConnectionError monkeypatch.setattr("apps.core.health.cache.set", fail_cache) result = readiness() assert result.ok is False assert result.checks["database"] == "ok" assert result.checks["cache"] == "error:ConnectionError"