1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00

Consider embeded art when serializing albums, add relevant test

This commit is contained in:
Taizo Simpson 2018-10-12 19:07:48 -04:00
parent 6efb8e8c2d
commit 066658f167
No known key found for this signature in database
GPG Key ID: D197B1197B2D4D68
2 changed files with 14 additions and 7 deletions

View File

@ -190,6 +190,10 @@ class Album(db.Entity):
track_with_cover = self.tracks.select(lambda t: t.folder.cover_art is not None).first()
if track_with_cover is not None:
info['coverArt'] = str(track_with_cover.folder.id)
else:
track_with_cover = self.tracks.select(lambda t: t.has_art).first()
if track_with_cover is not None:
info['coverArt'] = str(track_with_cover.id)
try:
starred = StarredAlbum[user.id, self.id]

View File

@ -97,9 +97,9 @@ class DbTestCase(unittest.TestCase):
return track1, track2
def create_track_in(self, folder, root):
artist = db.Artist(name = 'Snazzy Artist')
album = db.Album(artist = artist, name = 'Rockin\' Album')
def create_track_in(self, folder, root, artist = None, album = None, has_art = True):
artist = artist or db.Artist(name = 'Snazzy Artist')
album = album or db.Album(artist = artist, name = 'Rockin\' Album')
return db.Track(
title = 'Nifty Number',
album = album,
@ -107,7 +107,7 @@ class DbTestCase(unittest.TestCase):
disc = 1,
number = 1,
duration = 5,
has_art = True,
has_art = has_art,
bitrate = 96,
path = 'tests/assets/formats/silence.flac',
content_type = 'audio/flac',
@ -234,7 +234,8 @@ class DbTestCase(unittest.TestCase):
# No tracks, shouldn't be stored under normal circumstances
self.assertRaises(ValueError, album.as_subsonic_album, user)
self.create_some_tracks(artist, album)
root_folder, folder_art, folder_noart = self.create_some_folders()
track1 = self.create_track_in(root_folder, folder_noart, artist = artist, album = album)
album_dict = album.as_subsonic_album(user)
self.assertIsInstance(album_dict, dict)
@ -246,11 +247,13 @@ class DbTestCase(unittest.TestCase):
self.assertIn('duration', album_dict)
self.assertIn('created', album_dict)
self.assertIn('starred', album_dict)
self.assertIn('coverArt', album_dict)
self.assertEqual(album_dict['name'], album.name)
self.assertEqual(album_dict['artist'], artist.name)
self.assertEqual(album_dict['artistId'], str(artist.id))
self.assertEqual(album_dict['songCount'], 2)
self.assertEqual(album_dict['duration'], 8)
self.assertEqual(album_dict['songCount'], 1)
self.assertEqual(album_dict['duration'], 5)
self.assertEqual(album_dict['coverArt'], str(track1.id))
self.assertRegex(album_dict['created'], date_regex)
self.assertRegex(album_dict['starred'], date_regex)