mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
parent
194bf5e277
commit
7d1825151e
@ -85,7 +85,7 @@ def album_list():
|
||||
dict(
|
||||
album=[
|
||||
a.as_subsonic_child(request.user)
|
||||
for a in query.without_distinct().random(size)
|
||||
for a in query.distinct().random(size)
|
||||
]
|
||||
),
|
||||
)
|
||||
@ -106,7 +106,7 @@ def album_list():
|
||||
if s.user.id == request.user.id and count(s.starred.tracks) > 0
|
||||
)
|
||||
elif ltype == "alphabeticalByName":
|
||||
query = query.order_by(Folder.name)
|
||||
query = query.order_by(Folder.name).distinct()
|
||||
elif ltype == "alphabeticalByArtist":
|
||||
query = query.order_by(lambda f: f.parent.name + f.name)
|
||||
else:
|
||||
|
@ -29,13 +29,26 @@ class AlbumSongsTestCase(ApiTestBase):
|
||||
artist = Artist(name="Artist")
|
||||
album = Album(name="Album", artist=artist)
|
||||
|
||||
track = Track(
|
||||
title="Track",
|
||||
Track(
|
||||
title="Track 1",
|
||||
album=album,
|
||||
artist=artist,
|
||||
disc=1,
|
||||
number=1,
|
||||
path="tests/assets/empty",
|
||||
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,
|
||||
path="tests/assets/folder/2",
|
||||
folder=folder,
|
||||
root_folder=folder,
|
||||
duration=2,
|
||||
@ -51,24 +64,24 @@ class AlbumSongsTestCase(ApiTestBase):
|
||||
"getAlbumList", {"type": "newest", "offset": "minus one"}, error=0
|
||||
)
|
||||
|
||||
types = [
|
||||
"random",
|
||||
"newest",
|
||||
"highest",
|
||||
"frequent",
|
||||
"recent",
|
||||
"alphabeticalByName",
|
||||
types_and_count = [
|
||||
("random", 1),
|
||||
("newest", 1),
|
||||
("highest", 1),
|
||||
("frequent", 1),
|
||||
("recent", 0), # never played
|
||||
("alphabeticalByName", 1),
|
||||
(
|
||||
"alphabeticalByArtist",
|
||||
"starred",
|
||||
0, # somehow expected due to funky "album" definition on this endpoint
|
||||
),
|
||||
("starred", 0), # nothing's starred
|
||||
]
|
||||
for t in types:
|
||||
self._make_request(
|
||||
for t, c in types_and_count:
|
||||
rv, child = self._make_request(
|
||||
"getAlbumList", {"type": t}, tag="albumList", skip_post=True
|
||||
)
|
||||
|
||||
rv, child = self._make_request(
|
||||
"getAlbumList", {"type": "random"}, tag="albumList", skip_post=True
|
||||
)
|
||||
self.assertEqual(len(child), c)
|
||||
|
||||
with db_session:
|
||||
Folder.get().delete()
|
||||
@ -106,7 +119,7 @@ class AlbumSongsTestCase(ApiTestBase):
|
||||
)
|
||||
|
||||
with db_session:
|
||||
Track.get().delete()
|
||||
Track.select().delete()
|
||||
Album.get().delete()
|
||||
rv, child = self._make_request(
|
||||
"getAlbumList2", {"type": "random"}, tag="albumList2"
|
||||
|
@ -82,10 +82,9 @@ class TestBase(unittest.TestCase):
|
||||
__with_api__ = False
|
||||
|
||||
def setUp(self):
|
||||
self.__dbfile = tempfile.mkstemp()[1]
|
||||
self.__dir = tempfile.mkdtemp()
|
||||
config = TestConfig(self.__with_webui__, self.__with_api__)
|
||||
config.BASE["database_uri"] = "sqlite:///" + self.__dbfile
|
||||
config.BASE["database_uri"] = "sqlite:"
|
||||
config.WEBAPP["cache_dir"] = self.__dir
|
||||
|
||||
init_database(config.BASE["database_uri"])
|
||||
@ -108,4 +107,3 @@ class TestBase(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
release_database()
|
||||
shutil.rmtree(self.__dir)
|
||||
os.remove(self.__dbfile)
|
||||
|
Loading…
Reference in New Issue
Block a user