|
| 1 | +import os |
| 2 | +from http import HTTPStatus |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from beets.test.helper import TestHelper |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture(scope="session", autouse=True) |
| 11 | +def helper(): |
| 12 | + helper = TestHelper() |
| 13 | + helper.setup_beets() |
| 14 | + yield helper |
| 15 | + helper.teardown_beets() |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture(scope="session") |
| 19 | +def app(helper): |
| 20 | + from beetsplug.aura import create_app |
| 21 | + |
| 22 | + app = create_app() |
| 23 | + app.config["lib"] = helper.lib |
| 24 | + return app |
| 25 | + |
| 26 | + |
| 27 | +class TestResponse: |
| 28 | + @pytest.fixture(scope="class", autouse=True) |
| 29 | + def _other_album_and_item(self, helper): |
| 30 | + item = helper.add_item_fixture( |
| 31 | + album="Other Album", |
| 32 | + title="Other Title", |
| 33 | + artist="Other Artist", |
| 34 | + albumartist="Other Album Artist", |
| 35 | + ) |
| 36 | + helper.lib.add_album([item]) |
| 37 | + |
| 38 | + @pytest.fixture(scope="class") |
| 39 | + def item(self, helper): |
| 40 | + return helper.add_item_fixture( |
| 41 | + album="Album", |
| 42 | + title="Title", |
| 43 | + artist="Artist", |
| 44 | + albumartist="Album Artist", |
| 45 | + ) |
| 46 | + |
| 47 | + @pytest.fixture(scope="class") |
| 48 | + def album(self, helper, item): |
| 49 | + return helper.lib.add_album([item]) |
| 50 | + |
| 51 | + def test_tracks(self, client, item, album): |
| 52 | + res = client.get(f"/aura/tracks?filter[title]={item.title}") |
| 53 | + |
| 54 | + assert res.status_code == HTTPStatus.OK |
| 55 | + assert res.json == { |
| 56 | + "data": [ |
| 57 | + { |
| 58 | + "attributes": { |
| 59 | + "album": item.album, |
| 60 | + "albumartist": item.albumartist, |
| 61 | + "artist": item.artist, |
| 62 | + "size": Path(os.fsdecode(item.path)).stat().st_size, |
| 63 | + "title": item.title, |
| 64 | + }, |
| 65 | + "id": str(item.id), |
| 66 | + "relationships": { |
| 67 | + "albums": { |
| 68 | + "data": [{"id": str(album.id), "type": "album"}] |
| 69 | + }, |
| 70 | + "artists": { |
| 71 | + "data": [{"id": item.artist, "type": "artist"}] |
| 72 | + }, |
| 73 | + }, |
| 74 | + "type": "track", |
| 75 | + } |
| 76 | + ] |
| 77 | + } |
| 78 | + |
| 79 | + def test_artists(self, client, item): |
| 80 | + res = client.get(f"/aura/artists?filter[artist]={item.artist}") |
| 81 | + |
| 82 | + assert res.status_code == HTTPStatus.OK |
| 83 | + assert res.json == { |
| 84 | + "data": [ |
| 85 | + { |
| 86 | + "attributes": {"name": item.artist}, |
| 87 | + "id": item.artist, |
| 88 | + "relationships": { |
| 89 | + "tracks": { |
| 90 | + "data": [{"id": str(item.id), "type": "track"}] |
| 91 | + } |
| 92 | + }, |
| 93 | + "type": "artist", |
| 94 | + } |
| 95 | + ] |
| 96 | + } |
| 97 | + |
| 98 | + def test_albums(self, client, album): |
| 99 | + res = client.get(f"/aura/albums?filter[album]={album.album}") |
| 100 | + |
| 101 | + assert res.status_code == HTTPStatus.OK |
| 102 | + assert res.json == { |
| 103 | + "data": [ |
| 104 | + { |
| 105 | + "attributes": { |
| 106 | + "artist": album.albumartist, |
| 107 | + "title": album.album, |
| 108 | + }, |
| 109 | + "id": str(album.id), |
| 110 | + "relationships": { |
| 111 | + "tracks": { |
| 112 | + "data": [{"id": str(album.id), "type": "track"}] |
| 113 | + }, |
| 114 | + }, |
| 115 | + "type": "album", |
| 116 | + }, |
| 117 | + ] |
| 118 | + } |
0 commit comments