backend: Add playlists.as_list() and playlists.get_items(uri)
This commit is contained in:
parent
9462071e0c
commit
55b1eb7383
@ -318,6 +318,36 @@ class PlaylistsProvider(object):
|
||||
def playlists(self, playlists):
|
||||
raise NotImplementedError
|
||||
|
||||
def as_list(self):
|
||||
"""
|
||||
Get a list of the currently available playlists.
|
||||
|
||||
Returns a list of :class:`~mopidy.models.Ref` objects referring to the
|
||||
playlists. In other words, no information about the playlists' content
|
||||
is given.
|
||||
|
||||
:rtype: list of :class:`mopidy.models.Ref`
|
||||
|
||||
.. versionadded:: 1.0
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def get_items(self, uri):
|
||||
"""
|
||||
Get the items in a playlist specified by ``uri``.
|
||||
|
||||
Returns a list of :class:`~mopidy.models.Ref` objects referring to the
|
||||
playlist's items.
|
||||
|
||||
If a playlist with the given ``uri`` doesn't exist, it returns
|
||||
:class:`None`.
|
||||
|
||||
:rtype: list of :class:`mopidy.models.Ref`, or :class:`None`
|
||||
|
||||
.. versionadded:: 1.0
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def create(self, name):
|
||||
"""
|
||||
Create a new empty playlist with the given name.
|
||||
|
||||
@ -8,6 +8,7 @@ from tests import dummy_backend
|
||||
|
||||
|
||||
class LibraryTest(unittest.TestCase):
|
||||
|
||||
def test_default_get_images_impl_falls_back_to_album_image(self):
|
||||
album = models.Album(images=['imageuri'])
|
||||
track = models.Track(uri='trackuri', album=album)
|
||||
@ -31,10 +32,20 @@ class LibraryTest(unittest.TestCase):
|
||||
|
||||
|
||||
class PlaylistsTest(unittest.TestCase):
|
||||
def test_playlists_default_impl(self):
|
||||
playlists = backend.PlaylistsProvider(backend=None)
|
||||
|
||||
self.assertEqual(playlists.playlists, [])
|
||||
def setUp(self): # noqa: N802
|
||||
self.provider = backend.PlaylistsProvider(backend=None)
|
||||
|
||||
def test_playlists_default_impl(self):
|
||||
self.assertEqual(self.provider.playlists, [])
|
||||
|
||||
with self.assertRaises(NotImplementedError):
|
||||
playlists.playlists = []
|
||||
self.provider.playlists = []
|
||||
|
||||
def test_as_list_default_impl(self):
|
||||
with self.assertRaises(NotImplementedError):
|
||||
self.provider.as_list()
|
||||
|
||||
def test_get_items_default_impl(self):
|
||||
with self.assertRaises(NotImplementedError):
|
||||
self.provider.get_items('some uri')
|
||||
|
||||
@ -100,6 +100,17 @@ class DummyPlaylistsProvider(backend.PlaylistsProvider):
|
||||
super(DummyPlaylistsProvider, self).__init__(backend)
|
||||
self._playlists = []
|
||||
|
||||
def as_list(self):
|
||||
return [
|
||||
Ref.playlist(uri=pl.uri, name=pl.name) for pl in self._playlists]
|
||||
|
||||
def get_items(self, uri):
|
||||
playlist = self._playlists.get(uri)
|
||||
if playlist is None:
|
||||
return
|
||||
return [
|
||||
Ref.track(uri=t.uri, name=t.name) for t in playlist.tracks]
|
||||
|
||||
@property
|
||||
def playlists(self):
|
||||
return copy.copy(self._playlists)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user