26 lines
1.0 KiB
Python
26 lines
1.0 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from app.services.calculation_cleanup import _names, record_calculation_database
|
|
from app.algorithms._utils import calculation_temp_directory
|
|
|
|
|
|
def test_job_owned_database_ledger_survives_until_successful_cleanup(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("TJWATER_CALCULATION_JOB_DIR", str(tmp_path))
|
|
name = "tjw_tmp_run_project_" + "a" * 32
|
|
record_calculation_database(name)
|
|
record_calculation_database(name)
|
|
assert _names(tmp_path) == [name]
|
|
assert json.loads((tmp_path / "databases.json").read_text()) == [name]
|
|
record_calculation_database(name, removed=True)
|
|
assert _names(tmp_path) == []
|
|
assert calculation_temp_directory("leakage") == str(tmp_path / "leakage")
|
|
|
|
|
|
@pytest.mark.parametrize("names", [["production"], ["tjw_tmp_not_random"], {"database": "production"}])
|
|
def test_cleanup_rejects_non_job_database_names(tmp_path, names):
|
|
(tmp_path / "databases.json").write_text(json.dumps(names))
|
|
with pytest.raises(ValueError):
|
|
_names(tmp_path)
|