1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Deduplicate on getAlbumList

Fixes #199
This commit is contained in:
Alban Féron 2020-11-07 15:44:09 +01:00
parent 194bf5e277
commit 7d1825151e
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
3 changed files with 35 additions and 24 deletions

View File

@ -85,7 +85,7 @@ def album_list():
dict( dict(
album=[ album=[
a.as_subsonic_child(request.user) 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 if s.user.id == request.user.id and count(s.starred.tracks) > 0
) )
elif ltype == "alphabeticalByName": elif ltype == "alphabeticalByName":
query = query.order_by(Folder.name) query = query.order_by(Folder.name).distinct()
elif ltype == "alphabeticalByArtist": elif ltype == "alphabeticalByArtist":
query = query.order_by(lambda f: f.parent.name + f.name) query = query.order_by(lambda f: f.parent.name + f.name)
else: else:

View File

@ -29,13 +29,26 @@ class AlbumSongsTestCase(ApiTestBase):
artist = Artist(name="Artist") artist = Artist(name="Artist")
album = Album(name="Album", artist=artist) album = Album(name="Album", artist=artist)
track = Track( Track(
title="Track", title="Track 1",
album=album, album=album,
artist=artist, artist=artist,
disc=1, disc=1,
number=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, folder=folder,
root_folder=folder, root_folder=folder,
duration=2, duration=2,
@ -51,24 +64,24 @@ class AlbumSongsTestCase(ApiTestBase):
"getAlbumList", {"type": "newest", "offset": "minus one"}, error=0 "getAlbumList", {"type": "newest", "offset": "minus one"}, error=0
) )
types = [ types_and_count = [
"random", ("random", 1),
"newest", ("newest", 1),
"highest", ("highest", 1),
"frequent", ("frequent", 1),
"recent", ("recent", 0), # never played
"alphabeticalByName", ("alphabeticalByName", 1),
(
"alphabeticalByArtist", "alphabeticalByArtist",
"starred", 0, # somehow expected due to funky "album" definition on this endpoint
),
("starred", 0), # nothing's starred
] ]
for t in types: for t, c in types_and_count:
self._make_request( rv, child = self._make_request(
"getAlbumList", {"type": t}, tag="albumList", skip_post=True "getAlbumList", {"type": t}, tag="albumList", skip_post=True
) )
self.assertEqual(len(child), c)
rv, child = self._make_request(
"getAlbumList", {"type": "random"}, tag="albumList", skip_post=True
)
with db_session: with db_session:
Folder.get().delete() Folder.get().delete()
@ -106,7 +119,7 @@ class AlbumSongsTestCase(ApiTestBase):
) )
with db_session: with db_session:
Track.get().delete() Track.select().delete()
Album.get().delete() Album.get().delete()
rv, child = self._make_request( rv, child = self._make_request(
"getAlbumList2", {"type": "random"}, tag="albumList2" "getAlbumList2", {"type": "random"}, tag="albumList2"

View File

@ -82,10 +82,9 @@ class TestBase(unittest.TestCase):
__with_api__ = False __with_api__ = False
def setUp(self): def setUp(self):
self.__dbfile = tempfile.mkstemp()[1]
self.__dir = tempfile.mkdtemp() self.__dir = tempfile.mkdtemp()
config = TestConfig(self.__with_webui__, self.__with_api__) 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 config.WEBAPP["cache_dir"] = self.__dir
init_database(config.BASE["database_uri"]) init_database(config.BASE["database_uri"])
@ -108,4 +107,3 @@ class TestBase(unittest.TestCase):
def tearDown(self): def tearDown(self):
release_database() release_database()
shutil.rmtree(self.__dir) shutil.rmtree(self.__dir)
os.remove(self.__dbfile)