core: Reimplement get_playlists() using new backend API

This commit is contained in:
Stein Magnus Jodal 2015-03-22 23:43:57 +01:00
parent 4f3a0839b3
commit bd2e4f7af0
2 changed files with 12 additions and 10 deletions

View File

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

View File

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