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