55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from fastapi.testclient import TestClient
|
|
from app.main import app
|
|
|
|
c = TestClient(app)
|
|
|
|
|
|
def test_artist_detail_mocked(monkeypatch):
|
|
from app.api import artist as art
|
|
|
|
async def fake_details(artist_id):
|
|
return {
|
|
"id": artist_id,
|
|
"name": "Fleetwood Mac",
|
|
"cover": "https://cdn-images.dzcdn.net/cover.jpg",
|
|
"albums": [
|
|
{"id": "1", "title": "Rumours", "group": "album"},
|
|
{"id": "2", "title": "EP One", "group": "ep"},
|
|
{"id": "3", "title": "Single One", "group": "single"},
|
|
],
|
|
"featuring": [
|
|
{"id": "9", "title": "Guest Verse", "artist": "Someone"},
|
|
],
|
|
}
|
|
|
|
monkeypatch.setattr(art, "get_artist_details", fake_details)
|
|
r = c.get("/api/artist/169")
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert body["name"] == "Fleetwood Mac"
|
|
assert len(body["albums"]) == 3
|
|
assert len(body["featuring"]) == 1
|
|
|
|
|
|
def test_is_featuring_unit():
|
|
from app.services.streamrip_service import _is_featuring
|
|
|
|
assert _is_featuring("Fleetwood Mac", {"artist": {"name": "Fleetwood Mac"}}) is False
|
|
assert _is_featuring("Fleetwood Mac", {"artist": {"name": "Someone Else"}}) is True
|
|
assert _is_featuring("Fleetwood Mac", {"artist": "fleetwood mac"}) is False
|
|
|
|
|
|
def test_artist_grouping_unit():
|
|
from app.services.streamrip_service import _group_artist_albums
|
|
|
|
items = [
|
|
{"id": 1, "title": "A", "record_type": "album"},
|
|
{"id": 2, "title": "B", "record_type": "ep"},
|
|
{"id": 3, "title": "C", "record_type": "single"},
|
|
{"id": 4, "title": "D"}, # no record_type -> fallback single? album?
|
|
]
|
|
albums = _group_artist_albums(items)
|
|
groups = {a["group"] for a in albums}
|
|
assert {"album", "ep", "single"} <= groups
|
|
assert all(a["id"] for a in albums)
|