Files
govoplan/tests/test_postgres_integration_check.py
T
zemion ff9d2404ab
Dependency Audit / dependency-audit (push) Successful in 2m37s
Deployment Installer / deployment-installer (push) Successful in 7s
Security Audit / security-audit (push) Successful in 10m59s
Propagate CI safety settings into nested checks
2026-07-31 06:15:56 +02:00

76 lines
2.3 KiB
Python

from __future__ import annotations
import importlib.util
import os
from pathlib import Path
import unittest
from unittest.mock import patch
META_ROOT = Path(__file__).resolve().parents[1]
SCRIPT = META_ROOT / "tools" / "checks" / "postgres-integration-check.py"
def _load_script():
spec = importlib.util.spec_from_file_location(
"postgres_integration_check",
SCRIPT,
)
if spec is None or spec.loader is None:
raise RuntimeError(f"Could not load {SCRIPT}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
class PostgresIntegrationCheckTests(unittest.TestCase):
def test_staging_check_has_explicit_runtime_safety_settings(self) -> None:
module = _load_script()
with patch.dict(os.environ, {}, clear=True):
env = module._check_env(
database_url="postgresql+psycopg://user:password@postgres/db",
modules="tenancy,access,search",
app_env="staging",
)
self.assertEqual(
env["CORS_ORIGINS"],
"http://127.0.0.1:5173,http://localhost:5173",
)
self.assertEqual(
env["GOVOPLAN_TRUSTED_HOSTS"],
"127.0.0.1,localhost,testserver",
)
self.assertEqual(
env["GOVOPLAN_CONNECTOR_ALLOW_PRIVATE_NETWORKS"],
"false",
)
self.assertEqual(
env["GOVOPLAN_ALLOW_PROCESS_LOCAL_LOGIN_THROTTLE"],
"true",
)
def test_existing_runtime_safety_settings_are_preserved(self) -> None:
module = _load_script()
configured = {
"CORS_ORIGINS": "https://govoplan.example.test",
"GOVOPLAN_TRUSTED_HOSTS": "govoplan.example.test",
"GOVOPLAN_CONNECTOR_ALLOW_PRIVATE_NETWORKS": "true",
"GOVOPLAN_ALLOW_PROCESS_LOCAL_LOGIN_THROTTLE": "false",
}
with patch.dict(os.environ, configured, clear=True):
env = module._check_env(
database_url="postgresql+psycopg://user:password@postgres/db",
modules="tenancy,access,search",
app_env="staging",
)
for key, value in configured.items():
self.assertEqual(env[key], value)
if __name__ == "__main__":
unittest.main()