models: Add type specific constructors to Ref

This commit is contained in:
Stein Magnus Jodal 2014-01-09 08:50:26 +01:00
parent 1fd1a38013
commit 9da5ccbb79
2 changed files with 60 additions and 0 deletions

View File

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

View File

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