Skip to content

Commit

Permalink
Test fetching each of the documents
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed May 7, 2024
1 parent 5ef3cbe commit 7eedbfa
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def build_manpages():
"pylast",
"pytest",
"pytest-cov",
"pytest-flask",
"python-mpd2",
"python3-discogs-client>=2.3.15",
"py7zr",
Expand Down
118 changes: 118 additions & 0 deletions test/plugins/test_aura.py
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",
},
]
}

0 comments on commit 7eedbfa

Please sign in to comment.