From 00472ca1bc1ad4eaa8e6747b48873f1d42e00123 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 28 Feb 2010 21:10:53 +0100 Subject: [PATCH] Implement _current_playlist_move_{range,songpos} --- mopidy/mpd/handler.py | 17 +++++++++++++---- tests/mpd/handlertest.py | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/mopidy/mpd/handler.py b/mopidy/mpd/handler.py index fb0f5aa5..3e3752d4 100644 --- a/mopidy/mpd/handler.py +++ b/mopidy/mpd/handler.py @@ -306,10 +306,8 @@ class MpdHandler(object): """ self.backend.current_playlist.clear() - @handle_pattern(r'^move "(?P\d+)" "(?P\d+)"$') @handle_pattern(r'^move "(?P\d+):(?P\d+)*" "(?P\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\d+)" "(?P\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\d+)" "(?P\d+)"$') def _current_playlist_moveid(self, songid, to): diff --git a/tests/mpd/handlertest.py b/tests/mpd/handlertest.py index 7201be0c..c598a1d4 100644 --- a/tests/mpd/handlertest.py +++ b/tests/mpd/handlertest.py @@ -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"')