git-subtree-dir: fiscal git-subtree-mainline:d95165fc8fgit-subtree-split:102ba84500
34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
"""The RTC copy-write E2E may touch ONLY the disposable scratch copy; every real database path must be refused before any connection is opened."""
|
|
import importlib.util
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def _load():
|
|
import os
|
|
before = dict(os.environ)
|
|
sys.path.insert(0, str(ROOT / "scripts")); sys.path.insert(0, str(ROOT / "agent" / "src"))
|
|
spec = importlib.util.spec_from_file_location("rtc_copy_write_e2e", ROOT / "scripts" / "rtc_copy_write_e2e.py")
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
assert dict(os.environ) == before, "importing the E2E script must not change the environment"
|
|
return module
|
|
|
|
|
|
def test_guard_accepts_only_the_exact_scratch_copy_and_refuses_real_databases():
|
|
module = _load()
|
|
module.guard(module.COPY) # the copy itself is fine
|
|
for path in (ROOT / "TESTESOFICIAIS.FDB", ROOT / "Banco" / "CONSTRUCAO.FDB", ROOT / "Banco" / "RINCAO.FDB", ROOT / "scratch_rtc_e2e" / "OTHER.FDB", Path("D:/PROJETOS/GTISISTEMAS/Banco/GTI.FDB")):
|
|
with pytest.raises(SystemExit):
|
|
module.guard(str(path))
|
|
assert "scratch_rtc_e2e" in module.COPY
|
|
|
|
|
|
def test_the_e2e_script_only_ever_connects_to_the_copy():
|
|
text = (ROOT / "scripts" / "rtc_copy_write_e2e.py").read_text(encoding="utf-8")
|
|
assert text.count("fdb.connect(") == 1 and "database=COPY" in text # the single connection helper is bound to the copy path
|