from lyra_worker.registry import build_album_popularity from lyra_worker.similarity._lastfm_albums import _parse_top_albums def test_parse_orders_by_playcount_and_keeps_mbids(): data = {"topalbums": {"album": [ {"name": "Older Hit", "mbid": "rg-old", "playcount": "5000"}, {"name": "Newer", "mbid": "", "playcount": "9000"}, {"name": "No Plays", "playcount": "0"}, ]}} assert _parse_top_albums(data) == [ ["Newer", None, 9000], # highest playcount first; empty mbid -> None ["Older Hit", "rg-old", 5000], ["No Plays", None, 0], ] def test_parse_wraps_a_single_album_dict(): data = {"topalbums": {"album": {"name": "Only One", "mbid": "rg1", "playcount": "3"}}} assert _parse_top_albums(data) == [["Only One", "rg1", 3]] def test_parse_returns_empty_on_error_body(): assert _parse_top_albums({"error": 6, "message": "bad"}) == [] def test_build_album_popularity_none_without_key(): assert build_album_popularity({}) is None assert build_album_popularity({"lastfm.api_key": "abc"}) is not None