-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import os | ||
from http import HTTPStatus | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from beets.test.helper import TestHelper | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def helper(): | ||
helper = TestHelper() | ||
helper.setup_beets() | ||
yield helper | ||
helper.teardown_beets() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def app(helper): | ||
from beetsplug.aura import create_app | ||
|
||
app = create_app() | ||
app.config["lib"] = helper.lib | ||
return app | ||
|
||
|
||
class TestResponse: | ||
@pytest.fixture(scope="class", autouse=True) | ||
def _other_album_and_item(self, helper): | ||
item = helper.add_item_fixture( | ||
album="Other Album", | ||
title="Other Title", | ||
artist="Other Artist", | ||
albumartist="Other Album Artist", | ||
) | ||
helper.lib.add_album([item]) | ||
|
||
@pytest.fixture(scope="class") | ||
def item(self, helper): | ||
return helper.add_item_fixture( | ||
album="Album", | ||
title="Title", | ||
artist="Artist", | ||
albumartist="Album Artist", | ||
) | ||
|
||
@pytest.fixture(scope="class") | ||
def album(self, helper, item): | ||
return helper.lib.add_album([item]) | ||
|
||
def test_tracks(self, client, item, album): | ||
res = client.get(f"/aura/tracks?filter[title]={item.title}") | ||
|
||
assert res.status_code == HTTPStatus.OK | ||
assert res.json == { | ||
"data": [ | ||
{ | ||
"attributes": { | ||
"album": item.album, | ||
"albumartist": item.albumartist, | ||
"artist": item.artist, | ||
"size": Path(os.fsdecode(item.path)).stat().st_size, | ||
"title": item.title, | ||
}, | ||
"id": str(item.id), | ||
"relationships": { | ||
"albums": { | ||
"data": [{"id": str(album.id), "type": "album"}] | ||
}, | ||
"artists": { | ||
"data": [{"id": item.artist, "type": "artist"}] | ||
}, | ||
}, | ||
"type": "track", | ||
} | ||
] | ||
} | ||
|
||
def test_artists(self, client, item): | ||
res = client.get(f"/aura/artists?filter[artist]={item.artist}") | ||
|
||
assert res.status_code == HTTPStatus.OK | ||
assert res.json == { | ||
"data": [ | ||
{ | ||
"attributes": {"name": item.artist}, | ||
"id": item.artist, | ||
"relationships": { | ||
"tracks": { | ||
"data": [{"id": str(item.id), "type": "track"}] | ||
} | ||
}, | ||
"type": "artist", | ||
} | ||
] | ||
} | ||
|
||
def test_albums(self, client, album): | ||
res = client.get(f"/aura/albums?filter[album]={album.album}") | ||
|
||
assert res.status_code == HTTPStatus.OK | ||
assert res.json == { | ||
"data": [ | ||
{ | ||
"attributes": { | ||
"artist": album.albumartist, | ||
"title": album.album, | ||
}, | ||
"id": str(album.id), | ||
"relationships": { | ||
"tracks": { | ||
"data": [{"id": str(album.id), "type": "track"}] | ||
}, | ||
}, | ||
"type": "album", | ||
}, | ||
] | ||
} |