Make core.stored_playlists.lookup() support multibackend (#217)

This commit is contained in:
Stein Magnus Jodal 2012-10-31 09:47:31 +01:00
parent e2474da1ef
commit 8cc1896b9d
2 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import itertools import itertools
import urlparse
import pykka import pykka
@ -85,14 +86,18 @@ class StoredPlaylistsController(object):
def lookup(self, uri): def lookup(self, uri):
""" """
Lookup playlist with given URI in both the set of stored playlists and 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 :param uri: playlist URI
:type uri: string :type uri: string
:rtype: :class:`mopidy.models.Playlist` :rtype: :class:`mopidy.models.Playlist` or :class:`None`
""" """
# TODO Support multiple backends uri_scheme = urlparse.urlparse(uri).scheme
return self.backends[0].stored_playlists.lookup(uri).get() 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): def refresh(self):
""" """

View File

@ -59,5 +59,17 @@ class StoredPlaylistsTest(unittest.TestCase):
self.assertFalse(self.sp1.create.called) self.assertFalse(self.sp1.create.called)
self.sp2.create.assert_called_once_with('foo') 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 # TODO The rest of the stored playlists API is pending redesign before
# we'll update it to support multiple backends. # we'll update it to support multiple backends.