audio: Only add albums that have a name

Fixes case where we could have an empty album. We could alternatively be more
conservative and only limit to fully empty albums. But I think we only want
ones with names anyway.
This commit is contained in:
Thomas Adamcik 2014-12-22 22:45:31 +01:00
parent 819680e074
commit 935a038405
3 changed files with 9 additions and 5 deletions

View File

@ -123,7 +123,10 @@ def convert_tags_to_track(tags):
track_kwargs = {k: v for k, v in track_kwargs.items() if v}
album_kwargs = {k: v for k, v in album_kwargs.items() if v}
track_kwargs['album'] = Album(**album_kwargs)
# Only bother with album if we have a name to show.
if album_kwargs.get('name'):
track_kwargs['album'] = Album(**album_kwargs)
return Track(**track_kwargs)

View File

@ -8,6 +8,8 @@ from mopidy.models import Album, Artist, Track
# TODO: keep ids without name?
# TODO: current test is trying to test everything at once with a complete tags
# set, instead we might want to try with a minimal one making testing easier.
class TagsToTrackTest(unittest.TestCase):
def setUp(self): # noqa
self.tags = {
@ -156,8 +158,7 @@ class TagsToTrackTest(unittest.TestCase):
def test_missing_album_name(self):
del self.tags['album']
album = self.track.album.copy(name=None)
self.check(self.track.copy(album=album))
self.check(self.track.copy(album=None))
def test_multiple_album_name(self):
self.tags['album'].append('album2')

View File

@ -11,7 +11,7 @@ import gst # noqa: pygst magic is needed to import correct gst
import mock
from mopidy.models import Album, Track
from mopidy.models import Track
from mopidy.stream import actor
from mopidy.utils.path import path_to_uri
@ -39,5 +39,5 @@ class LibraryProviderTest(unittest.TestCase):
def test_lookup_converts_uri_metadata_to_track(self):
library = actor.StreamLibraryProvider(self.backend, 100, [])
self.assertEqual([Track(length=4406, uri=self.uri, album=Album())],
self.assertEqual([Track(length=4406, uri=self.uri)],
library.lookup(self.uri))