Merge pull request #314 from jodal/feature/album-images

models: Add Album.images field (#263)
This commit is contained in:
Thomas Adamcik 2013-01-06 13:04:02 -08:00
commit 1ea83803a5
3 changed files with 20 additions and 2 deletions

View File

@ -76,6 +76,11 @@ Current limitations:
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)
====================

View File

@ -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)

View File

@ -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):