local: Return multiple tracks from lookup()
This commit is contained in:
parent
c6f88feb00
commit
380223bb96
@ -99,11 +99,9 @@ class Library(object):
|
||||
"""
|
||||
Lookup the given URI.
|
||||
|
||||
Unlike the core APIs, local tracks uris can only be resolved to a
|
||||
single track.
|
||||
|
||||
:param string uri: track URI
|
||||
:rtype: :class:`~mopidy.models.Track`
|
||||
:rtype: List of :class:`~mopidy.models.Track` or single
|
||||
:class:`~mopidy.models.Track` for backward compatibility
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@ -33,11 +33,13 @@ class LocalLibraryProvider(backend.LibraryProvider):
|
||||
def lookup(self, uri):
|
||||
if not self._library:
|
||||
return []
|
||||
track = self._library.lookup(uri)
|
||||
if track is None:
|
||||
tracks = self._library.lookup(uri)
|
||||
if tracks is None:
|
||||
logger.debug('Failed to lookup %r', uri)
|
||||
return []
|
||||
return [track]
|
||||
if isinstance(tracks, models.Track):
|
||||
tracks = [tracks]
|
||||
return tracks
|
||||
|
||||
def find_exact(self, query=None, uris=None):
|
||||
if not self._library:
|
||||
|
||||
@ -4,6 +4,7 @@ import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
import mock
|
||||
|
||||
import pykka
|
||||
|
||||
@ -129,6 +130,26 @@ class LocalLibraryProviderTest(unittest.TestCase):
|
||||
tracks = self.library.lookup('fake uri')
|
||||
self.assertEqual(tracks, [])
|
||||
|
||||
@mock.patch.object(
|
||||
json.JsonLibrary, 'lookup')
|
||||
def test_lookup_multiple_tracks(self, mock_lookup):
|
||||
backend = actor.LocalBackend(config=self.config, audio=None)
|
||||
|
||||
mock_lookup.return_value = self.tracks
|
||||
tracks = backend.library.lookup('fake album uri')
|
||||
mock_lookup.assert_called_with('fake album uri')
|
||||
self.assertEqual(tracks, self.tracks)
|
||||
|
||||
mock_lookup.return_value = [self.tracks[0]]
|
||||
tracks = backend.library.lookup(self.tracks[0].uri)
|
||||
mock_lookup.assert_called_with(self.tracks[0].uri)
|
||||
self.assertEqual(tracks, self.tracks[0:1])
|
||||
|
||||
mock_lookup.return_value = []
|
||||
tracks = backend.library.lookup('fake uri')
|
||||
mock_lookup.assert_called_with('fake uri')
|
||||
self.assertEqual(tracks, [])
|
||||
|
||||
# TODO: move to search_test module
|
||||
def test_find_exact_no_hits(self):
|
||||
result = self.library.find_exact(track_name=['unknown track'])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user