Skip to content

Commit

Permalink
Merge ecc0bae into add79d9
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcik committed Oct 27, 2013
2 parents add79d9 + ecc0bae commit 8320985
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions mopidy/backends/local/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ def refresh(self, uri=None):
self._media_dir, self._tag_cache_file)

tracks = parse_mpd_tag_cache(self._tag_cache_file, self._media_dir)
uris_to_remove = set(self._uri_mapping)

for track in tracks:
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(
'Loaded %d local tracks from %s using %s',
Expand Down
30 changes: 27 additions & 3 deletions tests/backends/local/library_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

import tempfile
import unittest

import pykka
Expand All @@ -11,6 +12,8 @@
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):
artists = [
Artist(name='artist1'),
Expand Down Expand Up @@ -49,7 +52,6 @@ class LocalLibraryProviderTest(unittest.TestCase):
}

def setUp(self):

self.backend = actor.LocalBackend.start(
config=self.config, audio=None).proxy()
self.core = core.Core(backends=[self.backend])
Expand All @@ -65,9 +67,31 @@ def test_refresh(self):
def test_refresh_uri(self):
pass

@unittest.SkipTest
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):
tracks = self.library.lookup(self.tracks[0].uri)
Expand Down

0 comments on commit 8320985

Please sign in to comment.