fix: filter public media roles by entity

This commit is contained in:
ik
2026-09-21 18:09:11 +07:00
parent 4f847db38a
commit 31b720f7b3
3 changed files with 38 additions and 1 deletions
+20
View File
@@ -0,0 +1,20 @@
import json
from app import media_catalog
def test_public_media_catalog_rejects_unknown_and_cross_entity_roles(tmp_path, monkeypatch) -> None:
manifest = {
"assets": [
{"status": "approved", "sha256": "a" * 64, "local_path": "water.webp", "entity_type": "waterbody", "entity_key": "kuori", "media_role": "waterbody_map"},
{"status": "approved", "sha256": "b" * 64, "local_path": "wrong.webp", "entity_type": "waterbody", "entity_key": "kuori", "media_role": "tackle_card"},
{"status": "approved", "sha256": "c" * 64, "local_path": "unknown.webp", "entity_type": "tackle", "entity_key": "spiker", "media_role": "future_role"},
{"status": "approved", "sha256": "d" * 64, "local_path": "tackle.webp", "entity_type": "tackle", "entity_key": "spiker", "media_role": "tackle_card"},
],
}
(tmp_path / "manifest.json").write_text(json.dumps(manifest), encoding="utf-8")
monkeypatch.setattr(media_catalog, "MEDIA_ROOT", tmp_path)
rows = media_catalog.published_assets()
assert [row["id"] for row in rows] == ["d" * 64, "a" * 64]