Merge pull request #500 from ysinjab/refactor-unittests-to-accept-generic-user

Refactor two unittests that could fail for some users and make them more generic
This commit is contained in:
Stéphane Bruckert 2020-05-29 09:37:59 +01:00 committed by GitHub
commit 816457b7d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,6 +56,8 @@ class SpotipyPlaylistApiTest(unittest.TestCase):
playlists = self.spotify.user_playlists(self.username, limit=5) playlists = self.spotify.user_playlists(self.username, limit=5)
self.assertTrue('items' in playlists) self.assertTrue('items' in playlists)
for playlist in playlists['items']: for playlist in playlists['items']:
if playlist['uri'] != self.new_playlist_uri:
continue
user = playlist['owner']['id'] user = playlist['owner']['id']
pid = playlist['id'] pid = playlist['id']
results = self.spotify.user_playlist_tracks(user, pid) results = self.spotify.user_playlist_tracks(user, pid)
@ -323,19 +325,19 @@ class SpotipyFollowApiTests(unittest.TestCase):
def test_user_follows_and_unfollows_artist(self): def test_user_follows_and_unfollows_artist(self):
# Initially follows 1 artist # Initially follows 1 artist
res = self.spotify.current_user_followed_artists() current_user_followed_artists = self.spotify.current_user_followed_artists()[
self.assertEqual(res['artists']['total'], 1) 'artists']['total']
# Follow 2 more artists # Follow 2 more artists
artists = ["6DPYiyq5kWVQS4RGwxzPC7", "0NbfKEOTQCcwd6o7wSDOHI"] artists = ["6DPYiyq5kWVQS4RGwxzPC7", "0NbfKEOTQCcwd6o7wSDOHI"]
self.spotify.user_follow_artists(artists) self.spotify.user_follow_artists(artists)
res = self.spotify.current_user_followed_artists() res = self.spotify.current_user_followed_artists()
self.assertEqual(res['artists']['total'], 3) self.assertEqual(res['artists']['total'], current_user_followed_artists + len(artists))
# Unfollow these 2 artists # Unfollow these 2 artists
self.spotify.user_unfollow_artists(artists) self.spotify.user_unfollow_artists(artists)
res = self.spotify.current_user_followed_artists() res = self.spotify.current_user_followed_artists()
self.assertEqual(res['artists']['total'], 1) self.assertEqual(res['artists']['total'], current_user_followed_artists)
def test_user_follows_and_unfollows_user(self): def test_user_follows_and_unfollows_user(self):
# TODO improve after implementing `me/following/contains` # TODO improve after implementing `me/following/contains`