local: Update browse cache code to add all directories

Tests have been updated to make sure multiple folders are added. We had
forgotten to add child folders to the ones that had already been created.
This commit is contained in:
Thomas Adamcik 2014-01-19 22:21:02 +01:00
parent 4026e16996
commit 9ba168e9b9
2 changed files with 20 additions and 9 deletions

View File

@ -66,12 +66,15 @@ class _BrowseCache(object):
for i in reversed(range(len(parts))):
directory = '/'.join(parts[:i+1])
uri = translator.path_to_local_directory_uri(directory)
# First dir we process is our parent
if not parent_uri:
parent_uri = uri
# We found ourselves and we exist, done.
if uri in self._cache:
if child:
self._cache[uri][child.uri] = child
break
# Initialize ourselves, store child if present, and add

View File

@ -7,26 +7,34 @@ from mopidy.models import Ref
class BrowseCacheTest(unittest.TestCase):
maxDiff = None
def setUp(self):
self.uris = [b'local:track:foo/bar/song1',
b'local:track:foo/bar/song2',
b'local:track:foo/song3']
self.uris = ['local:track:foo/bar/song1',
'local:track:foo/bar/song2',
'local:track:foo/baz/song3',
'local:track:foo/song4',
'local:track:song5']
self.cache = json._BrowseCache(self.uris)
def test_lookup_root(self):
expected = [Ref.directory(uri='local:directory:foo', name='foo')]
self.assertEqual(expected, self.cache.lookup('local:directory'))
expected = [Ref.directory(uri='local:directory:foo', name='foo'),
Ref.track(uri='local:track:song5', name='song5')]
self.assertItemsEqual(expected, self.cache.lookup('local:directory'))
def test_lookup_foo(self):
expected = [Ref.directory(uri='local:directory:foo/bar', name='bar'),
Ref.track(uri=self.uris[2], name='song3')]
self.assertEqual(expected, self.cache.lookup('local:directory:foo'))
Ref.directory(uri='local:directory:foo/baz', name='baz'),
Ref.track(uri=self.uris[3], name='song4')]
result = self.cache.lookup('local:directory:foo')
self.assertItemsEqual(expected, result)
def test_lookup_foo_bar(self):
expected = [Ref.track(uri=self.uris[0], name='song1'),
Ref.track(uri=self.uris[1], name='song2')]
self.assertEqual(
self.assertItemsEqual(
expected, self.cache.lookup('local:directory:foo/bar'))
def test_lookup_foo_baz(self):
self.assertEqual([], self.cache.lookup('local:directory:foo/baz'))
result = self.cache.lookup('local:directory:foo/unknown')
self.assertItemsEqual([], result)