From 36c830021fa28fd0498eaf659d0672f7fbc31798 Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Sat, 31 Dec 2016 10:58:01 -0500 Subject: [PATCH] added unfollow endpoint + tests --- spotipy/client.py | 12 ++++++++++++ tests/authtests.py | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/spotipy/client.py b/spotipy/client.py index d54740d..1b9387d 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -507,6 +507,18 @@ class Spotify(object): ''' return self._put("users/{}/playlists/{}/followers".format(playlist_owner_id, playlist_id)) + def user_playlist_is_following(self, playlist_owner_id, playlist_id, user_ids): + ''' + Check to see if the given users are following the given playlist + + Parameters: + - playlist_owner_id - the user id of the playlist owner + - playlist_id - the id of the playlist + - user_ids - the ids of the users that you want to check to see if they follow the playlist. Maximum: 5 ids. + + ''' + return self._get("users/{}/playlists/{}/followers/contains?ids={}".format(playlist_owner_id, playlist_id, ','.join(user_ids))) + def me(self): ''' Get detailed profile information about the current user. An alias for the 'current_user' method. diff --git a/tests/authtests.py b/tests/authtests.py index a0e7e3b..13504a6 100644 --- a/tests/authtests.py +++ b/tests/authtests.py @@ -91,6 +91,19 @@ class AuthTestSpotipy(unittest.TestCase): self.assertTrue('items' in playlists) self.assertTrue(len(playlists['items']) == 10) + def test_user_playlist_follow(self): + spotify.user_playlist_follow_playlist('plamere', '4erXB04MxwRAVqcUEpu30O') + follows = spotify.user_playlist_is_following('plamere', '4erXB04MxwRAVqcUEpu30O', ['plamere']) + + self.assertTrue(len(follows) == 1, 'proper follows length') + self.assertTrue(follows[0], 'is following') + spotify.user_playlist_unfollow('plamere', '4erXB04MxwRAVqcUEpu30O') + + follows = spotify.user_playlist_is_following('plamere', '4erXB04MxwRAVqcUEpu30O', ['plamere']) + self.assertTrue(len(follows) == 1, 'proper follows length') + self.assertFalse(follows[0], 'is no longer following') + + def test_current_user_save_and_unsave_tracks(self): tracks = spotify.current_user_saved_tracks() total = tracks['total']