Implement _current_playlist_swap
This commit is contained in:
parent
c8ee771ebc
commit
b89a6fc46d
@ -496,7 +496,17 @@ class MpdHandler(object):
|
||||
|
||||
Swaps the positions of ``SONG1`` and ``SONG2``.
|
||||
"""
|
||||
raise MpdNotImplemented # TODO
|
||||
songpos1 = int(songpos1)
|
||||
songpos2 = int(songpos2)
|
||||
playlist = self.backend.current_playlist.playlist
|
||||
tracks = playlist.tracks
|
||||
song1 = tracks[songpos1]
|
||||
song2 = tracks[songpos2]
|
||||
del tracks[songpos1]
|
||||
tracks.insert(songpos1, song2)
|
||||
del tracks[songpos2]
|
||||
tracks.insert(songpos2, song1)
|
||||
self.backend.current_playlist.load(playlist.with_(tracks=tracks))
|
||||
|
||||
@handle_pattern(r'^swapid "(?P<songid1>\d+)" "(?P<songid2>\d+)"$')
|
||||
def _current_playlist_swapid(self, songid1, songid2):
|
||||
|
||||
@ -755,8 +755,17 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
def test_swap(self):
|
||||
result = self.h.handle_request(u'swap "10" "20"')
|
||||
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'swap "1" "4"')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[0].name, 'a')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[1].name, 'e')
|
||||
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, 'b')
|
||||
self.assertEquals(self.b.current_playlist.playlist.tracks[5].name, 'f')
|
||||
self.assert_(u'OK' in result)
|
||||
|
||||
def test_swapid(self):
|
||||
result = self.h.handle_request(u'swapid "10" "20"')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user