models: Add type specific constructors to Ref
This commit is contained in:
parent
1fd1a38013
commit
9da5ccbb79
@ -175,6 +175,36 @@ class Ref(ImmutableObject):
|
||||
#: Constant used for comparision with the :attr:`type` field.
|
||||
TRACK = 'track'
|
||||
|
||||
@classmethod
|
||||
def album(cls, **kwargs):
|
||||
"""Create a :class:`Ref` with ``type`` :attr:`ALBUM`."""
|
||||
kwargs['type'] = Ref.ALBUM
|
||||
return cls(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def artist(cls, **kwargs):
|
||||
"""Create a :class:`Ref` with ``type`` :attr:`ARTIST`."""
|
||||
kwargs['type'] = Ref.ARTIST
|
||||
return cls(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def directory(cls, **kwargs):
|
||||
"""Create a :class:`Ref` with ``type`` :attr:`DIRECTORY`."""
|
||||
kwargs['type'] = Ref.DIRECTORY
|
||||
return cls(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def playlist(cls, **kwargs):
|
||||
"""Create a :class:`Ref` with ``type`` :attr:`PLAYLIST`."""
|
||||
kwargs['type'] = Ref.PLAYLIST
|
||||
return cls(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def track(cls, **kwargs):
|
||||
"""Create a :class:`Ref` with ``type`` :attr:`TRACK`."""
|
||||
kwargs['type'] = Ref.TRACK
|
||||
return cls(**kwargs)
|
||||
|
||||
|
||||
class Artist(ImmutableObject):
|
||||
"""
|
||||
|
||||
@ -94,6 +94,36 @@ class RefTest(unittest.TestCase):
|
||||
self.assertEqual(Ref.PLAYLIST, 'playlist')
|
||||
self.assertEqual(Ref.TRACK, 'track')
|
||||
|
||||
def test_album_constructor(self):
|
||||
ref = Ref.album(uri='foo', name='bar')
|
||||
self.assertEqual(ref.uri, 'foo')
|
||||
self.assertEqual(ref.name, 'bar')
|
||||
self.assertEqual(ref.type, Ref.ALBUM)
|
||||
|
||||
def test_artist_constructor(self):
|
||||
ref = Ref.artist(uri='foo', name='bar')
|
||||
self.assertEqual(ref.uri, 'foo')
|
||||
self.assertEqual(ref.name, 'bar')
|
||||
self.assertEqual(ref.type, Ref.ARTIST)
|
||||
|
||||
def test_directory_constructor(self):
|
||||
ref = Ref.directory(uri='foo', name='bar')
|
||||
self.assertEqual(ref.uri, 'foo')
|
||||
self.assertEqual(ref.name, 'bar')
|
||||
self.assertEqual(ref.type, Ref.DIRECTORY)
|
||||
|
||||
def test_playlist_constructor(self):
|
||||
ref = Ref.playlist(uri='foo', name='bar')
|
||||
self.assertEqual(ref.uri, 'foo')
|
||||
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 ArtistTest(unittest.TestCase):
|
||||
def test_uri(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user