Skip to content

Commit

Permalink
local: Re-add test for mopidy#500 fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcik committed Dec 31, 2013
1 parent e880cb5 commit 29bb2d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions mopidy/backends/local/json.py
Expand Up @@ -52,6 +52,7 @@ def __init__(self, config):
config['local']['data_dir'], b'library.json.gz')

def load(self):
logger.debug('Loading json library from %s', self._json_file)
library = load_library(self._json_file)
self._tracks = dict((t.uri, t) for t in library.get('tracks', []))
return len(self._tracks)
Expand Down
26 changes: 13 additions & 13 deletions tests/backends/local/library_test.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

import copy
import os
import shutil
import tempfile
import unittest

Expand Down Expand Up @@ -89,31 +90,30 @@ def test_refresh_missing_uri(self):
# Verifies that https://github.com/mopidy/mopidy/issues/500
# has been fixed.

# TODO: re-add something that tests this in a more sane way
return
tmpdir = tempfile.mkdtemp()
try:
tmplib = os.path.join(tmpdir, 'library.json.gz')
shutil.copy(path_to_data_dir('library.json.gz'), tmplib)

with tempfile.NamedTemporaryFile() as library:
with open(self.config['local-json']['json_file']) as fh:
library.write(fh.read())
library.flush()

config = copy.deepcopy(self.config)
config['local-json']['json_file'] = library.name
config = {'local': self.config['local'].copy()}
config['local']['data_dir'] = tmpdir
backend = actor.LocalBackend(config=config, audio=None)

# Sanity check that value is in the library
result = backend.library.lookup(self.tracks[0].uri)
self.assertEqual(result, self.tracks[0:1])

# Clear library and refresh
library.seek(0)
library.truncate()
# Clear and refresh.
open(tmplib, 'w').close()
backend.library.refresh()

# Now it should be gone.
result = backend.library.lookup(self.tracks[0].uri)
self.assertEqual(result, [])

finally:
shutil.rmtree(tmpdir)

def test_lookup(self):
tracks = self.library.lookup(self.tracks[0].uri)
self.assertEqual(tracks, self.tracks[0:1])
Expand Down

0 comments on commit 29bb2d5

Please sign in to comment.