Environment-variable configuration that fails fast, database-only health check, JSON request logs with a request id, security headers with a strict CSP, and a multi-stage non-root Docker image with compose file. Ticket 1.1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sk72AxLwQnYttF6VFSxQLt
21 lines
672 B
Python
21 lines
672 B
Python
from unittest import mock
|
|
|
|
import pytest
|
|
from django.db.utils import OperationalError
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_health_ok(client):
|
|
response = client.get("/healthz")
|
|
assert response.status_code == 200
|
|
assert response.json() == {"status": "ok"}
|
|
|
|
|
|
def test_health_down_when_database_unreachable(client, caplog):
|
|
with mock.patch("portal.config.health.connection") as connection:
|
|
connection.cursor.side_effect = OperationalError("unable to open database file")
|
|
response = client.get("/healthz")
|
|
assert response.status_code == 503
|
|
assert response.json() == {"status": "unavailable"}
|
|
assert "unable to open" not in caplog.text
|