From bd2e4f7af0cabeaa0d271aaca1cd6a8b0e7077fa Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 22 Mar 2015 23:43:57 +0100 Subject: [PATCH] core: Reimplement get_playlists() using new backend API --- mopidy/core/playlists.py | 16 +++++++++------- tests/core/test_playlists.py | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/mopidy/core/playlists.py b/mopidy/core/playlists.py index 146b8058..715e5870 100644 --- a/mopidy/core/playlists.py +++ b/mopidy/core/playlists.py @@ -6,6 +6,7 @@ import urlparse import pykka from mopidy.core import listener +from mopidy.models import Playlist from mopidy.utils.deprecation import deprecated_property @@ -62,13 +63,14 @@ class PlaylistsController(object): .. deprecated:: 1.0 Use :meth:`as_list` and :meth:`get_items` instead. """ - futures = [b.playlists.playlists - for b in self.backends.with_playlists.values()] - results = pykka.get_all(futures) - playlists = list(itertools.chain(*results)) - if not include_tracks: - playlists = [p.copy(tracks=[]) for p in playlists] - return playlists + playlist_refs = self.as_list() + + if include_tracks: + playlists = [self.lookup(r.uri) for r in playlist_refs] + return [pl for pl in playlists if pl is not None] + else: + return [ + Playlist(uri=r.uri, name=r.name) for r in playlist_refs] playlists = deprecated_property(get_playlists) """ diff --git a/tests/core/test_playlists.py b/tests/core/test_playlists.py index 232631d7..fecbbdcb 100644 --- a/tests/core/test_playlists.py +++ b/tests/core/test_playlists.py @@ -23,12 +23,12 @@ class PlaylistsTest(unittest.TestCase): self.sp1 = mock.Mock(spec=backend.PlaylistsProvider) self.sp1.as_list.return_value.get.return_value = [ self.plr1a, self.plr1b] - self.sp1.playlists.get.return_value = [self.pl1a, self.pl1b] + self.sp1.lookup.return_value.get.side_effect = [self.pl1a, self.pl1b] self.sp2 = mock.Mock(spec=backend.PlaylistsProvider) self.sp2.as_list.return_value.get.return_value = [ self.plr2a, self.plr2b] - self.sp2.playlists.get.return_value = [self.pl2a, self.pl2b] + self.sp2.lookup.return_value.get.side_effect = [self.pl2a, self.pl2b] self.backend1 = mock.Mock() self.backend1.uri_schemes.get.return_value = ['dummy1'] @@ -73,7 +73,7 @@ class PlaylistsTest(unittest.TestCase): self.assertFalse(self.sp2.delete.called) def test_get_playlists_combines_result_from_backends(self): - result = self.core.playlists.playlists + result = self.core.playlists.get_playlists() self.assertIn(self.pl1a, result) self.assertIn(self.pl1b, result)