mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-10-11 01:10:45 +00:00
Renamed the auth parameter of Spotify.__init__ to access_token for better clarity.
Removed the `client_credentials_manager` and `oauth_manager` parameters because they are redundant. Replaced the `set_auth` and `auth_manager` properties with standard attributes. Removed the following deprecated methods from `Spotify`: * `playlist_tracks` * `user_playlist` * `user_playlist_tracks` * `user_playlist_change_details` * `user_playlist_unfollow` * `user_playlist_add_tracks` * `user_playlist_replace_tracks` * `user_playlist_reorder_tracks` * `user_playlist_remove_all_occurrences_of_tracks` * `user_playlist_remove_specific_occurrences_of_tracks` * `user_playlist_follow_playlist` * `user_playlist_is_following` Removed the deprecated `as_dict` parameter from the `get_access_token` method of `SpotifyOAuth` and `SpotifyPKCE`. Removed the deprecated `get_cached_token` and `_save_token_info` methods of `SpotifyOAuth` and `SpotifyPKCE`. Removed `SpotifyImplicitGrant`. Removed `prompt_for_user_token`.
This commit is contained in:
1 parent
68ee2d6de8
commit
c8e045891b
34 files changed
+202
-1196
No files matched your search
@@ -70,7 +70,8 @@ class AuthTestSpotipy(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
self.spotify = Spotify(
|
||||
client_credentials_manager=SpotifyClientCredentials())
|
||||
auth_manager=SpotifyClientCredentials()
|
||||
)
|
||||
self.spotify.trace = False
|
||||
|
||||
def test_audio_analysis(self):
|
||||
@@ -341,9 +342,9 @@ class AuthTestSpotipy(unittest.TestCase):
|
||||
self.assertTrue(find_album())
|
||||
|
||||
def test_search_timeout(self):
|
||||
client_credentials_manager = SpotifyClientCredentials()
|
||||
auth_manager = SpotifyClientCredentials()
|
||||
sp = spotipy.Spotify(requests_timeout=0.01,
|
||||
client_credentials_manager=client_credentials_manager)
|
||||
auth_manager=auth_manager)
|
||||
|
||||
# depending on the timing or bandwidth, this raises a timeout or connection error
|
||||
self.assertRaises((requests.exceptions.Timeout, requests.exceptions.ConnectionError),
|
||||
@@ -352,17 +353,15 @@ class AuthTestSpotipy(unittest.TestCase):
|
||||
@unittest.skip("flaky test, need a better method to test retries")
|
||||
def test_max_retries_reached_get(self):
|
||||
spotify_no_retry = Spotify(
|
||||
client_credentials_manager=SpotifyClientCredentials(),
|
||||
auth_manager=SpotifyClientCredentials(),
|
||||
retries=0)
|
||||
i = 0
|
||||
while i < 100:
|
||||
for i in range(100):
|
||||
try:
|
||||
spotify_no_retry.search(q='foo')
|
||||
except SpotifyException as e:
|
||||
self.assertIsInstance(e, SpotifyException)
|
||||
self.assertEqual(e.http_status, 429)
|
||||
return
|
||||
i += 1
|
||||
self.fail()
|
||||
|
||||
def test_album_search(self):
|
||||
@@ -460,7 +459,7 @@ class AuthTestSpotipy(unittest.TestCase):
|
||||
sess = requests.Session()
|
||||
sess.headers["user-agent"] = "spotipy-test"
|
||||
with_custom_session = spotipy.Spotify(
|
||||
client_credentials_manager=SpotifyClientCredentials(),
|
||||
auth_manager=SpotifyClientCredentials(),
|
||||
requests_session=sess)
|
||||
self.assertTrue(
|
||||
with_custom_session.user(
|
||||
@@ -469,7 +468,7 @@ class AuthTestSpotipy(unittest.TestCase):
|
||||
|
||||
def test_force_no_requests_session(self):
|
||||
with_no_session = spotipy.Spotify(
|
||||
client_credentials_manager=SpotifyClientCredentials(),
|
||||
auth_manager=SpotifyClientCredentials(),
|
||||
requests_session=False)
|
||||
self.assertNotIsInstance(with_no_session._session, requests.Session)
|
||||
user = with_no_session.user(user="akx")
|
||||
|
||||
@@ -2,15 +2,30 @@ import os
|
||||
|
||||
from spotipy import (
|
||||
CLIENT_CREDS_ENV_VARS as CCEV,
|
||||
prompt_for_user_token,
|
||||
Spotify,
|
||||
SpotifyException,
|
||||
SpotifyImplicitGrant,
|
||||
SpotifyPKCE
|
||||
SpotifyOAuth,
|
||||
SpotifyPKCE,
|
||||
CacheFileHandler
|
||||
)
|
||||
import unittest
|
||||
from tests import helpers
|
||||
|
||||
def _make_spotify(scopes=None, retries=None):
|
||||
|
||||
retries = retries or Spotify.max_retries
|
||||
|
||||
auth_manager = SpotifyOAuth(
|
||||
scope=scopes,
|
||||
cache_handler=CacheFileHandler()
|
||||
)
|
||||
|
||||
spotify = Spotify(
|
||||
auth_manager=auth_manager,
|
||||
retries=retries
|
||||
)
|
||||
|
||||
return spotify
|
||||
|
||||
class SpotipyPlaylistApiTest(unittest.TestCase):
|
||||
@classmethod
|
||||
@@ -48,10 +63,10 @@ class SpotipyPlaylistApiTest(unittest.TestCase):
|
||||
'user-read-playback-state'
|
||||
)
|
||||
|
||||
token = prompt_for_user_token(cls.username, scope=scope)
|
||||
cls.spotify = _make_spotify(scopes=scope)
|
||||
cls.spotify_no_retry = _make_spotify(scopes=scope, retries=0)
|
||||
|
||||
|
||||
cls.spotify = Spotify(auth=token)
|
||||
cls.spotify_no_retry = Spotify(auth=token, retries=0)
|
||||
cls.new_playlist_name = 'spotipy-playlist-test'
|
||||
cls.new_playlist = helpers.get_spotify_playlist(
|
||||
cls.spotify, cls.new_playlist_name, cls.username) or \
|
||||
@@ -201,17 +216,6 @@ class SpotipyPlaylistApiTest(unittest.TestCase):
|
||||
return
|
||||
self.fail()
|
||||
|
||||
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
|
||||
@@ -240,10 +244,7 @@ class SpotipyLibraryApiTests(unittest.TestCase):
|
||||
'ugc-image-upload '
|
||||
'user-read-playback-state'
|
||||
)
|
||||
|
||||
token = prompt_for_user_token(cls.username, scope=scope)
|
||||
|
||||
cls.spotify = Spotify(auth=token)
|
||||
cls.spotify = _make_spotify(scopes=scope)
|
||||
|
||||
def test_track_bad_id(self):
|
||||
with self.assertRaises(SpotifyException):
|
||||
@@ -330,9 +331,7 @@ class SpotipyUserApiTests(unittest.TestCase):
|
||||
'user-read-playback-state'
|
||||
)
|
||||
|
||||
token = prompt_for_user_token(cls.username, scope=scope)
|
||||
|
||||
cls.spotify = Spotify(auth=token)
|
||||
cls.spotify = _make_spotify(scopes=scope)
|
||||
|
||||
def test_basic_user_profile(self):
|
||||
user = self.spotify.user(self.username)
|
||||
@@ -360,9 +359,7 @@ class SpotipyUserApiTests(unittest.TestCase):
|
||||
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)
|
||||
cls.spotify = _make_spotify()
|
||||
|
||||
def test_category(self):
|
||||
rock_cat_id = '0JQ5DAqbMKFDXXwE9BDJAr'
|
||||
@@ -455,9 +452,7 @@ class SpotipyFollowApiTests(unittest.TestCase):
|
||||
'user-read-playback-state'
|
||||
)
|
||||
|
||||
token = prompt_for_user_token(cls.username, scope=scope)
|
||||
|
||||
cls.spotify = Spotify(auth=token)
|
||||
cls.spotify = _make_spotify(scopes=scope)
|
||||
|
||||
def test_current_user_follows(self):
|
||||
response = self.spotify.current_user_followed_artists()
|
||||
@@ -510,9 +505,7 @@ class SpotipyPlayerApiTests(unittest.TestCase):
|
||||
'user-read-playback-state'
|
||||
)
|
||||
|
||||
token = prompt_for_user_token(cls.username, scope=scope)
|
||||
|
||||
cls.spotify = Spotify(auth=token)
|
||||
cls.spotify = _make_spotify(scopes=scope)
|
||||
|
||||
def test_devices(self):
|
||||
# No devices playing by default
|
||||
@@ -526,23 +519,6 @@ class SpotipyPlayerApiTests(unittest.TestCase):
|
||||
# not much more to test if account is inactive and has no recently played tracks
|
||||
|
||||
|
||||
class SpotipyImplicitGrantTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
scope = (
|
||||
'user-follow-read '
|
||||
'user-follow-modify '
|
||||
)
|
||||
auth_manager = SpotifyImplicitGrant(scope=scope,
|
||||
cache_path=".cache-implicittest")
|
||||
cls.spotify = Spotify(auth_manager=auth_manager)
|
||||
|
||||
def test_current_user(self):
|
||||
c_user = self.spotify.current_user()
|
||||
user = self.spotify.user(c_user['id'])
|
||||
self.assertEqual(c_user['display_name'], user['display_name'])
|
||||
|
||||
|
||||
class SpotifyPKCETests(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
@@ -551,7 +527,8 @@ class SpotifyPKCETests(unittest.TestCase):
|
||||
'user-follow-read '
|
||||
'user-follow-modify '
|
||||
)
|
||||
auth_manager = SpotifyPKCE(scope=scope, cache_path=".cache-pkcetest")
|
||||
cache_handler = CacheFileHandler(cache_path=".cache-pkcetest")
|
||||
auth_manager = SpotifyPKCE(scope=scope, cache_handler=cache_handler)
|
||||
cls.spotify = Spotify(auth_manager=auth_manager)
|
||||
|
||||
def test_current_user(self):
|
||||
|
||||
Reference in new issue
Block a user