aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_media_cache.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/tests/test_media_cache.py')
-rw-r--r--packages/meshbay-node/tests/test_media_cache.py53
1 files changed, 51 insertions, 2 deletions
diff --git a/packages/meshbay-node/tests/test_media_cache.py b/packages/meshbay-node/tests/test_media_cache.py
index b66c448..e70ef43 100644
--- a/packages/meshbay-node/tests/test_media_cache.py
+++ b/packages/meshbay-node/tests/test_media_cache.py
@@ -1,10 +1,10 @@
-"""Tests for media_cache.py — TMDB/thumbnail cache and its pruning obligation."""
+"""Tests for media_cache.py — TMDB/MusicBrainz/thumbnail cache and its pruning obligation."""
import time
import pytest
-from meshbay_node.media_cache import MediaCache, TMDB_META_TTL_SECS
+from meshbay_node.media_cache import MediaCache, TMDB_META_TTL_SECS, MUSICBRAINZ_META_TTL_SECS
@pytest.fixture
@@ -69,3 +69,52 @@ async def test_prune_file_removes_thumb_and_mapping_but_not_shared_meta(cache):
# ep2's own mapping and the shared show metadata both survive
assert await cache.get_file_tmdb("ep2") == ("555", "tv")
assert await cache.get_tmdb_meta("555", "tv") == {"name": "A Show"}
+
+
+# ── Music app (docs/musicbay.md §6) — file_mbid/mbid_meta ────────────────────
+
+@pytest.mark.asyncio
+async def test_file_mbid_round_trip(cache):
+ assert await cache.get_file_mbid("file1") is None
+
+ await cache.set_file_mbid("file1", "release-mbid-1")
+
+ assert await cache.get_file_mbid("file1") == "release-mbid-1"
+
+
+@pytest.mark.asyncio
+async def test_mbid_meta_round_trip(cache):
+ assert await cache.get_mbid_meta("release-mbid-1") is None
+
+ await cache.set_mbid_meta("release-mbid-1", {"artist": "Some Artist", "album": "An Album"})
+
+ meta = await cache.get_mbid_meta("release-mbid-1")
+ assert meta == {"artist": "Some Artist", "album": "An Album"}
+
+
+@pytest.mark.asyncio
+async def test_mbid_meta_expires_after_ttl(cache):
+ await cache._db.execute(
+ "INSERT INTO mbid_meta (mbid, json, fetched_at) VALUES (?, ?, ?)",
+ ("old-mbid", '{"album": "Old"}', time.time() - MUSICBRAINZ_META_TTL_SECS - 1),
+ )
+ await cache._db.commit()
+
+ assert await cache.get_mbid_meta("old-mbid") is None
+
+
+@pytest.mark.asyncio
+async def test_prune_file_removes_mbid_mapping_but_not_shared_meta(cache):
+ # Two tracks of the same release share one mbid_meta row.
+ await cache.set_file_mbid("track1", "release-mbid-1")
+ await cache.set_file_mbid("track2", "release-mbid-1")
+ await cache.set_mbid_meta("release-mbid-1", {"album": "An Album"})
+ await cache.put_thumb("cover-hash", "track1", b"cover-bytes")
+
+ await cache.prune_file("track1")
+
+ assert await cache.get_file_mbid("track1") is None
+ assert await cache.get_thumb("cover-hash") is None
+ # track2's own mapping and the shared release metadata both survive
+ assert await cache.get_file_mbid("track2") == "release-mbid-1"
+ assert await cache.get_mbid_meta("release-mbid-1") == {"album": "An Album"}