core: Make lookup(uris=...) return dict with all uris
All uris given to lookup should be in the result even if there is no backend to handle the uri, and the lookup result thus is an empty list. As a side effect, future.get() is now called in the order of the URIs in the `uris` list, making it easier to mock out backend.library.lookup() in core layer tests.
This commit is contained in:
parent
35a8fecd5d
commit
f67e55618c
@ -188,20 +188,26 @@ class LibraryController(object):
|
||||
if none_set or both_set:
|
||||
raise ValueError("One of 'uri' or 'uris' must be set")
|
||||
|
||||
if uri is not None:
|
||||
uris = [uri]
|
||||
|
||||
futures = {}
|
||||
result = {}
|
||||
backends = self._get_backends_to_uris([uri] if uri else uris)
|
||||
backends = self._get_backends_to_uris(uris)
|
||||
|
||||
# TODO: lookup(uris) to backend APIs
|
||||
for backend, backend_uris in backends.items():
|
||||
for u in backend_uris or []:
|
||||
futures[u] = backend.library.lookup(u)
|
||||
|
||||
for u, future in futures.items():
|
||||
result[u] = future.get()
|
||||
for u in uris:
|
||||
if u in futures:
|
||||
result[u] = futures[u].get()
|
||||
else:
|
||||
result[u] = []
|
||||
|
||||
if uri:
|
||||
return result.get(uri, [])
|
||||
return result[uri]
|
||||
return result
|
||||
|
||||
def refresh(self, uri=None):
|
||||
|
||||
@ -168,13 +168,20 @@ class CoreLibraryTest(unittest.TestCase):
|
||||
result = self.core.library.lookup(uris=['dummy1:a', 'dummy2:a'])
|
||||
self.assertEqual(result, {'dummy2:a': [5678], 'dummy1:a': [1234]})
|
||||
|
||||
def test_lookup_returns_nothing_for_dummy3_track(self):
|
||||
def test_lookup_uri_returns_empty_list_for_dummy3_track(self):
|
||||
result = self.core.library.lookup('dummy3:a')
|
||||
|
||||
self.assertEqual(result, [])
|
||||
self.assertFalse(self.library1.lookup.called)
|
||||
self.assertFalse(self.library2.lookup.called)
|
||||
|
||||
def test_lookup_uris_returns_empty_list_for_dummy3_track(self):
|
||||
result = self.core.library.lookup(uris=['dummy3:a'])
|
||||
|
||||
self.assertEqual(result, {'dummy3:a': []})
|
||||
self.assertFalse(self.library1.lookup.called)
|
||||
self.assertFalse(self.library2.lookup.called)
|
||||
|
||||
def test_refresh_with_uri_selects_dummy1_backend(self):
|
||||
self.core.library.refresh('dummy1:a')
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user