Add tests to get full test coverage of MpdHandler
This commit is contained in:
parent
80b1f377b6
commit
e3e5f0c9bb
@ -35,4 +35,5 @@ class DummyPlaybackController(BasePlaybackController):
|
||||
return True
|
||||
|
||||
class DummyStoredPlaylistsController(BaseStoredPlaylistsController):
|
||||
pass
|
||||
def search(self, query):
|
||||
return [Playlist(name=query)]
|
||||
|
||||
@ -394,15 +394,14 @@ class MpdHandler(object):
|
||||
|
||||
@register(r'^stats$')
|
||||
def _stats(self):
|
||||
pass # TODO
|
||||
return {
|
||||
'artists': 0,
|
||||
'albums': 0,
|
||||
'songs': 0,
|
||||
'artists': 0, # TODO
|
||||
'albums': 0, # TODO
|
||||
'songs': 0, # TODO
|
||||
'uptime': self.session.stats_uptime(),
|
||||
'db_playtime': 0,
|
||||
'db_update': 0,
|
||||
'playtime': 0,
|
||||
'db_playtime': 0, # TODO
|
||||
'db_update': 0, # TODO
|
||||
'playtime': 0, # TODO
|
||||
}
|
||||
|
||||
@register(r'^stop$')
|
||||
@ -487,10 +486,12 @@ class MpdHandler(object):
|
||||
return self.backend.playback.time_position
|
||||
|
||||
def _status_time_total(self):
|
||||
if self.backend.playback.current_track is not None:
|
||||
return self.backend.playback.current_track.length // 1000
|
||||
else:
|
||||
if self.backend.playback.current_track is None:
|
||||
return 0
|
||||
elif self.backend.playback.current_track.length is None:
|
||||
return 0
|
||||
else:
|
||||
return self.backend.playback.current_track.length // 1000
|
||||
|
||||
def _status_volume(self):
|
||||
if self.backend.playback.volume is not None:
|
||||
|
||||
@ -144,38 +144,116 @@ class StatusHandlerTest(unittest.TestCase):
|
||||
result = self.h.handle_request(u'status')
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
def test_status_method(self):
|
||||
def test_status_method_contains_volume_which_defaults_to_0(self):
|
||||
self.b.playback.volume = None
|
||||
result = dict(self.h._status())
|
||||
self.assert_('volume' in result)
|
||||
self.assert_(int(result['volume']) in xrange(0, 101))
|
||||
self.assertEquals(int(result['volume']), 0)
|
||||
|
||||
def test_status_method_contains_volume(self):
|
||||
self.b.playback.volume = 17
|
||||
result = dict(self.h._status())
|
||||
self.assert_('volume' in result)
|
||||
self.assertEquals(int(result['volume']), 17)
|
||||
|
||||
def test_status_method_contains_repeat_is_0(self):
|
||||
result = dict(self.h._status())
|
||||
self.assert_('repeat' in result)
|
||||
self.assert_(int(result['repeat']) in (0, 1))
|
||||
self.assertEquals(int(result['repeat']), 0)
|
||||
|
||||
def test_status_method_contains_repeat_is_1(self):
|
||||
self.b.playback.repeat = 1
|
||||
result = dict(self.h._status())
|
||||
self.assert_('repeat' in result)
|
||||
self.assertEquals(int(result['repeat']), 1)
|
||||
|
||||
def test_status_method_contains_random_is_0(self):
|
||||
result = dict(self.h._status())
|
||||
self.assert_('random' in result)
|
||||
self.assert_(int(result['random']) in (0, 1))
|
||||
self.assertEquals(int(result['random']), 0)
|
||||
|
||||
def test_status_method_contains_random_is_1(self):
|
||||
self.b.playback.random = 1
|
||||
result = dict(self.h._status())
|
||||
self.assert_('random' in result)
|
||||
self.assertEquals(int(result['random']), 1)
|
||||
|
||||
def test_status_method_contains_single(self):
|
||||
result = dict(self.h._status())
|
||||
self.assert_('single' in result)
|
||||
self.assert_(int(result['single']) in (0, 1))
|
||||
|
||||
def test_status_method_contains_consume_is_0(self):
|
||||
result = dict(self.h._status())
|
||||
self.assert_('consume' in result)
|
||||
self.assert_(int(result['consume']) in (0, 1))
|
||||
self.assertEquals(int(result['consume']), 0)
|
||||
|
||||
def test_status_method_contains_consume_is_1(self):
|
||||
self.b.playback.consume = 1
|
||||
result = dict(self.h._status())
|
||||
self.assert_('consume' in result)
|
||||
self.assertEquals(int(result['consume']), 1)
|
||||
|
||||
def test_status_method_contains_playlist(self):
|
||||
result = dict(self.h._status())
|
||||
self.assert_('playlist' in result)
|
||||
self.assert_(int(result['playlist']) in xrange(0, 2**31))
|
||||
|
||||
def test_status_method_contains_playlistlength(self):
|
||||
result = dict(self.h._status())
|
||||
self.assert_('playlistlength' in result)
|
||||
self.assert_(int(result['playlistlength']) >= 0)
|
||||
|
||||
def test_status_method_contains_xfade(self):
|
||||
result = dict(self.h._status())
|
||||
self.assert_('xfade' in result)
|
||||
self.assert_(int(result['xfade']) >= 0)
|
||||
self.assert_('state' in result)
|
||||
self.assert_(result['state'] in ('play', 'stop', 'pause'))
|
||||
|
||||
def test_status_method_when_playlist_loaded(self):
|
||||
def test_status_method_contains_state_is_play(self):
|
||||
self.b.playback.state = self.b.playback.PLAYING
|
||||
result = dict(self.h._status())
|
||||
self.assert_('state' in result)
|
||||
self.assertEquals(result['state'], 'play')
|
||||
|
||||
def test_status_method_contains_state_is_stop(self):
|
||||
self.b.playback.state = self.b.playback.STOPPED
|
||||
result = dict(self.h._status())
|
||||
self.assert_('state' in result)
|
||||
self.assertEquals(result['state'], 'stop')
|
||||
|
||||
def test_status_method_contains_state_is_pause(self):
|
||||
self.b.playback.state = self.b.playback.PLAYING
|
||||
self.b.playback.state = self.b.playback.PAUSED
|
||||
result = dict(self.h._status())
|
||||
self.assert_('state' in result)
|
||||
self.assertEquals(result['state'], 'pause')
|
||||
|
||||
def test_status_method_when_playlist_loaded_contains_song(self):
|
||||
track = Track()
|
||||
self.b.current_playlist.load(Playlist(tracks=[track]))
|
||||
self.b.playback.current_track = track
|
||||
result = dict(self.h._status())
|
||||
self.assert_('song' in result)
|
||||
self.assert_(int(result['song']) >= 0)
|
||||
|
||||
def test_status_method_when_playlist_loaded_contains_pos_as_songid(self):
|
||||
track = Track()
|
||||
self.b.current_playlist.load(Playlist(tracks=[track]))
|
||||
self.b.playback.current_track = track
|
||||
result = dict(self.h._status())
|
||||
self.assert_('songid' in result)
|
||||
self.assert_(int(result['songid']) >= 0)
|
||||
|
||||
def test_status_method_when_playing(self):
|
||||
def test_status_method_when_playlist_loaded_contains_id_as_songid(self):
|
||||
track = Track(id=1)
|
||||
self.b.current_playlist.load(Playlist(tracks=[track]))
|
||||
self.b.playback.current_track = track
|
||||
result = dict(self.h._status())
|
||||
self.assert_('songid' in result)
|
||||
self.assertEquals(int(result['songid']), 1)
|
||||
|
||||
def test_status_method_when_playing_contains_time_with_no_length(self):
|
||||
self.b.playback.current_track = Track(length=None)
|
||||
self.b.playback.state = self.b.playback.PLAYING
|
||||
result = dict(self.h._status())
|
||||
self.assert_('time' in result)
|
||||
@ -184,6 +262,23 @@ class StatusHandlerTest(unittest.TestCase):
|
||||
total = int(total)
|
||||
self.assert_(position <= total)
|
||||
|
||||
def test_status_method_when_playing_contains_time_with_length(self):
|
||||
self.b.playback.current_track = Track(length=10000)
|
||||
self.b.playback.state = self.b.playback.PLAYING
|
||||
result = dict(self.h._status())
|
||||
self.assert_('time' in result)
|
||||
(position, total) = result['time'].split(':')
|
||||
position = int(position)
|
||||
total = int(total)
|
||||
self.assert_(position <= total)
|
||||
|
||||
def test_status_method_when_playing_contains_bitrate(self):
|
||||
self.b.playback.state = self.b.playback.PLAYING
|
||||
self.b.playback.current_track = Track(bitrate=320)
|
||||
result = dict(self.h._status())
|
||||
self.assert_('bitrate' in result)
|
||||
self.assertEquals(int(result['bitrate']), 320)
|
||||
|
||||
|
||||
class PlaybackOptionsHandlerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@ -340,6 +435,11 @@ class PlaybackControlHandlerTest(unittest.TestCase):
|
||||
self.assert_(u'OK' in result)
|
||||
self.assertEquals(self.b.playback.PLAYING, self.b.playback.state)
|
||||
|
||||
def test_playid_which_does_not_exist(self):
|
||||
self.b.current_playlist.load(Playlist(tracks=[Track(id=0)]))
|
||||
result = self.h.handle_request(u'playid "1"')
|
||||
self.assert_(u'ACK Track with ID "1" not found' in result)
|
||||
|
||||
def test_previous(self):
|
||||
result = self.h.handle_request(u'previous')
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user