diff --git a/docs/changes.rst b/docs/changes.rst index f1df2ae4..82ec44b5 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -33,6 +33,11 @@ v0.11.2 (UNRELEASED) data returned if the response is to be passed out of the application, e.g. to a web client. (Fixes: :issue:`297`) +**Models** + +- Add :attr:`mopidy.models.Album.images` field for including album art URIs. + (Partly fixes :issue:`263`) + v0.11.1 (2012-12-24) ==================== diff --git a/mopidy/models.py b/mopidy/models.py index 1fb3d7a7..1a165222 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -167,6 +167,8 @@ class Album(ImmutableObject): :type date: string :param musicbrainz_id: MusicBrainz ID :type musicbrainz_id: string + :param images: album image URIs + :type images: list of strings """ #: The album URI. Read-only. @@ -187,10 +189,14 @@ class Album(ImmutableObject): #: The MusicBrainz ID of the album. Read-only. musicbrainz_id = None + #: The album image URIs. Read-only. + images = frozenset() + def __init__(self, *args, **kwargs): # NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5 # See https://github.com/mopidy/mopidy/issues/302 for details self.__dict__[b'artists'] = frozenset(kwargs.pop('artists', [])) + self.__dict__[b'images'] = frozenset(kwargs.pop('images', [])) super(Album, self).__init__(*args, **kwargs) diff --git a/tests/models_test.py b/tests/models_test.py index 89d0b132..ef3fd68c 100644 --- a/tests/models_test.py +++ b/tests/models_test.py @@ -216,18 +216,25 @@ class AlbumTest(unittest.TestCase): self.assertRaises( AttributeError, setattr, album, 'musicbrainz_id', None) + def test_images(self): + image = 'data:foobar' + album = Album(images=[image]) + self.assertIn(image, album.images) + self.assertRaises(AttributeError, setattr, album, 'images', None) + def test_invalid_kwarg(self): test = lambda: Album(foo='baz') self.assertRaises(TypeError, test) def test_repr_without_artists(self): self.assertEquals( - "Album(artists=[], name=u'name', uri=u'uri')", + "Album(artists=[], images=[], name=u'name', uri=u'uri')", repr(Album(uri='uri', name='name'))) def test_repr_with_artists(self): self.assertEquals( - "Album(artists=[Artist(name=u'foo')], name=u'name', uri=u'uri')", + "Album(artists=[Artist(name=u'foo')], images=[], name=u'name', " + "uri=u'uri')", repr(Album(uri='uri', name='name', artists=[Artist(name='foo')]))) def test_serialize_without_artists(self):