diff --git a/mopidy/core/stored_playlists.py b/mopidy/core/stored_playlists.py index 3525ff67..b34b8bc1 100644 --- a/mopidy/core/stored_playlists.py +++ b/mopidy/core/stored_playlists.py @@ -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): """ diff --git a/tests/core/stored_playlists_test.py b/tests/core/stored_playlists_test.py index aeb22e1a..2e90416e 100644 --- a/tests/core/stored_playlists_test.py +++ b/tests/core/stored_playlists_test.py @@ -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.