diff --git a/mopidy/models.py b/mopidy/models.py index 758b6c6d..daadf7b8 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -212,6 +212,23 @@ class Ref(ImmutableObject): return cls(**kwargs) +class Image(ImmutableObject): + """ + :param string uri: URI of the image + :param int width: Optional width of image or :class:`None` + :param int height: Optional height of image or :class:`None` + """ + + #: The image URI. Read-only. + uri = None + + #: Optional width of the image or :class:`None`. Read-only. + width = None + + #: Optional height of the image or :class:`None`. Read-only. + height = None + + class Artist(ImmutableObject): """ :param uri: artist URI diff --git a/tests/test_models.py b/tests/test_models.py index ed1586da..af8e0f82 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -4,8 +4,8 @@ import json import unittest from mopidy.models import ( - Album, Artist, ModelJSONEncoder, Playlist, Ref, SearchResult, TlTrack, - Track, model_json_decoder) + Album, Artist, Image, ModelJSONEncoder, Playlist, Ref, SearchResult, + TlTrack, Track, model_json_decoder) class GenericCopyTest(unittest.TestCase): @@ -74,7 +74,7 @@ class RefTest(unittest.TestCase): def test_invalid_kwarg(self): with self.assertRaises(TypeError): - SearchResult(foo='baz') + Ref(foo='baz') def test_repr_without_results(self): self.assertEquals( @@ -123,11 +123,30 @@ class RefTest(unittest.TestCase): self.assertEqual(ref.name, 'bar') self.assertEqual(ref.type, Ref.PLAYLIST) - def test_track_constructor(self): - ref = Ref.track(uri='foo', name='bar') - self.assertEqual(ref.uri, 'foo') - self.assertEqual(ref.name, 'bar') - self.assertEqual(ref.type, Ref.TRACK) + +class ImageTest(unittest.TestCase): + def test_uri(self): + uri = 'an_uri' + image = Image(uri=uri) + self.assertEqual(image.uri, uri) + with self.assertRaises(AttributeError): + image.uri = None + + def test_width(self): + image = Image(width=100) + self.assertEqual(image.width, 100) + with self.assertRaises(AttributeError): + image.width = None + + def test_height(self): + image = Image(height=100) + self.assertEqual(image.height, 100) + with self.assertRaises(AttributeError): + image.height = None + + def test_invalid_kwarg(self): + with self.assertRaises(TypeError): + Image(foo='baz') class ArtistTest(unittest.TestCase):