"""Connection and source-code guards: no live database required.""" import re import unittest from pathlib import Path from db_config import DEFAULT_DB_CONFIG, build_dsn_from_config from version_info import versioned_title class IsolationTests(unittest.TestCase): def test_connection_allows_only_local_clone(self): config = dict(DEFAULT_DB_CONFIG, password="test-not-a-real-password") self.assertIn("Xwmsdb", build_dsn_from_config(config)) for database in ("Mediseawall", "SAMA1", "master", ""): with self.assertRaises(ValueError): build_dsn_from_config(dict(config, database=database)) with self.assertRaises(ValueError): build_dsn_from_config(dict(config, server="production")) def test_runtime_sql_has_no_original_database_identifiers(self): root = Path(__file__).resolve().parents[1] for path in [root / "inventory_report.sql", *root.glob("*.py")]: with self.subTest(file=path.name): self.assertIsNone(re.search(r"(?i)\b(?:SAMA1|Mediseawall)\b", path.read_text(encoding="utf-8"))) def test_test_environment_is_visible_in_titles(self): self.assertTrue(versioned_title("Inventario", "inventario").startswith("[XWMS TEST]")) if __name__ == "__main__": unittest.main()