Make core.stored_playlists.lookup() support multibackend (#217)
This commit is contained in:
parent
e2474da1ef
commit
8cc1896b9d
@ -1,4 +1,5 @@
|
||||
import itertools
|
||||
import urlparse
|
||||
|
||||
import pykka
|
||||
|
||||
@ -85,14 +86,18 @@ class StoredPlaylistsController(object):
|
||||
def lookup(self, uri):
|
||||
"""
|
||||
Lookup playlist with given URI in both the set of stored playlists and
|
||||
in any other playlist sources.
|
||||
in any other playlist sources. Returns :class:`None` if not found.
|
||||
|
||||
:param uri: playlist URI
|
||||
:type uri: string
|
||||
:rtype: :class:`mopidy.models.Playlist`
|
||||
:rtype: :class:`mopidy.models.Playlist` or :class:`None`
|
||||
"""
|
||||
# TODO Support multiple backends
|
||||
return self.backends[0].stored_playlists.lookup(uri).get()
|
||||
uri_scheme = urlparse.urlparse(uri).scheme
|
||||
backend = self.backends.by_uri_scheme.get(uri_scheme, None)
|
||||
if backend:
|
||||
return backend.stored_playlists.lookup(uri).get()
|
||||
else:
|
||||
return None
|
||||
|
||||
def refresh(self):
|
||||
"""
|
||||
|
||||
@ -59,5 +59,17 @@ class StoredPlaylistsTest(unittest.TestCase):
|
||||
self.assertFalse(self.sp1.create.called)
|
||||
self.sp2.create.assert_called_once_with('foo')
|
||||
|
||||
def test_lookup_selects_the_dummy1_backend(self):
|
||||
self.core.stored_playlists.lookup('dummy1:a')
|
||||
|
||||
self.sp1.lookup.assert_called_once_with('dummy1:a')
|
||||
self.assertFalse(self.sp2.lookup.called)
|
||||
|
||||
def test_lookup_selects_the_dummy2_backend(self):
|
||||
self.core.stored_playlists.lookup('dummy2:a')
|
||||
|
||||
self.assertFalse(self.sp1.lookup.called)
|
||||
self.sp2.lookup.assert_called_once_with('dummy2:a')
|
||||
|
||||
# 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