models: Add basic image model
This commit is contained in:
parent
69d3f90628
commit
05b66ba4a3
@ -212,6 +212,23 @@ class Ref(ImmutableObject):
|
|||||||
return cls(**kwargs)
|
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):
|
class Artist(ImmutableObject):
|
||||||
"""
|
"""
|
||||||
:param uri: artist URI
|
:param uri: artist URI
|
||||||
|
|||||||
@ -4,8 +4,8 @@ import json
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from mopidy.models import (
|
from mopidy.models import (
|
||||||
Album, Artist, ModelJSONEncoder, Playlist, Ref, SearchResult, TlTrack,
|
Album, Artist, Image, ModelJSONEncoder, Playlist, Ref, SearchResult,
|
||||||
Track, model_json_decoder)
|
TlTrack, Track, model_json_decoder)
|
||||||
|
|
||||||
|
|
||||||
class GenericCopyTest(unittest.TestCase):
|
class GenericCopyTest(unittest.TestCase):
|
||||||
@ -74,7 +74,7 @@ class RefTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_invalid_kwarg(self):
|
def test_invalid_kwarg(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
SearchResult(foo='baz')
|
Ref(foo='baz')
|
||||||
|
|
||||||
def test_repr_without_results(self):
|
def test_repr_without_results(self):
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
@ -123,11 +123,30 @@ class RefTest(unittest.TestCase):
|
|||||||
self.assertEqual(ref.name, 'bar')
|
self.assertEqual(ref.name, 'bar')
|
||||||
self.assertEqual(ref.type, Ref.PLAYLIST)
|
self.assertEqual(ref.type, Ref.PLAYLIST)
|
||||||
|
|
||||||
def test_track_constructor(self):
|
|
||||||
ref = Ref.track(uri='foo', name='bar')
|
class ImageTest(unittest.TestCase):
|
||||||
self.assertEqual(ref.uri, 'foo')
|
def test_uri(self):
|
||||||
self.assertEqual(ref.name, 'bar')
|
uri = 'an_uri'
|
||||||
self.assertEqual(ref.type, Ref.TRACK)
|
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):
|
class ArtistTest(unittest.TestCase):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user