Merge pull request #549 from adamcik/fix/bug-500-library-refresh-does-not-remove-uris
local: Delete uris in library refresh (fixes #500)
This commit is contained in:
commit
1d651c5ff4
@ -27,9 +27,14 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
|||||||
self._media_dir, self._tag_cache_file)
|
self._media_dir, self._tag_cache_file)
|
||||||
|
|
||||||
tracks = parse_mpd_tag_cache(self._tag_cache_file, self._media_dir)
|
tracks = parse_mpd_tag_cache(self._tag_cache_file, self._media_dir)
|
||||||
|
uris_to_remove = set(self._uri_mapping)
|
||||||
|
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
self._uri_mapping[track.uri] = track
|
self._uri_mapping[track.uri] = track
|
||||||
|
uris_to_remove.discard(track.uri)
|
||||||
|
|
||||||
|
for uri in uris_to_remove:
|
||||||
|
del self._uri_mapping[uri]
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
'Loaded %d local tracks from %s using %s',
|
'Loaded %d local tracks from %s using %s',
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import pykka
|
import pykka
|
||||||
@ -11,6 +12,8 @@ from mopidy.models import Track, Album, Artist
|
|||||||
from tests import path_to_data_dir
|
from tests import path_to_data_dir
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: update tests to only use backend, not core. we need a seperate
|
||||||
|
# core test that does this integration test.
|
||||||
class LocalLibraryProviderTest(unittest.TestCase):
|
class LocalLibraryProviderTest(unittest.TestCase):
|
||||||
artists = [
|
artists = [
|
||||||
Artist(name='artist1'),
|
Artist(name='artist1'),
|
||||||
@ -49,7 +52,6 @@ class LocalLibraryProviderTest(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
||||||
self.backend = actor.LocalBackend.start(
|
self.backend = actor.LocalBackend.start(
|
||||||
config=self.config, audio=None).proxy()
|
config=self.config, audio=None).proxy()
|
||||||
self.core = core.Core(backends=[self.backend])
|
self.core = core.Core(backends=[self.backend])
|
||||||
@ -65,9 +67,31 @@ class LocalLibraryProviderTest(unittest.TestCase):
|
|||||||
def test_refresh_uri(self):
|
def test_refresh_uri(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@unittest.SkipTest
|
|
||||||
def test_refresh_missing_uri(self):
|
def test_refresh_missing_uri(self):
|
||||||
pass
|
# Verifies that https://github.com/mopidy/mopidy/issues/500
|
||||||
|
# has been fixed.
|
||||||
|
|
||||||
|
tag_cache = tempfile.NamedTemporaryFile()
|
||||||
|
with open(self.config['local']['tag_cache_file']) as fh:
|
||||||
|
tag_cache.write(fh.read())
|
||||||
|
tag_cache.flush()
|
||||||
|
|
||||||
|
config = {'local': self.config['local'].copy()}
|
||||||
|
config['local']['tag_cache_file'] = tag_cache.name
|
||||||
|
backend = actor.LocalBackend(config=config, audio=None)
|
||||||
|
|
||||||
|
# Sanity check that value is in tag cache
|
||||||
|
result = backend.library.lookup(self.tracks[0].uri)
|
||||||
|
self.assertEqual(result, self.tracks[0:1])
|
||||||
|
|
||||||
|
# Clear tag cache and refresh
|
||||||
|
tag_cache.seek(0)
|
||||||
|
tag_cache.truncate()
|
||||||
|
backend.library.refresh()
|
||||||
|
|
||||||
|
# Now it should be gone.
|
||||||
|
result = backend.library.lookup(self.tracks[0].uri)
|
||||||
|
self.assertEqual(result, [])
|
||||||
|
|
||||||
def test_lookup(self):
|
def test_lookup(self):
|
||||||
tracks = self.library.lookup(self.tracks[0].uri)
|
tracks = self.library.lookup(self.tracks[0].uri)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user