Retries For All Endpoints, fixes #347 (#457)

* test_improvements - Add __init__.py files to tests dirs so you can run all tests

* test_improvements - added helpers file, restructured tests to work without previous data and to be grouped with api type

* http_retries - Implement Retry for all requests

* Readme - Update README with contributing info

* PR Feedback - Added CONTRIBUTING.md, fixed README, fixed test
This commit is contained in:
Dj authored and GitHub committed 2020-03-29 17:18:23 +01:00
1 parent 8b84300597
commit 024a6c96d4
9 files changed
+382 -328

No files matched your search

View File
Whitespace-only changes.
+19
View File
@@ -0,0 +1,19 @@
import base64
import requests
def get_spotify_playlist(spotify_object, playlist_name, username):
playlists = spotify_object.user_playlists(username)
while playlists:
for item in playlists['items']:
if item['name'] == playlist_name:
return item
playlists = spotify_object.next(playlists)
def create_spotify_playlist(spotify_object, playlist_name, username):
return spotify_object.user_playlist_create(username, playlist_name)
def get_as_base64(url):
return base64.b64encode(requests.get(url).content).decode("utf-8")
View File
Whitespace-only changes.
+6 -11
View File
@@ -189,15 +189,11 @@ class AuthTestSpotipy(unittest.TestCase):
def test_search_timeout(self):
client_credentials_manager = SpotifyClientCredentials()
sp = spotipy.Spotify(
client_credentials_manager=client_credentials_manager,
requests_timeout=.01)
sp = spotipy.Spotify(requests_timeout=0.01,
client_credentials_manager=client_credentials_manager)
try:
with self.assertRaises(requests.exceptions.Timeout):
sp.search(q='my*', type='track')
self.assertTrue(False, 'unexpected search timeout')
except requests.exceptions.Timeout:
self.assertTrue(True, 'expected search timeout')
def test_album_search(self):
results = self.spotify.search(q='weezer pinkerton', type='album')
@@ -302,10 +298,9 @@ class AuthTestSpotipy(unittest.TestCase):
sess.close()
def test_force_no_requests_session(self):
from requests import Session
with_no_session = spotipy.Spotify(
client_credentials_manager=SpotifyClientCredentials(),
requests_session=False)
self.assertFalse(isinstance(with_no_session._session, Session))
self.assertTrue(with_no_session.user(user="akx")
["uri"] == "spotify:user:akx")
self.assertNotIsInstance(with_no_session._session, requests.Session)
user = with_no_session.user(user="akx")
self.assertEqual(user["uri"], "spotify:user:akx")
+270 -269
View File
@@ -1,20 +1,4 @@
# -*- coding: utf-8 -*-
"""
These tests require user authentication - provide client credentials using the
following environment variables
::
'SPOTIPY_CLIENT_USERNAME'
'SPOTIPY_CLIENT_ID'
'SPOTIPY_CLIENT_SECRET'
'SPOTIPY_REDIRECT_URI'
"""
from __future__ import print_function
import os
import sys
from spotipy import (
CLIENT_CREDS_ENV_VARS as CCEV,
@@ -23,63 +7,23 @@ from spotipy import (
SpotifyException,
)
import unittest
import warnings
import requests
from pprint import pprint # noqa
from tests import helpers
class AuthTestSpotipy(unittest.TestCase):
"""
These tests require user authentication - provide client credentials using
the following environment variables
::
'SPOTIPY_CLIENT_USERNAME'
'SPOTIPY_CLIENT_ID'
'SPOTIPY_CLIENT_SECRET'
'SPOTIPY_REDIRECT_URI'
"""
playlist = "spotify:user:plamere:playlist:2oCEWyyAPbZp9xhVSxZavx"
playlist_new_id = "spotify:playlist:7GlxpQjjxRjmbb3RP2rDqI"
four_tracks = ["spotify:track:6RtPijgfPKROxEzTHNRiDp",
"spotify:track:7IHOIqZUUInxjVkko181PB",
"4VrWlk8IQxevMvERoX08iC",
"http://open.spotify.com/track/3cySlItpiPiIAzU3NyHCJf"]
two_tracks = ["spotify:track:6RtPijgfPKROxEzTHNRiDp",
"spotify:track:7IHOIqZUUInxjVkko181PB"]
other_tracks = ["spotify:track:2wySlB6vMzCbQrRnNGOYKa",
"spotify:track:29xKs5BAHlmlX1u4gzQAbJ",
"spotify:track:1PB7gRWcvefzu7t3LJLUlf"]
album_ids = ["spotify:album:6kL09DaURb7rAoqqaA51KU",
"spotify:album:6RTzC0rDbvagTSJLlY7AKl"]
bad_id = 'BAD_ID'
class SpotipyPlaylistApiTest(unittest.TestCase):
@classmethod
def setUpClass(self):
if sys.version_info >= (3, 2):
# >= Python3.2 only
warnings.filterwarnings(
"ignore",
category=ResourceWarning, # noqa
message="unclosed.*<ssl.SSLSocket.*>")
def setUpClass(cls):
cls.four_tracks = ["spotify:track:6RtPijgfPKROxEzTHNRiDp",
"spotify:track:7IHOIqZUUInxjVkko181PB",
"4VrWlk8IQxevMvERoX08iC",
"http://open.spotify.com/track/3cySlItpiPiIAzU3NyHCJf"]
cls.other_tracks = ["spotify:track:2wySlB6vMzCbQrRnNGOYKa",
"spotify:track:29xKs5BAHlmlX1u4gzQAbJ",
"spotify:track:1PB7gRWcvefzu7t3LJLUlf"]
cls.username = os.getenv(CCEV['client_username'])
missing = list(filter(lambda var: not os.getenv(CCEV[var]), CCEV))
if missing:
raise Exception(
('Please set the client credentials for the test application'
' using the following environment variables: {}').format(
CCEV.values()))
self.username = os.getenv(CCEV['client_username'])
self.scope = (
scope = (
'playlist-modify-public '
'user-library-read '
'user-follow-read '
@@ -88,52 +32,25 @@ class AuthTestSpotipy(unittest.TestCase):
'user-top-read '
'user-follow-modify '
'user-read-recently-played '
'ugc-image-upload'
'ugc-image-upload '
'user-read-playback-state'
)
self.token = prompt_for_user_token(self.username, scope=self.scope)
token = prompt_for_user_token(cls.username, scope=scope)
self.spotify = Spotify(auth=self.token)
cls.spotify = Spotify(auth=token)
# Helper
def get_or_create_spotify_playlist(self, playlist_name):
playlists = self.spotify.user_playlists(self.username)
while playlists:
for item in playlists['items']:
if item['name'] == playlist_name:
return item
playlists = self.spotify.next(playlists)
return self.spotify.user_playlist_create(
self.username, playlist_name)
# Helper
def get_as_base64(self, url):
import base64
return base64.b64encode(requests.get(url).content).decode("utf-8")
def test_track_bad_id(self):
try:
self.spotify.track(self.bad_id)
self.assertTrue(False)
except SpotifyException:
self.assertTrue(True)
def test_basic_user_profile(self):
user = self.spotify.user(self.username)
self.assertTrue(user['id'] == self.username.lower())
def test_current_user(self):
user = self.spotify.current_user()
self.assertTrue(user['id'] == self.username.lower())
def test_me(self):
user = self.spotify.me()
self.assertTrue(user['id'] == self.username.lower())
cls.new_playlist_name = 'spotipy-playlist-test'
cls.new_playlist = helpers.get_spotify_playlist(
cls.spotify, cls.new_playlist_name, cls.username) or \
helpers.create_spotify_playlist(
cls.spotify, cls.new_playlist_name, cls.username)
cls.new_playlist_uri = cls.new_playlist['uri']
def test_user_playlists(self):
playlists = self.spotify.user_playlists(self.username, limit=5)
self.assertTrue('items' in playlists)
self.assertTrue(len(playlists['items']) == 5)
self.assertGreaterEqual(len(playlists['items']), 1)
def test_user_playlist_tracks(self):
playlists = self.spotify.user_playlists(self.username, limit=5)
@@ -142,53 +59,135 @@ class AuthTestSpotipy(unittest.TestCase):
user = playlist['owner']['id']
pid = playlist['id']
results = self.spotify.user_playlist_tracks(user, pid)
self.assertTrue(len(results['items']) >= 0)
def test_current_user_saved_albums(self):
# List
albums = self.spotify.current_user_saved_albums()
self.assertTrue(len(albums['items']) > 1)
# Add
self.spotify.current_user_saved_albums_add(self.album_ids)
# Contains
self.assertTrue(
self.spotify.current_user_saved_albums_contains(
self.album_ids) == [
True, True])
# Remove
self.spotify.current_user_saved_albums_delete(self.album_ids)
albums = self.spotify.current_user_saved_albums()
self.assertTrue(len(albums['items']) > 1)
self.assertEquals(len(results['items']), 0)
def test_current_user_playlists(self):
playlists = self.spotify.current_user_playlists(limit=10)
self.assertTrue('items' in playlists)
self.assertTrue(len(playlists['items']) == 10)
self.assertGreaterEqual(len(playlists['items']), 1)
self.assertLessEqual(len(playlists['items']), 10)
def test_user_playlist_follow(self):
user_to_follow = 'plamere'
user_to_follow_id = '4erXB04MxwRAVqcUEpu30O'
self.spotify.user_playlist_follow_playlist(
'plamere', '4erXB04MxwRAVqcUEpu30O')
user_to_follow, user_to_follow_id)
follows = self.spotify.user_playlist_is_following(
'plamere', '4erXB04MxwRAVqcUEpu30O', [
self.spotify.current_user()['id']])
user_to_follow, user_to_follow_id, [self.username])
self.assertTrue(len(follows) == 1, 'proper follows length')
self.assertTrue(follows[0], 'is following')
self.spotify.user_playlist_unfollow(
'plamere', '4erXB04MxwRAVqcUEpu30O')
user_to_follow, user_to_follow_id)
follows = self.spotify.user_playlist_is_following(
'plamere', '4erXB04MxwRAVqcUEpu30O', [
self.spotify.current_user()['id']])
user_to_follow, user_to_follow_id, [self.username])
self.assertTrue(len(follows) == 1, 'proper follows length')
self.assertFalse(follows[0], 'is no longer following')
def test_user_playlist_replace_tracks(self):
# add tracks to playlist
self.spotify.user_playlist_add_tracks(
self.username, self.new_playlist['id'], self.four_tracks)
playlist = self.spotify.user_playlist(self.username, self.new_playlist['id'])
self.assertEqual(playlist['tracks']['total'], 4)
self.assertEqual(len(playlist['tracks']['items']), 4)
# replace with 3 other tracks
self.spotify.user_playlist_replace_tracks(self.username,
self.new_playlist['id'],
self.other_tracks)
playlist = self.spotify.user_playlist(self.username,
self.new_playlist['id'])
self.assertEqual(playlist['tracks']['total'], 3)
self.assertEqual(len(playlist['tracks']['items']), 3)
self.spotify.user_playlist_remove_all_occurrences_of_tracks(
self.username, playlist['id'], self.other_tracks)
playlist = self.spotify.user_playlist(self.username, self.new_playlist['id'])
self.assertEqual(playlist["tracks"]["total"], 0)
def test_get_playlist_by_id(self):
pl = self.spotify.playlist(self.new_playlist['id'])
self.assertEqual(pl["tracks"]["total"], 0)
def test_playlist_add_tracks(self):
# add tracks to playlist
self.spotify.user_playlist_add_tracks(
self.username, self.new_playlist['id'], self.other_tracks)
playlist = self.spotify.user_playlist(self.username, self.new_playlist['id'])
self.assertEqual(playlist['tracks']['total'], 3)
self.assertEqual(len(playlist['tracks']['items']), 3)
pl = self.spotify.playlist_tracks(self.new_playlist['id'], limit=2)
self.assertEqual(len(pl["items"]), 2)
self.spotify.user_playlist_remove_all_occurrences_of_tracks(
self.username, playlist['id'], self.other_tracks)
playlist = self.spotify.user_playlist(self.username, self.new_playlist['id'])
self.assertEqual(playlist["tracks"]["total"], 0)
def test_playlist_cover_image(self):
# Upload random dog image
r = requests.get('https://dog.ceo/api/breeds/image/random')
dog_base64 = helpers.get_as_base64(r.json()['message'])
self.spotify.playlist_upload_cover_image(self.new_playlist_uri, dog_base64)
res = self.spotify.playlist_cover_image(self.new_playlist_uri)
self.assertEquals(len(res), 1)
first_image = res[0]
self.assertIn('width', first_image)
self.assertIn('height', first_image)
self.assertIn('url', first_image)
def test_deprecated_starred(self):
pl = self.spotify.user_playlist(self.username)
self.assertTrue(pl["tracks"] is None)
self.assertTrue(pl["owner"] is None)
def test_deprecated_user_playlist(self):
# Test without user due to change from
# https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/
pl = self.spotify.user_playlist(None, self.new_playlist['id'])
self.assertEqual(pl["tracks"]["total"], 0)
class SpotipyLibraryApiTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.four_tracks = ["spotify:track:6RtPijgfPKROxEzTHNRiDp",
"spotify:track:7IHOIqZUUInxjVkko181PB",
"4VrWlk8IQxevMvERoX08iC",
"http://open.spotify.com/track/3cySlItpiPiIAzU3NyHCJf"]
cls.album_ids = ["spotify:album:6kL09DaURb7rAoqqaA51KU",
"spotify:album:6RTzC0rDbvagTSJLlY7AKl"]
cls.username = os.getenv(CCEV['client_username'])
scope = (
'playlist-modify-public '
'user-library-read '
'user-follow-read '
'user-library-modify '
'user-read-private '
'user-top-read '
'user-follow-modify '
'user-read-recently-played '
'ugc-image-upload '
'user-read-playback-state'
)
token = prompt_for_user_token(cls.username, scope=scope)
cls.spotify = Spotify(auth=token)
def test_track_bad_id(self):
with self.assertRaises(SpotifyException):
self.spotify.track('BadID123')
def test_current_user_saved_tracks(self):
# TODO make this not fail if someone doesnthave saved tracks
tracks = self.spotify.current_user_saved_tracks()
self.assertTrue(len(tracks['items']) > 0)
self.assertGreater(len(tracks['items']), 0)
def test_current_user_save_and_unsave_tracks(self):
tracks = self.spotify.current_user_saved_tracks()
@@ -197,168 +196,146 @@ class AuthTestSpotipy(unittest.TestCase):
tracks = self.spotify.current_user_saved_tracks()
new_total = tracks['total']
self.assertTrue(new_total - total == len(self.four_tracks))
self.assertEquals(new_total - total, len(self.four_tracks))
tracks = self.spotify.current_user_saved_tracks_delete(
self.four_tracks)
tracks = self.spotify.current_user_saved_tracks()
new_total = tracks['total']
self.assertTrue(new_total == total)
self.assertEquals(new_total, total)
def test_categories(self):
response = self.spotify.categories()
self.assertTrue(len(response['categories']) > 0)
def test_current_user_saved_albums(self):
# Add
self.spotify.current_user_saved_albums_add(self.album_ids)
albums = self.spotify.current_user_saved_albums()
self.assertGreaterEqual(len(albums['items']), 2)
def test_category_playlists(self):
response = self.spotify.categories()
for cat in response['categories']['items']:
cat_id = cat['id']
response = self.spotify.category_playlists(category_id=cat_id)
if len(response['playlists']["items"]) > 0:
break
self.assertTrue(True)
# Contains
resp = self.spotify.current_user_saved_albums_contains(self.album_ids)
self.assertEquals(resp, [True, True])
def test_new_releases(self):
response = self.spotify.new_releases()
self.assertTrue(len(response['albums']) > 0)
# Remove
self.spotify.current_user_saved_albums_delete(self.album_ids)
resp = self.spotify.current_user_saved_albums_contains(self.album_ids)
self.assertEquals(resp, [False, False])
def test_featured_releases(self):
response = self.spotify.featured_playlists()
self.assertTrue(len(response['playlists']) > 0)
def test_current_user_follows(self):
response = self.spotify.current_user_followed_artists()
artists = response['artists']
self.assertTrue(len(artists['items']) > 0)
class SpotipyUserApiTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.username = os.getenv(CCEV['client_username'])
scope = (
'playlist-modify-public '
'user-library-read '
'user-follow-read '
'user-library-modify '
'user-read-private '
'user-top-read '
'user-follow-modify '
'user-read-recently-played '
'ugc-image-upload '
'user-read-playback-state'
)
token = prompt_for_user_token(cls.username, scope=scope)
cls.spotify = Spotify(auth=token)
def test_basic_user_profile(self):
user = self.spotify.user(self.username)
self.assertEquals(user['id'], self.username.lower())
def test_current_user(self):
user = self.spotify.current_user()
self.assertEquals(user['id'], self.username.lower())
def test_me(self):
user = self.spotify.me()
self.assertTrue(user['id'] == self.username.lower())
def test_current_user_top_tracks(self):
response = self.spotify.current_user_top_tracks()
items = response['items']
self.assertTrue(len(items) > 0)
self.assertGreater(len(items), 0)
def test_current_user_top_artists(self):
response = self.spotify.current_user_top_artists()
items = response['items']
self.assertTrue(len(items) > 0)
self.assertGreater(len(items), 0)
def test_current_user_recently_played(self):
# No cursor
res = self.spotify.current_user_recently_played()
self.assertTrue(len(res['items']) <= 50)
played_at = res['items'][0]['played_at']
# Using `before` gives tracks played before
res = self.spotify.current_user_recently_played(
before=res['cursors']['after'])
self.assertTrue(len(res['items']) <= 50)
self.assertTrue(res['items'][0]['played_at'] < played_at)
played_at = res['items'][0]['played_at']
class SpotipyBrowseApiTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
username = os.getenv(CCEV['client_username'])
token = prompt_for_user_token(username)
cls.spotify = Spotify(auth=token)
# Using `after` gives tracks played after
res = self.spotify.current_user_recently_played(
after=res['cursors']['before'])
self.assertTrue(len(res['items']) <= 50)
self.assertTrue(res['items'][0]['played_at'] > played_at)
def test_categories(self):
response = self.spotify.categories()
self.assertGreater(len(response['categories']), 0)
def test_user_playlist_ops(self):
sp = self.spotify
# create empty playlist
playlist = self.get_or_create_spotify_playlist(
'spotipy-testing-playlist-1')
playlist_id = playlist['id']
def test_category_playlists(self):
response = self.spotify.categories()
category = 'rock'
for cat in response['categories']['items']:
cat_id = cat['id']
if cat_id == category:
response = self.spotify.category_playlists(category_id=cat_id)
self.assertGreater(len(response['playlists']["items"]), 0)
# remove all tracks from it
sp.user_playlist_replace_tracks(
self.username, playlist_id, [])
playlist = sp.user_playlist(self.username, playlist_id)
self.assertTrue(playlist['tracks']['total'] == 0)
self.assertTrue(len(playlist['tracks']['items']) == 0)
def test_new_releases(self):
response = self.spotify.new_releases()
self.assertGreater(len(response['albums']), 0)
# add tracks to it
sp.user_playlist_add_tracks(
self.username, playlist_id, self.four_tracks)
playlist = sp.user_playlist(self.username, playlist_id)
self.assertTrue(playlist['tracks']['total'] == 4)
self.assertTrue(len(playlist['tracks']['items']) == 4)
def test_featured_releases(self):
response = self.spotify.featured_playlists()
self.assertGreater(len(response['playlists']), 0)
# remove two tracks from it
sp.user_playlist_remove_all_occurrences_of_tracks(self.username,
playlist_id,
self.two_tracks)
playlist = sp.user_playlist(self.username, playlist_id)
self.assertTrue(playlist['tracks']['total'] == 2)
self.assertTrue(len(playlist['tracks']['items']) == 2)
class SpotipyFollowApiTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.username = os.getenv(CCEV['client_username'])
# replace with 3 other tracks
sp.user_playlist_replace_tracks(self.username,
playlist_id,
self.other_tracks)
playlist = sp.user_playlist(self.username, playlist_id)
self.assertTrue(playlist['tracks']['total'] == 3)
self.assertTrue(len(playlist['tracks']['items']) == 3)
scope = (
'playlist-modify-public '
'user-library-read '
'user-follow-read '
'user-library-modify '
'user-read-private '
'user-top-read '
'user-follow-modify '
'user-read-recently-played '
'ugc-image-upload '
'user-read-playback-state'
)
def test_playlist(self):
# New playlist ID
pl = self.spotify.playlist(self.playlist_new_id)
self.assertTrue(pl["tracks"]["total"] > 0)
token = prompt_for_user_token(cls.username, scope=scope)
# Old playlist ID
pl = self.spotify.playlist(self.playlist)
self.assertTrue(pl["tracks"]["total"] > 0)
cls.spotify = Spotify(auth=token)
def test_playlist_tracks(self):
# New playlist ID
pl = self.spotify.playlist_tracks(self.playlist_new_id, limit=2)
self.assertTrue(len(pl["items"]) == 2)
self.assertTrue(pl["total"] > 0)
# Old playlist ID
pl = self.spotify.playlist_tracks(self.playlist, limit=2)
self.assertTrue(len(pl["items"]) == 2)
self.assertTrue(pl["total"] > 0)
def test_playlist_upload_cover_image(self):
pl1 = self.get_or_create_spotify_playlist('spotipy-testing-playlist-1')
plid = pl1['uri']
old_b64 = pl1['images'][0]['url']
# Upload random dog image
r = requests.get('https://dog.ceo/api/breeds/image/random')
dog_base64 = self.get_as_base64(r.json()['message'])
self.spotify.playlist_upload_cover_image(plid, dog_base64)
# Image must be different
pl1 = self.spotify.playlist(plid)
new_b64 = self.get_as_base64(pl1['images'][0]['url'])
self.assertTrue(old_b64 != new_b64)
def test_playlist_cover_image(self):
pl = self.get_or_create_spotify_playlist('spotipy-testing-playlist-1')
plid = pl['uri']
res = self.spotify.playlist_cover_image(plid)
self.assertTrue(len(res) > 0)
first_image = res[0]
self.assertTrue('width' in first_image)
self.assertTrue('height' in first_image)
self.assertTrue('url' in first_image)
def test_current_user_follows(self):
response = self.spotify.current_user_followed_artists()
artists = response['artists']
self.assertGreater(len(artists['items']), 0)
def test_user_follows_and_unfollows_artist(self):
# Initially follows 1 artist
res = self.spotify.current_user_followed_artists()
self.assertTrue(res['artists']['total'] == 1)
self.assertEqual(res['artists']['total'], 1)
# Follow 2 more artists
artists = ["6DPYiyq5kWVQS4RGwxzPC7", "0NbfKEOTQCcwd6o7wSDOHI"]
self.spotify.user_follow_artists(artists)
res = self.spotify.current_user_followed_artists()
self.assertTrue(res['artists']['total'] == 3)
self.assertEqual(res['artists']['total'], 3)
# Unfollow these 2 artists
self.spotify.user_unfollow_artists(artists)
res = self.spotify.current_user_followed_artists()
self.assertTrue(res['artists']['total'] == 1)
self.assertEqual(res['artists']['total'], 1)
def test_user_follows_and_unfollows_user(self):
# TODO improve after implementing `me/following/contains`
@@ -370,25 +347,49 @@ class AuthTestSpotipy(unittest.TestCase):
# Unfollow these 2 users
self.spotify.user_unfollow_users(users)
def test_deprecated_starred(self):
pl = self.spotify.user_playlist(self.username)
self.assertTrue(pl["tracks"] is None)
self.assertTrue(pl["owner"] is None)
def test_deprecated_user_playlist(self):
# Test without user due to change from
# https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/
pl = self.spotify.user_playlist(None, self.playlist)
self.assertTrue(pl["tracks"]["total"] > 0)
class SpotipyPlayerApiTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.username = os.getenv(CCEV['client_username'])
def test_deprecated_user_playlis(self):
# Test without user due to change from
# https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/
pl = self.spotify.user_playlist_tracks(None, self.playlist, limit=2)
self.assertTrue(len(pl["items"]) == 2)
self.assertTrue(pl["total"] > 0)
scope = (
'playlist-modify-public '
'user-library-read '
'user-follow-read '
'user-library-modify '
'user-read-private '
'user-top-read '
'user-follow-modify '
'user-read-recently-played '
'ugc-image-upload '
'user-read-playback-state'
)
token = prompt_for_user_token(cls.username, scope=scope)
cls.spotify = Spotify(auth=token)
def test_devices(self):
# No devices playing by default
res = self.spotify.devices()
self.assertEqual(len(res["devices"]), 0)
self.assertEquals(len(res["devices"]), 0)
def test_current_user_recently_played(self):
# No cursor
res = self.spotify.current_user_recently_played()
self.assertLessEqual(len(res['items']), 50)
played_at = res['items'][0]['played_at']
# Using `before` gives tracks played before
res = self.spotify.current_user_recently_played(
before=res['cursors']['after'])
self.assertLessEqual(len(res['items']), 50)
self.assertTrue(res['items'][0]['played_at'] < played_at)
played_at = res['items'][0]['played_at']
# Using `after` gives tracks played after
res = self.spotify.current_user_recently_played(
after=res['cursors']['before'])
self.assertLessEqual(len(res['items']), 50)
self.assertGreater(res['items'][0]['played_at'], played_at)
View File
Whitespace-only changes.