Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
playlists: Make move from/to same index a no-op
Browse files Browse the repository at this point in the history
Fixes #175
  • Loading branch information
jodal committed Sep 4, 2015
1 parent e565e59 commit 66e7da1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
Changelog
*********


v2.0.3 (UNRELEASED)
===================

Bug fix release.

- Make moving a playlist to its own location a no-op instead of causing an
error like libspotify does. (Fixes: :issue:`175`)


v2.0.2 (2015-08-06)
===================

Expand Down
2 changes: 2 additions & 0 deletions spotify/playlist_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ def move_playlist(self, from_index, to_index, dry_run=False):
If ``dry_run`` is :class:`True` the move isn't actually done. It is
only checked if the move is possible.
"""
if from_index == to_index:
return
spotify.Error.maybe_raise(lib.sp_playlistcontainer_move_playlist(
self._sp_playlistcontainer, from_index, to_index, int(dry_run)))

Expand Down
12 changes: 12 additions & 0 deletions tests/test_playlist_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,18 @@ def test_move_playlist_out_of_range_fails(self, lib_mock):
with self.assertRaises(spotify.Error):
playlist_container.move_playlist(5, 7)

def test_move_playlist_to_itself_is_a_noop(self, lib_mock):
lib_mock.sp_playlistcontainer_move_playlist.return_value = int(
spotify.ErrorType.INVALID_INDATA)
sp_playlistcontainer = spotify.ffi.cast('sp_playlistcontainer *', 42)
playlist_container = spotify.PlaylistContainer(
self.session, sp_playlistcontainer=sp_playlistcontainer)

playlist_container.move_playlist(5, 5)

self.assertEqual(
lib_mock.sp_playlistcontainer_move_playlist.call_count, 0)

@mock.patch('spotify.User', spec=spotify.User)
def test_owner(self, user_mock, lib_mock):
user_mock.return_value = mock.sentinel.user
Expand Down

0 comments on commit 66e7da1

Please sign in to comment.