From 3180d7faf2092a00bd64572f90f2c1d0053b2f58 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 28 Feb 2010 21:15:01 +0100 Subject: [PATCH] Implement _current_playlist_moveid --- mopidy/mpd/handler.py | 9 +++++++-- tests/mpd/handlertest.py | 13 +++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mopidy/mpd/handler.py b/mopidy/mpd/handler.py index 3e3752d4..6a79c490 100644 --- a/mopidy/mpd/handler.py +++ b/mopidy/mpd/handler.py @@ -327,7 +327,8 @@ class MpdHandler(object): 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) + to = int(to) + self.backend.current_playlist.move(songpos, songpos + 1, to) @handle_pattern(r'^moveid "(?P\d+)" "(?P\d+)"$') def _current_playlist_moveid(self, songid, to): @@ -340,7 +341,11 @@ class MpdHandler(object): the playlist. If ``TO`` is negative, it is relative to the current song in the playlist (if there is one). """ - raise MpdNotImplemented # TODO + songid = int(songid) + to = int(to) + track = self.backend.current_playlist.get_by_id(songid) + position = self.backend.current_playlist.playlist.tracks.index(track) + self.backend.current_playlist.move(position, position + 1, to) @handle_pattern(r'^playlist$') def _current_playlist_playlist(self): diff --git a/tests/mpd/handlertest.py b/tests/mpd/handlertest.py index c598a1d4..04466190 100644 --- a/tests/mpd/handlertest.py +++ b/tests/mpd/handlertest.py @@ -631,8 +631,17 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_moveid(self): - result = self.h.handle_request(u'moveid "0" "10"') - 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', id=137), Track(name='f')])) + result = self.h.handle_request(u'moveid "137" "2"') + self.assertEquals(self.b.current_playlist.playlist.tracks[0].name, 'a') + self.assertEquals(self.b.current_playlist.playlist.tracks[1].name, 'b') + self.assertEquals(self.b.current_playlist.playlist.tracks[2].name, 'e') + self.assertEquals(self.b.current_playlist.playlist.tracks[3].name, 'c') + self.assertEquals(self.b.current_playlist.playlist.tracks[4].name, 'd') + self.assertEquals(self.b.current_playlist.playlist.tracks[5].name, 'f') + self.assert_(u'OK' in result) def test_playlist_returns_same_as_playlistinfo(self): playlist_result = self.h.handle_request(u'playlist')