Merge pull request #313 from jodal/feature/get-playlists-without-tracks

core: Add 'include_tracks' argument to 'get_playlists()'
This commit is contained in:
Thomas Adamcik 2013-01-06 12:37:48 -08:00
commit 86403acc33
4 changed files with 31 additions and 3 deletions

View File

@ -67,6 +67,15 @@ Current limitations:
contains stream URIs. You need to extract the stream URL from the playlist
yourself. See :issue:`303` for progress on this.
**Core API**
- :meth:`mopidy.core.PlaylistsController.get_playlists` now accepts an argument
``include_tracks``. This defaults to :class:`True`, which has the same old
behavior. If set to :class:`False`, the tracks are stripped from the
playlists before they are returned. This can be used to limit the amount of
data returned if the response is to be passed out of the application, e.g. to
a web client. (Fixes: :issue:`297`)
v0.11.1 (2012-12-24)
====================

View File

@ -15,11 +15,14 @@ class PlaylistsController(object):
self.backends = backends
self.core = core
def get_playlists(self):
def get_playlists(self, include_tracks=True):
futures = [
b.playlists.playlists for b in self.backends.with_playlists]
results = pykka.get_all(futures)
return list(itertools.chain(*results))
playlists = list(itertools.chain(*results))
if not include_tracks:
playlists = [p.copy(tracks=[]) for p in playlists]
return playlists
playlists = property(get_playlists)
"""

View File

@ -46,6 +46,22 @@ class PlaylistsTest(unittest.TestCase):
self.assertIn(self.pl2a, result)
self.assertIn(self.pl2b, result)
def test_get_playlists_includes_tracks_by_default(self):
result = self.core.playlists.get_playlists()
self.assertEqual(result[0].name, 'A')
self.assertEqual(len(result[0].tracks), 1)
self.assertEqual(result[1].name, 'B')
self.assertEqual(len(result[1].tracks), 1)
def test_get_playlist_can_strip_tracks_from_returned_playlists(self):
result = self.core.playlists.get_playlists(include_tracks=False)
self.assertEqual(result[0].name, 'A')
self.assertEqual(len(result[0].tracks), 0)
self.assertEqual(result[1].name, 'B')
self.assertEqual(len(result[1].tracks), 0)
def test_create_without_uri_scheme_uses_first_backend(self):
playlist = Playlist()
self.sp1.create().get.return_value = playlist

View File

@ -603,7 +603,7 @@ class JsonRpcInspectorTest(JsonRpcTestBase):
self.assertIn('core.playlists.get_playlists', methods)
self.assertEquals(
len(methods['core.playlists.get_playlists']['params']), 0)
len(methods['core.playlists.get_playlists']['params']), 1)
self.assertIn('core.tracklist.filter', methods.keys())
self.assertEquals(