Replace some backend properties with plain fields. Fix failing tests.
This commit is contained in:
parent
230c3af3cb
commit
20e360131f
@ -11,12 +11,16 @@ class BaseBackend(object):
|
||||
PAUSE = u'pause'
|
||||
STOP = u'stop'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._state = self.STOP
|
||||
self._playlists = []
|
||||
self._x_current_playlist = Playlist()
|
||||
self._current_playlist_version = 0
|
||||
|
||||
# Backend state
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
if not hasattr(self, '_state'):
|
||||
self._state = self.STOP
|
||||
return self._state
|
||||
|
||||
@state.setter
|
||||
@ -51,32 +55,14 @@ class BaseBackend(object):
|
||||
def _play_time_resume(self):
|
||||
self._play_time_started = int(time.time())
|
||||
|
||||
@property
|
||||
def _playlists(self):
|
||||
if not hasattr(self, '_x_playlists') or not self._x_playlists:
|
||||
self._x_playlists = []
|
||||
return self._x_playlists
|
||||
|
||||
@_playlists.setter
|
||||
def _playlists(self, playlists):
|
||||
self._x_playlists = playlists
|
||||
|
||||
@property
|
||||
def _current_playlist(self):
|
||||
if not hasattr(self, '_x_current_playlist'):
|
||||
self._x_current_playlist = Playlist()
|
||||
return self._x_current_playlist
|
||||
|
||||
@_current_playlist.setter
|
||||
def _current_playlist(self, playlist):
|
||||
self._x_current_playlist = playlist
|
||||
self._x_current_playlist_version += 1
|
||||
|
||||
@property
|
||||
def _current_playlist_version(self):
|
||||
if not hasattr(self, '_x_current_playlist_version'):
|
||||
self._x_current_playlist_version = 0
|
||||
return self._x_current_playlist_version
|
||||
self._current_playlist_version += 1
|
||||
|
||||
@property
|
||||
def _current_track(self):
|
||||
@ -237,6 +223,12 @@ class BaseBackend(object):
|
||||
if songpos is not None:
|
||||
start = int(songpos)
|
||||
end = start + 1
|
||||
else:
|
||||
if start is None:
|
||||
start = 0
|
||||
start = int(start)
|
||||
if end is not None:
|
||||
end = int(end)
|
||||
return self._current_playlist.mpd_format(start, end)
|
||||
|
||||
# Stored playlist methods
|
||||
|
||||
@ -14,6 +14,7 @@ ENCODING = 'utf-8'
|
||||
|
||||
class DespotifyBackend(BaseBackend):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DespotifyBackend, self).__init__(*args, **kwargs)
|
||||
logger.info(u'Connecting to Spotify')
|
||||
self.spotify = spytify.Spytify(
|
||||
config.SPOTIFY_USERNAME, config.SPOTIFY_PASSWORD)
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
from mopidy.backends import BaseBackend
|
||||
|
||||
class DummyBackend(BaseBackend):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DummyBackend, self).__init__(*args, **kwargs)
|
||||
|
||||
def url_handlers(self):
|
||||
return [u'dummy:']
|
||||
|
||||
|
||||
@ -75,6 +75,7 @@ class LibspotifySession(SpotifySessionManager, threading.Thread):
|
||||
|
||||
class LibspotifyBackend(BaseBackend):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LibspotifyBackend, self).__init__(*args, **kwargs)
|
||||
self.spotify = LibspotifySession(
|
||||
config.SPOTIFY_USERNAME, config.SPOTIFY_PASSWORD)
|
||||
logger.info(u'Connecting to Spotify')
|
||||
|
||||
@ -2,7 +2,8 @@ import unittest
|
||||
|
||||
from mopidy.backends.dummy import DummyBackend
|
||||
from mopidy.exceptions import MpdAckError
|
||||
from mopidy.mpd.handler import MpdHandler
|
||||
from mopidy.models import Track, Playlist
|
||||
from mopidy.mpd import handler
|
||||
|
||||
class DummySession(object):
|
||||
def do_close(self):
|
||||
@ -17,7 +18,7 @@ class DummySession(object):
|
||||
|
||||
class RequestHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
def test_register_same_pattern_twice_fails(self):
|
||||
func = lambda: None
|
||||
@ -44,7 +45,7 @@ class RequestHandlerTest(unittest.TestCase):
|
||||
|
||||
class CommandListsTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
def test_command_list_begin(self):
|
||||
result = self.h.handle_request(u'command_list_begin')
|
||||
@ -86,7 +87,7 @@ class StatusHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.b = DummyBackend()
|
||||
self.s = DummySession()
|
||||
self.h = MpdHandler(backend=self.b, session=self.s)
|
||||
self.h = handler.MpdHandler(backend=self.b, session=self.s)
|
||||
|
||||
def test_clearerror(self):
|
||||
result = self.h.handle_request(u'clearerror')
|
||||
@ -151,7 +152,7 @@ class StatusHandlerTest(unittest.TestCase):
|
||||
self.assert_(result['state'] in ('play', 'stop', 'pause'))
|
||||
|
||||
def test_status_method_when_playlist_loaded(self):
|
||||
self.b.status_playlist_length = lambda: 1
|
||||
self.b._current_playlist = Playlist(tracks=[Track()])
|
||||
result = dict(self.h._status())
|
||||
self.assert_('song' in result)
|
||||
self.assert_(int(result['song']) >= 0)
|
||||
@ -170,7 +171,7 @@ class StatusHandlerTest(unittest.TestCase):
|
||||
|
||||
class PlaybackOptionsHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
def test_consume_off(self):
|
||||
result = self.h.handle_request(u'consume "0"')
|
||||
@ -271,7 +272,7 @@ class PlaybackOptionsHandlerTest(unittest.TestCase):
|
||||
class PlaybackControlHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.b = DummyBackend()
|
||||
self.h = MpdHandler(backend=self.b)
|
||||
self.h = handler.MpdHandler(backend=self.b)
|
||||
|
||||
def test_next(self):
|
||||
result = self.h.handle_request(u'next')
|
||||
@ -325,7 +326,7 @@ class PlaybackControlHandlerTest(unittest.TestCase):
|
||||
|
||||
class CurrentPlaylistHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
def test_add(self):
|
||||
result = self.h.handle_request(u'add "file:///dev/urandom"')
|
||||
@ -443,7 +444,7 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
||||
|
||||
class StoredPlaylistsHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
def test_listplaylist(self):
|
||||
result = self.h.handle_request(u'listplaylist "name"')
|
||||
@ -493,7 +494,7 @@ class StoredPlaylistsHandlerTest(unittest.TestCase):
|
||||
|
||||
class MusicDatabaseHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
def test_count(self):
|
||||
result = self.h.handle_request(u'count "tag" "needle"')
|
||||
@ -609,14 +610,14 @@ class MusicDatabaseHandlerTest(unittest.TestCase):
|
||||
|
||||
class StickersHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
pass # TODO
|
||||
|
||||
|
||||
class ConnectionHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(session=DummySession(),
|
||||
self.h = handler.MpdHandler(session=DummySession(),
|
||||
backend=DummyBackend())
|
||||
|
||||
def test_close(self):
|
||||
@ -641,14 +642,14 @@ class ConnectionHandlerTest(unittest.TestCase):
|
||||
|
||||
class AudioOutputHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
pass # TODO
|
||||
|
||||
|
||||
class ReflectionHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.h = MpdHandler(backend=DummyBackend())
|
||||
self.h = handler.MpdHandler(backend=DummyBackend())
|
||||
|
||||
def test_urlhandlers(self):
|
||||
result = self.h.handle_request(u'urlhandlers')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user