models: Add Album.images field (#263)
This commit is contained in:
parent
86403acc33
commit
6599094b1e
@ -76,6 +76,11 @@ Current limitations:
|
|||||||
data returned if the response is to be passed out of the application, e.g. to
|
data returned if the response is to be passed out of the application, e.g. to
|
||||||
a web client. (Fixes: :issue:`297`)
|
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)
|
v0.11.1 (2012-12-24)
|
||||||
====================
|
====================
|
||||||
|
|||||||
@ -167,6 +167,8 @@ class Album(ImmutableObject):
|
|||||||
:type date: string
|
:type date: string
|
||||||
:param musicbrainz_id: MusicBrainz ID
|
:param musicbrainz_id: MusicBrainz ID
|
||||||
:type musicbrainz_id: string
|
:type musicbrainz_id: string
|
||||||
|
:param images: album image URIs
|
||||||
|
:type images: list of strings
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#: The album URI. Read-only.
|
#: The album URI. Read-only.
|
||||||
@ -187,10 +189,14 @@ class Album(ImmutableObject):
|
|||||||
#: The MusicBrainz ID of the album. Read-only.
|
#: The MusicBrainz ID of the album. Read-only.
|
||||||
musicbrainz_id = None
|
musicbrainz_id = None
|
||||||
|
|
||||||
|
#: The album image URIs. Read-only.
|
||||||
|
images = frozenset()
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5
|
# NOTE kwargs dict keys must be bytestrings to work on Python < 2.6.5
|
||||||
# See https://github.com/mopidy/mopidy/issues/302 for details
|
# See https://github.com/mopidy/mopidy/issues/302 for details
|
||||||
self.__dict__[b'artists'] = frozenset(kwargs.pop('artists', []))
|
self.__dict__[b'artists'] = frozenset(kwargs.pop('artists', []))
|
||||||
|
self.__dict__[b'images'] = frozenset(kwargs.pop('images', []))
|
||||||
super(Album, self).__init__(*args, **kwargs)
|
super(Album, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -216,18 +216,25 @@ class AlbumTest(unittest.TestCase):
|
|||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
AttributeError, setattr, album, 'musicbrainz_id', None)
|
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):
|
def test_invalid_kwarg(self):
|
||||||
test = lambda: Album(foo='baz')
|
test = lambda: Album(foo='baz')
|
||||||
self.assertRaises(TypeError, test)
|
self.assertRaises(TypeError, test)
|
||||||
|
|
||||||
def test_repr_without_artists(self):
|
def test_repr_without_artists(self):
|
||||||
self.assertEquals(
|
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')))
|
repr(Album(uri='uri', name='name')))
|
||||||
|
|
||||||
def test_repr_with_artists(self):
|
def test_repr_with_artists(self):
|
||||||
self.assertEquals(
|
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')])))
|
repr(Album(uri='uri', name='name', artists=[Artist(name='foo')])))
|
||||||
|
|
||||||
def test_serialize_without_artists(self):
|
def test_serialize_without_artists(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user