42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
from rf4_research.media_store import bootstrap_media_store
|
|
|
|
|
|
def test_bootstrap_merges_new_baseline_without_replacing_decisions(tmp_path: Path) -> None:
|
|
source = tmp_path / "source"
|
|
target = tmp_path / "target"
|
|
(source / "files").mkdir(parents=True)
|
|
(source / "files/new.bin").write_bytes(b"new")
|
|
(source / "manifest.json").write_text(json.dumps({"version": 2, "assets": [{
|
|
"asset_url": "https://new.example/asset", "status": "approved",
|
|
"local_path": "files/new.bin",
|
|
}]}), encoding="utf-8")
|
|
target.mkdir()
|
|
(target / "manifest.json").write_text(json.dumps({"version": 1, "assets": [{
|
|
"asset_url": "https://new.example/asset", "status": "superseded",
|
|
"local_path": "files/new.bin", "review_note": "owner decision",
|
|
}]}), encoding="utf-8")
|
|
|
|
result = bootstrap_media_store(source, target)
|
|
|
|
assert result == {"added_assets": 0, "copied_files": 1}
|
|
saved = json.loads((target / "manifest.json").read_text(encoding="utf-8"))
|
|
assert saved["assets"][0]["status"] == "superseded"
|
|
assert saved["assets"][0]["review_note"] == "owner decision"
|
|
assert (target / "files/new.bin").read_bytes() == b"new"
|
|
|
|
|
|
def test_bootstrap_adds_assets_from_new_release(tmp_path: Path) -> None:
|
|
source = tmp_path / "source"
|
|
target = tmp_path / "target"
|
|
(source / "files").mkdir(parents=True)
|
|
(source / "files/new.bin").write_bytes(b"new")
|
|
(source / "manifest.json").write_text(json.dumps({"version": 1, "assets": [{
|
|
"asset_url": "https://new.example/asset", "local_path": "files/new.bin",
|
|
}]}), encoding="utf-8")
|
|
|
|
assert bootstrap_media_store(source, target) == {"added_assets": 1, "copied_files": 1}
|
|
assert (target / "files/new.bin").exists()
|