models: Add basic image model

This commit is contained in:
Thomas Adamcik 2015-02-12 22:02:59 +01:00
parent 69d3f90628
commit 05b66ba4a3
2 changed files with 44 additions and 8 deletions

View File

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

View File

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