mpd: Update playlistdelete to handle unknown names and indexes

This commit is contained in:
Thomas Adamcik 2015-12-05 14:01:43 +01:00
parent b21debf6ee
commit 5de9495eaa
2 changed files with 15 additions and 3 deletions

View File

@ -254,9 +254,12 @@ def playlistdelete(context, name, songpos):
if not playlist:
raise exceptions.MpdNoExistError('No such playlist')
# Convert tracks to list and remove requested
tracks = list(playlist.tracks)
tracks.pop(songpos)
try:
# Convert tracks to list and remove requested
tracks = list(playlist.tracks)
tracks.pop(songpos)
except IndexError:
raise exceptions.MpdArgError('Bad song index')
# Replace tracks and save playlist
playlist = playlist.replace(tracks=tracks)

View File

@ -314,6 +314,15 @@ class PlaylistsHandlerTest(protocol.BaseTestCase):
'invalid: playlist names may not contain '
'slashes, newlines or carriage returns')
def test_playlistdelete_unknown_playlist_acks(self):
self.send_request('playlistdelete "foobar" "0"')
self.assertInResponse('ACK [50@0] {playlistdelete} No such playlist')
def test_playlistdelete_unknown_index_acks(self):
self.send_request('save "foobar"')
self.send_request('playlistdelete "foobar" "0"')
self.assertInResponse('ACK [2@0] {playlistdelete} Bad song index')
def test_playlistmove(self):
tracks = [
Track(uri='dummy:a'),