Implement _current_playlist_move_{range,songpos}
This commit is contained in:
parent
434fbb8853
commit
00472ca1bc
@ -306,10 +306,8 @@ class MpdHandler(object):
|
||||
"""
|
||||
self.backend.current_playlist.clear()
|
||||
|
||||
@handle_pattern(r'^move "(?P<songpos>\d+)" "(?P<to>\d+)"$')
|
||||
@handle_pattern(r'^move "(?P<start>\d+):(?P<end>\d+)*" "(?P<to>\d+)"$')
|
||||
def _current_playlist_move(self, songpos=None,
|
||||
start=None, end=None, to=None):
|
||||
def _current_playlist_move_range(self, start, to, end=None):
|
||||
"""
|
||||
*musicpd.org, current playlist section:*
|
||||
|
||||
@ -318,7 +316,18 @@ class MpdHandler(object):
|
||||
Moves the song at ``FROM`` or range of songs at ``START:END`` to
|
||||
``TO`` in the playlist.
|
||||
"""
|
||||
raise MpdNotImplemented # TODO
|
||||
if end is None:
|
||||
end = self.backend.current_playlist.playlist.length
|
||||
start = int(start)
|
||||
end = int(end)
|
||||
to = int(to)
|
||||
self.backend.current_playlist.move(start, end, to)
|
||||
|
||||
@handle_pattern(r'^move "(?P<songpos>\d+)" "(?P<to>\d+)"$')
|
||||
def _current_playlist_move_songpos(self, songpos, to):
|
||||
"""See :meth:`_current_playlist_move_range`."""
|
||||
songpos = int(songpos)
|
||||
self._current_playlist_move_range(start=songpos, end=songpos + 1, to=to)
|
||||
|
||||
@handle_pattern(r'^moveid "(?P<songid>\d+)" "(?P<to>\d+)"$')
|
||||
def _current_playlist_moveid(self, songid, to):
|
||||
|
||||
@ -592,16 +592,43 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
||||
self.assert_(u'ACK Track with ID "0" not found' in result)
|
||||
|
||||
def test_move_songpos(self):
|
||||
result = self.h.handle_request(u'move "5" "0"')
|
||||
self.assert_(u'ACK Not implemented' in result)
|
||||
self.b.current_playlist.load(Playlist(tracks=[
|
||||
Track(name='a'), Track(name='b'), Track(name='c'),
|
||||
Track(name='d'), Track(name='e'), Track(name='f')]))
|
||||
result = self.h.handle_request(u'move "1" "0"')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[0].name, 'b')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[1].name, 'a')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[2].name, 'c')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[3].name, 'd')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[4].name, 'e')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[5].name, 'f')
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
def test_move_open_range(self):
|
||||
result = self.h.handle_request(u'move "10:" "0"')
|
||||
self.assert_(u'ACK Not implemented' in result)
|
||||
self.b.current_playlist.load(Playlist(tracks=[
|
||||
Track(name='a'), Track(name='b'), Track(name='c'),
|
||||
Track(name='d'), Track(name='e'), Track(name='f')]))
|
||||
result = self.h.handle_request(u'move "2:" "0"')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[0].name, 'c')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[1].name, 'd')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[2].name, 'e')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[3].name, 'f')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[4].name, 'a')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[5].name, 'b')
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
def test_move_closed_range(self):
|
||||
result = self.h.handle_request(u'move "10:20" "0"')
|
||||
self.assert_(u'ACK Not implemented' in result)
|
||||
self.b.current_playlist.load(Playlist(tracks=[
|
||||
Track(name='a'), Track(name='b'), Track(name='c'),
|
||||
Track(name='d'), Track(name='e'), Track(name='f')]))
|
||||
result = self.h.handle_request(u'move "1:3" "0"')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[0].name, 'b')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[1].name, 'c')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[2].name, 'a')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[3].name, 'd')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[4].name, 'e')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[5].name, 'f')
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
def test_moveid(self):
|
||||
result = self.h.handle_request(u'moveid "0" "10"')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user