51 lines
2.7 KiB
Python
51 lines
2.7 KiB
Python
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]
|
|
|
|
|
|
def test_media_catalog_does_not_infer_official_source_from_url_substrings(tmp_path, monkeypatch) -> None:
|
|
manifest = {"assets": [
|
|
{"status": "approved", "sha256": "e" * 64, "local_path": "asset.webp", "entity_type": "fish", "entity_key": "pike", "source_page": "https://rf4db.com.attacker.test/pike"},
|
|
{"status": "approved", "sha256": "f" * 64, "local_path": "asset2.webp", "entity_type": "fish", "entity_key": "pike", "source_page": "https://rf4db.com/ru/fish/pike"},
|
|
]}
|
|
(tmp_path / "manifest.json").write_text(json.dumps(manifest), encoding="utf-8")
|
|
monkeypatch.setattr(media_catalog, "MEDIA_ROOT", tmp_path)
|
|
|
|
rows = {row["id"]: row for row in media_catalog.published_assets()}
|
|
|
|
assert rows["e" * 64]["source_system"] == "unknown"
|
|
assert rows["f" * 64]["source_system"] == "rf4db"
|
|
|
|
|
|
def test_media_manifest_cache_invalidates_after_revision(tmp_path, monkeypatch) -> None:
|
|
manifest_path = tmp_path / "manifest.json"
|
|
manifest_path.write_text(json.dumps({"version": 1, "assets": [
|
|
{"status": "approved", "sha256": "a" * 64, "local_path": "one.webp", "entity_type": "fish", "entity_key": "pike"},
|
|
]}), encoding="utf-8")
|
|
monkeypatch.setattr(media_catalog, "MEDIA_ROOT", tmp_path)
|
|
assert [row["id"] for row in media_catalog.published_assets()] == ["a" * 64]
|
|
|
|
manifest_path.write_text(json.dumps({"version": 2, "assets": [
|
|
{"status": "approved", "sha256": "b" * 64, "local_path": "two.webp", "entity_type": "fish", "entity_key": "pike"},
|
|
]}), encoding="utf-8")
|
|
|
|
assert media_catalog.media_manifest_version() == 2
|
|
assert [row["id"] for row in media_catalog.published_assets()] == ["b" * 64]
|