Make core.stored_playlists.refresh() support multibackend (#217)
This commit is contained in:
parent
8cc1896b9d
commit
fd88b974e8
@ -99,12 +99,25 @@ class StoredPlaylistsController(object):
|
||||
else:
|
||||
return None
|
||||
|
||||
def refresh(self):
|
||||
def refresh(self, uri_scheme=None):
|
||||
"""
|
||||
Refresh the stored playlists in :attr:`playlists`.
|
||||
|
||||
If ``uri_scheme`` is :class:`None`, all backends are asked to refresh.
|
||||
If ``uri_scheme`` is an URI scheme handled by a backend, only that
|
||||
backend is asked to refresh. If ``uri_scheme`` doesn't match any
|
||||
current backend, nothing happens.
|
||||
|
||||
:param uri_scheme: limit to the backend matching the URI scheme
|
||||
:type uri_scheme: string
|
||||
"""
|
||||
# TODO Support multiple backends
|
||||
return self.backends[0].stored_playlists.refresh().get()
|
||||
if uri_scheme is None:
|
||||
futures = [b.stored_playlists.refresh() for b in self.backends]
|
||||
pykka.get_all(futures)
|
||||
else:
|
||||
if uri_scheme in self.backends.by_uri_scheme:
|
||||
backend = self.backends.by_uri_scheme[uri_scheme]
|
||||
backend.stored_playlists.refresh().get()
|
||||
|
||||
def rename(self, playlist, new_name):
|
||||
"""
|
||||
|
||||
@ -71,5 +71,23 @@ class StoredPlaylistsTest(unittest.TestCase):
|
||||
self.assertFalse(self.sp1.lookup.called)
|
||||
self.sp2.lookup.assert_called_once_with('dummy2:a')
|
||||
|
||||
def test_refresh_without_uri_scheme_refreshes_all_backends(self):
|
||||
self.core.stored_playlists.refresh()
|
||||
|
||||
self.sp1.refresh.assert_called_once_with()
|
||||
self.sp2.refresh.assert_called_once_with()
|
||||
|
||||
def test_refresh_with_uri_scheme_refreshes_matching_backend(self):
|
||||
self.core.stored_playlists.refresh(uri_scheme='dummy2')
|
||||
|
||||
self.assertFalse(self.sp1.refresh.called)
|
||||
self.sp2.refresh.assert_called_once_with()
|
||||
|
||||
def test_refresh_with_unknown_uri_scheme_refreshes_nothing(self):
|
||||
self.core.stored_playlists.refresh(uri_scheme='foobar')
|
||||
|
||||
self.assertFalse(self.sp1.refresh.called)
|
||||
self.assertFalse(self.sp2.refresh.called)
|
||||
|
||||
# TODO The rest of the stored playlists API is pending redesign before
|
||||
# we'll update it to support multiple backends.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user