Implement _current_playlist_moveid

This commit is contained in:
Stein Magnus Jodal 2010-02-28 21:15:01 +01:00
parent 00472ca1bc
commit 3180d7faf2
2 changed files with 18 additions and 4 deletions

View File

@ -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<songid>\d+)" "(?P<to>\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):

View File

@ -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')