diff --git a/docs/changes.rst b/docs/changes.rst index dfe46951..d5428a68 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -41,12 +41,13 @@ greatly improved MPD client support. - Support ``pause`` without arguments to work better with MPDroid. - Support ``plchanges``, ``play``, ``consume``, ``random``, ``repeat``, and ``single`` without quotes to work better with BitMPC. - - Fixed delete current playing track from playlist, which crashed several - clients. + - Fixed deletion of the currently playing track from the current playlist, + which crashed several clients. - Implement ``seek`` and ``seekid``. - Fix ``playlistfind`` output so the correct song is played when playing songs directly from search results in GMPC. - - Fix ``load`` so that one can append a playlist to the current playlist. + - Fix ``load`` so that one can append a playlist to the current playlist, and + make it return the correct error message if the playlist is not found. - Support for single track repeat added. (Fixes: :issue:`4`) - Rename ``mopidy.frontends.mpd.{serializer => translator}`` to match naming in backends. diff --git a/mopidy/frontends/mpd/protocol/stored_playlists.py b/mopidy/frontends/mpd/protocol/stored_playlists.py index 25ae4c32..39a2e150 100644 --- a/mopidy/frontends/mpd/protocol/stored_playlists.py +++ b/mopidy/frontends/mpd/protocol/stored_playlists.py @@ -91,9 +91,11 @@ def load(frontend, name): - ``load`` appends the given playlist to the current playlist. """ - matches = frontend.backend.stored_playlists.search(name) - if matches: - frontend.backend.current_playlist.append(matches[0].tracks) + try: + playlist = frontend.backend.stored_playlists.get(name=name) + frontend.backend.current_playlist.append(playlist.tracks) + except LookupError as e: + raise MpdNoExistError(u'No such playlist', command=u'load') @handle_pattern(r'^playlistadd "(?P[^"]+)" "(?P[^"]+)"$') def playlistadd(frontend, name, uri): diff --git a/tests/frontends/mpd/stored_playlists_test.py b/tests/frontends/mpd/stored_playlists_test.py index 9babc670..b49ccce1 100644 --- a/tests/frontends/mpd/stored_playlists_test.py +++ b/tests/frontends/mpd/stored_playlists_test.py @@ -49,12 +49,24 @@ class StoredPlaylistsHandlerTest(unittest.TestCase): self.assert_(u'Last-Modified: 2001-03-17T13:41:17Z' in result) self.assert_(u'OK' in result) - def test_load(self): - result = self.h.handle_request(u'load "name"') + def test_load_known_playlist_appends_to_current_playlist(self): + self.b.current_playlist.append([Track(uri='a'), Track(uri='b')]) + self.assertEqual(len(self.b.current_playlist.tracks), 2) + self.b.stored_playlists.playlists = [Playlist(name='A-list', + tracks=[Track(uri='c'), Track(uri='d'), Track(uri='e')])] + result = self.h.handle_request(u'load "A-list"') self.assert_(u'OK' in result) + self.assertEqual(len(self.b.current_playlist.tracks), 5) + self.assertEqual(self.b.current_playlist.tracks[0].uri, 'a') + self.assertEqual(self.b.current_playlist.tracks[1].uri, 'b') + self.assertEqual(self.b.current_playlist.tracks[2].uri, 'c') + self.assertEqual(self.b.current_playlist.tracks[3].uri, 'd') + self.assertEqual(self.b.current_playlist.tracks[4].uri, 'e') - def test_load_appends(self): - raise SkipTest + def test_load_unknown_playlist_acks(self): + result = self.h.handle_request(u'load "unknown playlist"') + self.assert_(u'ACK [50@0] {load} No such playlist' in result) + self.assertEqual(len(self.b.current_playlist.tracks), 0) def test_playlistadd(self): result = self.h.handle_request(