from unittest.mock import patch import pytest from django.db import OperationalError, connection @pytest.mark.django_db def test_health_checks_postgresql(client): assert connection.vendor == "postgresql" response = client.get("/health/") assert response.status_code == 200 assert response.json() == {"status": "ok"} def test_health_failure_does_not_disclose_connection_details(client): with patch("django.db.backends.postgresql.base.DatabaseWrapper.cursor", side_effect=OperationalError("private-host secret-password")): response = client.get("/health/") assert response.status_code == 503 assert response.json() == {"status": "unavailable"} assert b"secret-password" not in response.content