2017-11-10 23:13:18 +00:00
|
|
|
# This file is part of Supysonic.
|
|
|
|
# Supysonic is a Python implementation of the Subsonic server API.
|
|
|
|
#
|
2020-11-10 13:21:51 +00:00
|
|
|
# Copyright (C) 2017-2020 Alban 'spl0k' Féron
|
2017-11-10 23:13:18 +00:00
|
|
|
#
|
|
|
|
# Distributed under terms of the GNU AGPLv3 license.
|
|
|
|
|
2020-11-29 16:24:28 +00:00
|
|
|
import unittest
|
2017-11-10 23:13:18 +00:00
|
|
|
|
2018-08-11 14:16:34 +00:00
|
|
|
from pony.orm import db_session
|
|
|
|
|
|
|
|
from supysonic.db import Folder, Artist, Album, Track
|
2017-11-10 23:13:18 +00:00
|
|
|
|
|
|
|
from .apitestbase import ApiTestBase
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
|
2017-11-10 23:13:18 +00:00
|
|
|
class AlbumSongsTestCase(ApiTestBase):
|
|
|
|
# I'm too lazy to write proper tests concerning the data on those endpoints
|
|
|
|
# Let's just check paramter validation and ensure coverage
|
|
|
|
|
|
|
|
def setUp(self):
|
2020-11-22 15:12:14 +00:00
|
|
|
super().setUp()
|
2017-11-10 23:13:18 +00:00
|
|
|
|
2017-12-23 21:59:04 +00:00
|
|
|
with db_session:
|
2019-06-29 15:25:44 +00:00
|
|
|
folder = Folder(name="Root", root=True, path="tests/assets")
|
|
|
|
artist = Artist(name="Artist")
|
|
|
|
album = Album(name="Album", artist=artist)
|
2017-12-23 21:59:04 +00:00
|
|
|
|
2020-11-07 14:44:09 +00:00
|
|
|
Track(
|
|
|
|
title="Track 1",
|
2019-06-29 15:25:44 +00:00
|
|
|
album=album,
|
|
|
|
artist=artist,
|
|
|
|
disc=1,
|
|
|
|
number=1,
|
2020-11-10 13:21:51 +00:00
|
|
|
year=123,
|
2020-11-07 14:44:09 +00:00
|
|
|
path="tests/assets/folder/1",
|
|
|
|
folder=folder,
|
|
|
|
root_folder=folder,
|
|
|
|
duration=2,
|
|
|
|
bitrate=320,
|
|
|
|
last_modification=0,
|
|
|
|
)
|
|
|
|
Track(
|
|
|
|
title="Track 2",
|
|
|
|
album=album,
|
|
|
|
artist=artist,
|
|
|
|
disc=1,
|
|
|
|
number=1,
|
2020-11-10 13:21:51 +00:00
|
|
|
year=124,
|
|
|
|
genre="Lampshade",
|
2020-11-07 14:44:09 +00:00
|
|
|
path="tests/assets/folder/2",
|
2019-06-29 15:25:44 +00:00
|
|
|
folder=folder,
|
|
|
|
root_folder=folder,
|
|
|
|
duration=2,
|
|
|
|
bitrate=320,
|
|
|
|
last_modification=0,
|
2017-12-23 21:59:04 +00:00
|
|
|
)
|
2017-11-10 23:13:18 +00:00
|
|
|
|
|
|
|
def test_get_album_list(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("getAlbumList", error=10)
|
|
|
|
self._make_request("getAlbumList", {"type": "kraken"}, error=0)
|
|
|
|
self._make_request("getAlbumList", {"type": "random", "size": "huge"}, error=0)
|
|
|
|
self._make_request(
|
|
|
|
"getAlbumList", {"type": "newest", "offset": "minus one"}, error=0
|
|
|
|
)
|
2020-11-10 13:21:51 +00:00
|
|
|
self._make_request("getAlbumList", {"type": "byYear"}, error=10)
|
|
|
|
self._make_request(
|
|
|
|
"getAlbumList",
|
|
|
|
{"type": "byYear", "fromYear": "Epoch", "toYear": "EOL"},
|
|
|
|
error=0,
|
|
|
|
)
|
|
|
|
self._make_request("getAlbumList", {"type": "byGenre"}, error=10)
|
2019-06-29 15:25:44 +00:00
|
|
|
|
2020-11-07 14:44:09 +00:00
|
|
|
types_and_count = [
|
|
|
|
("random", 1),
|
|
|
|
("newest", 1),
|
|
|
|
("highest", 1),
|
|
|
|
("frequent", 1),
|
|
|
|
("recent", 0), # never played
|
|
|
|
("alphabeticalByName", 1),
|
|
|
|
(
|
|
|
|
"alphabeticalByArtist",
|
|
|
|
0, # somehow expected due to funky "album" definition on this endpoint
|
|
|
|
),
|
|
|
|
("starred", 0), # nothing's starred
|
2019-06-29 15:25:44 +00:00
|
|
|
]
|
2020-11-07 14:44:09 +00:00
|
|
|
for t, c in types_and_count:
|
|
|
|
rv, child = self._make_request(
|
2020-11-10 13:21:51 +00:00
|
|
|
"getAlbumList", {"type": t}, tag="albumList", skip_post=t == "random"
|
2019-06-29 15:25:44 +00:00
|
|
|
)
|
2020-11-07 14:44:09 +00:00
|
|
|
self.assertEqual(len(child), c)
|
2017-11-10 23:13:18 +00:00
|
|
|
|
2020-11-10 13:21:51 +00:00
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList",
|
|
|
|
{"type": "byYear", "fromYear": 100, "toYear": 200},
|
|
|
|
tag="albumList",
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 1)
|
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList",
|
|
|
|
{"type": "byYear", "fromYear": 200, "toYear": 300},
|
|
|
|
tag="albumList",
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 0)
|
|
|
|
# Need more data to properly test ordering
|
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList",
|
|
|
|
{"type": "byYear", "fromYear": 200, "toYear": 100},
|
|
|
|
tag="albumList",
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 1)
|
|
|
|
|
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList", {"type": "byGenre", "genre": "FARTS"}, tag="albumList"
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 0)
|
|
|
|
|
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList", {"type": "byGenre", "genre": "Lampshade"}, tag="albumList"
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 1)
|
|
|
|
|
2017-12-23 21:59:04 +00:00
|
|
|
with db_session:
|
|
|
|
Folder.get().delete()
|
2019-06-29 15:25:44 +00:00
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList", {"type": "random"}, tag="albumList"
|
|
|
|
)
|
2017-11-10 23:13:18 +00:00
|
|
|
self.assertEqual(len(child), 0)
|
|
|
|
|
|
|
|
def test_get_album_list2(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("getAlbumList2", error=10)
|
|
|
|
self._make_request("getAlbumList2", {"type": "void"}, error=0)
|
|
|
|
self._make_request(
|
|
|
|
"getAlbumList2", {"type": "random", "size": "size_t"}, error=0
|
|
|
|
)
|
|
|
|
self._make_request(
|
|
|
|
"getAlbumList2", {"type": "newest", "offset": "&v + 2"}, error=0
|
|
|
|
)
|
2020-11-10 13:21:51 +00:00
|
|
|
self._make_request("getAlbumList2", {"type": "byYear"}, error=10)
|
|
|
|
self._make_request(
|
|
|
|
"getAlbumList2",
|
|
|
|
{"type": "byYear", "fromYear": "Epoch", "toYear": "EOL"},
|
|
|
|
error=0,
|
|
|
|
)
|
|
|
|
self._make_request("getAlbumList2", {"type": "byGenre"}, error=10)
|
2019-06-29 15:25:44 +00:00
|
|
|
|
|
|
|
types = [
|
|
|
|
"random",
|
|
|
|
"newest",
|
|
|
|
"frequent",
|
|
|
|
"recent",
|
|
|
|
"starred",
|
|
|
|
"alphabeticalByName",
|
|
|
|
"alphabeticalByArtist",
|
|
|
|
]
|
2017-11-10 23:13:18 +00:00
|
|
|
for t in types:
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request(
|
2020-11-10 13:21:51 +00:00
|
|
|
"getAlbumList2", {"type": t}, tag="albumList2", skip_post=t == "random"
|
2019-06-29 15:25:44 +00:00
|
|
|
)
|
2017-11-10 23:13:18 +00:00
|
|
|
|
2020-11-10 13:21:51 +00:00
|
|
|
self._make_request(
|
2019-06-29 15:25:44 +00:00
|
|
|
"getAlbumList2", {"type": "random"}, tag="albumList2", skip_post=True
|
|
|
|
)
|
2017-11-10 23:13:18 +00:00
|
|
|
|
2020-11-10 13:21:51 +00:00
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList2",
|
|
|
|
{"type": "byYear", "fromYear": 100, "toYear": 200},
|
|
|
|
tag="albumList2",
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 1)
|
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList2",
|
|
|
|
{"type": "byYear", "fromYear": 200, "toYear": 300},
|
|
|
|
tag="albumList2",
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 0)
|
|
|
|
# Need more data to properly test ordering
|
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList2",
|
|
|
|
{"type": "byYear", "fromYear": 200, "toYear": 100},
|
|
|
|
tag="albumList2",
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 1)
|
|
|
|
|
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList2", {"type": "byGenre", "genre": "FARTS"}, tag="albumList2"
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 0)
|
|
|
|
|
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList2", {"type": "byGenre", "genre": "Lampshade"}, tag="albumList2"
|
|
|
|
)
|
|
|
|
self.assertEqual(len(child), 1)
|
|
|
|
|
2017-12-23 21:59:04 +00:00
|
|
|
with db_session:
|
2020-11-07 14:44:09 +00:00
|
|
|
Track.select().delete()
|
2017-12-23 21:59:04 +00:00
|
|
|
Album.get().delete()
|
2019-06-29 15:25:44 +00:00
|
|
|
rv, child = self._make_request(
|
|
|
|
"getAlbumList2", {"type": "random"}, tag="albumList2"
|
|
|
|
)
|
2017-11-10 23:13:18 +00:00
|
|
|
self.assertEqual(len(child), 0)
|
|
|
|
|
|
|
|
def test_get_random_songs(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("getRandomSongs", {"size": "8 floors"}, error=0)
|
|
|
|
self._make_request("getRandomSongs", {"fromYear": "year"}, error=0)
|
|
|
|
self._make_request("getRandomSongs", {"toYear": "year"}, error=0)
|
|
|
|
self._make_request("getRandomSongs", {"musicFolderId": "idid"}, error=0)
|
2019-10-01 14:55:23 +00:00
|
|
|
self._make_request("getRandomSongs", {"musicFolderId": 1234567890}, error=70)
|
2017-11-10 23:13:18 +00:00
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
rv, child = self._make_request(
|
|
|
|
"getRandomSongs", tag="randomSongs", skip_post=True
|
|
|
|
)
|
2017-11-10 23:13:18 +00:00
|
|
|
|
2017-12-23 21:59:04 +00:00
|
|
|
with db_session:
|
|
|
|
fid = Folder.get().id
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request(
|
|
|
|
"getRandomSongs",
|
|
|
|
{
|
|
|
|
"fromYear": -52,
|
|
|
|
"toYear": "1984",
|
|
|
|
"genre": "some cryptic subgenre youve never heard of",
|
|
|
|
"musicFolderId": fid,
|
|
|
|
},
|
|
|
|
tag="randomSongs",
|
|
|
|
)
|
2017-11-10 23:13:18 +00:00
|
|
|
|
|
|
|
def test_now_playing(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("getNowPlaying", tag="nowPlaying")
|
2017-11-10 23:13:18 +00:00
|
|
|
|
|
|
|
def test_get_starred(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("getStarred", tag="starred")
|
2017-11-10 23:13:18 +00:00
|
|
|
|
|
|
|
def test_get_starred2(self):
|
2019-06-29 15:25:44 +00:00
|
|
|
self._make_request("getStarred2", tag="starred2")
|
2017-11-10 23:13:18 +00:00
|
|
|
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|