Commit Graph

115 Commits

Author SHA1 Message Date
badfarmerjohn
7bb3e7349f Fixed audio_features API wrapper function return structure (#653)
Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2024-10-13 21:24:17 +02:00
Stéphane Bruckert
c90ce4a875
Fix audiobook integration tests (#1141) 2024-06-23 22:13:44 +01:00
Brennan Pate
d92951b356
Update Directions In TUTORIAL.md; Add Unit Tests To non_user_endpoints test.py (#1136)
* Update navigational directions in Step 1(A)

* Combine directions in Step 1(B) and Step 2(C) and remove Step 2(C)

* Update navigational directions and verbage in Step 1(C)

* Change reference from Step 1(C) to Step 1(B) in Step 2(D)

* Update capitalization in Prerequisites Step 3

* Add directions for installing Spotipy in Prerequisites Step 1(A)

* List updates to TUTORIAL.md file in CHANGELOG.md

* Update docstrings for funcs in lines 340-585

* Add unit tests for artist ID and URL

* Add test_artists_mixed_ids

* Updated CHANGELOG.md and TUTORIAL.md as requested

* Update client.py and test.py

* Fix linting issue

* Remove duplicate line; Change order of prerequisites

* Update local repo

* Add test_artists_mixed_ids

* Add Radiohead ID and URL; Add qotsa URL

* Add test_artist_url

* Comment out three failing tests

* Fix linting errors

* Uncommenting out failed tests

* Add test_artist_id

* List changes in CHANGELOG.md

* Add line breaks at the end of files.

* Remove multiple spaces

Also I've removed a sentence that just doesn't make sense in my eyes, but was added before this PR.

---------

Co-authored-by: Niko <github@dieserniko.link>
2024-06-22 17:35:53 +02:00
Stephane Bruckert
c5a0943016 Uncomment temporarily failing test 2024-06-01 19:34:44 +01:00
Brandon Parrott
f94a89a995
Add unit tests for queue functions (#1059)
* Update test.py

Add tests for queue manipulation/retrieval functions

* Update CHANGELOG.md

* flake8

---------

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2024-05-31 17:46:19 +01:00
Stephane Bruckert
cb36133ca9 Comment out test failing with payment_required 2024-05-31 17:42:28 +01:00
Shukie Li
df27fe93bf
Combined assertion tests, fixes #1051 (#1052)
* addressed issue 936

* publish branch

* 12/9/2023

* Update CHANGELOG.md

---------

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2024-05-30 19:29:32 +01:00
Hugo van Kemenade
85c9d74dc1
Drop support for EOL Python 3.7 (#1065)
* Add python_requires to help pip

* Update supported versions in tox.ini

* Upgrade Python syntax with pyupgrade --py37-plus

* Bump GitHub Actions

* Add Python 3.11 and 3.12 to CI

* Remove six dependency

* Remove redundant dependencies

* Remove redudant Python 3.5 code

* Drop support for EOL Python 3.7

* Upgrade Python syntax with pyupgrade --py38-plus

* Update CHANGELOG

* More f-strings

---------

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2024-05-21 18:32:01 +02:00
Dan Joseph
1416d47cba
Audiobook Support and CI Workflow Update (#1036)
* Implement audiobook endpoints

* Update GitHub CI Workflow: Removed Python v2.7

* Update GitHub CI Workflow: Removed Python v3.6

* Add integration tests for audiobook endpoints
2023-10-31 01:32:46 +00:00
Richard Ngo-Lam
fe438c0432
Update search_markets method to apply the total parameter to all types, add tests (#901)
* Update search_markets method to apply the total parameter to all types, fixes #534

* Add integration tests for searching multiple types in multiple markets

* Update search_markets method to apply the total parameter to all types, add tests

---------

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2023-03-15 23:46:08 +00:00
Kevin Sekuj
5201f58247
Add tests for global categories, releases, fix bugged tests (#893) 2022-11-26 09:29:53 +00:00
Sean Park
6f56504c2c
Update category tests to fix 1 failing and 1 error test results (#886)
* update category tests to fix 1 failing and 1 error test results

* update changelog
2022-11-13 10:42:25 +00:00
Stéphane Bruckert
1265d7b915
GHA integration tests (#876) 2022-11-01 21:57:40 +00:00
Bruno Alla
fa44fed76d
Fix a few typos in comments & strings (#866) 2022-10-29 14:23:43 +01:00
Stephane Bruckert
06765c4f5a Fix flake8 2022-10-26 22:56:38 +01:00
Stephane Bruckert
36ea3d9319 Fix lint 2022-06-18 23:29:12 +01:00
mattrost
1b0c426984
Addition of Test Cases (#818)
* Added test_categories_country to use optional country selection for categories method.

* Added test_categories_locale for testing locale method of categories.

* Added test_categories_limit_low and test_categories_limit_high to test the limit method of categories for edge cases.

* Rearranged for flow

* Added test_category_playlists_limit_low and test_category_playlists_limit_high for testing the limit method.
2022-06-18 23:28:08 +01:00
Stephane Bruckert
48d04f343b Bump to 2.19.0 2021-08-12 11:27:26 +01:00
Gustavo Krieger
85746e4e62
set cache checking to false so that failing test passes (#682) 2021-04-25 22:02:07 +01:00
Gustavo Krieger
e4c581bbb6
add tearDownClass to unfollow test playlist after tests (#680) 2021-04-23 18:41:50 +01:00
Gustavo Krieger
49f46264c7
change assertGreater to assertGreaterEqual in some tests (#679) 2021-04-23 18:41:11 +01:00
Peter Schorn
07915e21e5
Added MemoryCacheHandler (#670)
* Added `MemoryCacheHandler`, a cache handler that simply stores the token info in memory as an instance attribute of this class.

* Fixed a bug in `CacheFileHandler.__init__`: The documentation says that the username will be retrieved from the environment, but it wasn't.
2021-04-14 16:59:37 +01:00
Peter Schorn
25f9df2dd5
Added new endpoints (#666)
* Added an exception clause that catches `FileNotFoundError` and logs a debug message in `SpotifyOAuth.get_cached_token`, `SpotifyPKCE.get_cached_token` and `SpotifyImplicitGrant.get_cached_token`.

* Changed docs for `auth` parameter of `Spotify.init` to `access token` instead of `authorization token`. In issue #599, a user confused the access token with the authorization code.

* Updated CHANGELOG.md

* Removed `FileNotFoundError` because it does not exist in python 2.7 (*sigh*) and replaced it with a call to `os.path.exists`.

* Replaced ` os.path.exists` with `error.errno == errno.ENOENT` to supress errors when the cache file does not exist.

* Changed docs for `search` to mention that you can provide multiple multiple types to search for. The query parameters of requests are now logged. Added log messages for when the access token and refresh tokens are retrieved and when they are refreshed. Other small grammar fixes.

* Removed duplicate word "multiple" from CHANGELOG

* * Fixed the bugs in `SpotifyOAuth.refresh_access_token` and `SpotifyPKCE.refresh_access_token` which raised the incorrect exception upon receiving an error response from the server. This addresses #645.
* Fixed a bug in `RequestHandler.do_GET` in which the non-existent `state` attribute of  `SpotifyOauthError` is accessed. This bug occurs when the user clicks "cancel" in the permissions dialog that opens in the browser.
* Cleaned up the documentation for `SpotifyClientCredentials.__init__`, `SpotifyOAuth.__init__`, and `SpotifyPKCE.__init__`.

* Removed unneeded import

* Added the following endpoints:
 `Spotify.current_user_saved_episodes` `Spotify.current_user_saved_episodes_add` `Spotify.current_user_saved_episodes_delete` `Spotify.current_user_saved_episodes_contains` `Spotify.available_markets`
 Added tests for the above endpoints.

* updated CHANGELOG

* Fixed flake8 issue

Co-authored-by: Stéphane Bruckert <stephane.bruckert@gmail.com>
2021-04-10 14:53:03 +01:00
Stephane Bruckert
e35f6ec5ad Fix lint 2021-02-28 10:16:21 +01:00
Stephane Bruckert
ef2ed1a9c5 Bump to 2.17.0 2021-02-28 10:12:26 +01:00
Stephane Bruckert
27a7c2c880 Fix integration tests 2021-02-27 16:41:14 +01:00
Tony Jackson
a7b25d0f6e
Add deprecation warnings to direct users towards using cache_handler (#630)
* Refactor functions into static methods of AuthBase

Functions is_token_expired was a loose function that was added to
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes
through a method on each class that passed the call to the loose
is_token_expired function. Function _is_scope_subset was duplicated on
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes.

Refactoring is_token_expired and _is_scope_subset to be static methods
on SpotifyAuthBase means both are available for all derived classes and
require less boilerplate.

* Create CacheHandler to abstract caching tokens

Previous code only supported caching to and from json files in a given
directory. In addition, the get_cached_token method mixed getting and
getting the token in the same method.

This change creates a CacheHandler class to abstract out the caching
implementation and allow the user to cache tokens in any way they
see fit. For example, the user could create a MongoCache class to store
and retrieve tokens from a Mongo database and specify that
cache_handler=MongoCache in creating an auth_manager object.

To implement the CacheHandler abstraction, the following changes are
implemented:

The validation code in each get_cached_token method in SpotifyOAuth,
SpotifyPKCE, and SpotifyImplicitGrant is moved into a validate_token
method in each class.

The CacheHandler class is created with get_cached_token and
save_token_to_cache methods.

Previous instances of self.get_cached_token() are now replaced with
self.validate_token(self.cache_handler.get_cached_token()) to preserve
the getting and validation behaviour.

cache_handler is added as an argument to SpotifyOAuth, SpotifyPKCE, and
SpotifyImplicitGrant. Specifying a cache_handler now overrides any
specification of cache_path and/or username.

To preserve backwards compatibility in handling cache files, a
CacheFileHandler class extending CacheHandler is created. If no
cache_handler is specified, the cache_path and username arguments are
used to create an instance of CacheFileHandler. It may be worth
deprecating the cache_path and username fields in favour of using
CacheFileHandler.

Tests are also modified and extended to cover the new functionality. A
sample MemoryCache CacheHandler is created to test getting and saving to
a custom CacheHandler.

* Fix cache_handler subclass check for Python 2

* Split assert message to fix line over max length

* Split cache handlers into cache_handler.py

* flake8 and autopep fixes

* Fix init to allow importing CacheHandler

When spotipy is installed as a package, CacheHandler is not accessible
from a `from spotipy import CacheHandler` statement because the import
is not specified in the __init__.py file. This commit adds CacheHandler
and CacheFileHandler to the init file so the user can import them.

* flake8 fix

* Add cache_path & username deprecation warning

When cache_path or username are specified in the constructors of
SpotifyOAuth, SpotifyPKCE, or SpotifyImplicitGrant, the constructor
creates a CacheFileHandler instance under the hood. The user is
currently able to create a CacheFileHandler instance in two ways:

1.  By creating it outside the SpotifyOAuth (or etc.) constructor and
    passing it as the cache_handler
2.  By passing cache_path and username to the constructor

Ideally, there would be one and only one obvious way to specify a
CacheFileHandler instance and the cache_handler approach allows any
CacheHandler to be used, so passing the cache_path or username to the
constructor should be deprecated.

* Update flask example to use CacheFileHandler

* Update changelog with deprecation warning info

* Restore token caching methods on auth_manager

Change 9550c8fd86 in
https://github.com/plamere/spotipy accidentally broke the caching
functionality in SpotifyOAUth, SpotifyPKCE, and SpotifyImplicitGrant by
removing the get_cached_token and _save_token_info methods from the
auth_manager object. Users with existing codebases that use the
get_cached_token and _save_token_info methods directly will experience
errors if they upgrade spotipy.

This commit restores the get_cached_token and _save_token_info methods
on the three auth_manager classes as aliases for the corresponding
methods in the cache_handler. Deprecation warnings are also added to
the get_cached_token and _save_token_info methods to direct users to
switch to using the new cache_handler approach.

* Add deprecation warning to docstrings

* Rearrange depr. warn for cache_path & username

Rearrange logic so that deprecation warning always triggers if
cache_path or username are specified. Previously, if cache_handler was
specified, no deprecation warning would be raised if cache_path or
username were specified.

In addition, if both cache_handler and cache_path or username are
specified, a new warning will be raised alongside the deprecation
warning to let the user know that the cache_path and username fields
will be ignored in favour of the cache_handler.
2021-01-13 11:34:53 +01:00
Tony Jackson
9550c8fd86
Create CacheHandler to abstract caching tokens (#625)
* Refactor functions into static methods of AuthBase

Functions is_token_expired was a loose function that was added to
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes
through a method on each class that passed the call to the loose
is_token_expired function. Function _is_scope_subset was duplicated on
SpotifyClientCredentials, SpotifyPKCE, and SpotifyImplicitGrant classes.

Refactoring is_token_expired and _is_scope_subset to be static methods
on SpotifyAuthBase means both are available for all derived classes and
require less boilerplate.

* Create CacheHandler to abstract caching tokens

Previous code only supported caching to and from json files in a given
directory. In addition, the get_cached_token method mixed getting and
getting the token in the same method.

This change creates a CacheHandler class to abstract out the caching
implementation and allow the user to cache tokens in any way they
see fit. For example, the user could create a MongoCache class to store
and retrieve tokens from a Mongo database and specify that
cache_handler=MongoCache in creating an auth_manager object.

To implement the CacheHandler abstraction, the following changes are
implemented:

The validation code in each get_cached_token method in SpotifyOAuth,
SpotifyPKCE, and SpotifyImplicitGrant is moved into a validate_token
method in each class.

The CacheHandler class is created with get_cached_token and
save_token_to_cache methods.

Previous instances of self.get_cached_token() are now replaced with
self.validate_token(self.cache_handler.get_cached_token()) to preserve
the getting and validation behaviour.

cache_handler is added as an argument to SpotifyOAuth, SpotifyPKCE, and
SpotifyImplicitGrant. Specifying a cache_handler now overrides any
specification of cache_path and/or username.

To preserve backwards compatibility in handling cache files, a
CacheFileHandler class extending CacheHandler is created. If no
cache_handler is specified, the cache_path and username arguments are
used to create an instance of CacheFileHandler. It may be worth
deprecating the cache_path and username fields in favour of using
CacheFileHandler.

Tests are also modified and extended to cover the new functionality. A
sample MemoryCache CacheHandler is created to test getting and saving to
a custom CacheHandler.

* Fix cache_handler subclass check for Python 2

* Split assert message to fix line over max length

* Split cache handlers into cache_handler.py

* flake8 and autopep fixes

* Fix init to allow importing CacheHandler

When spotipy is installed as a package, CacheHandler is not accessible
from a `from spotipy import CacheHandler` statement because the import
is not specified in the __init__.py file. This commit adds CacheHandler
and CacheFileHandler to the init file so the user can import them.

* flake8 fix
2020-12-21 11:31:21 +01:00
Stéphane Bruckert
dd948c49d9
Retry for POST, PUT and DELETE, fixes #577 (#596)
* Retry for POST, PUT and DELETE, fixes #577

* Lint
2020-10-24 14:32:04 +01:00
Callum
4bb42598e1
Fixed UnboundLocalError / AttributeError #571, #581 (#583)
* Fix plamere/spotipy#571, plamere/spotipy#581

* Add integration test for reaching max retries

* Update tests/integration/test_non_user_endpoints.py

Co-authored-by: Stéphane Bruckert <contact@stephanebruckert.com>

* Update CHANGELOG.md, integration test mock data

Co-authored-by: Stéphane Bruckert <contact@stephanebruckert.com>
2020-10-07 09:00:45 +01:00
Stéphane Bruckert
d0ca977647
Made cache_path and username optional (#567)
* Made cache_path and username optional

* Update readme and example

* Lint

* Lint

* Feedback / add warning
2020-08-30 23:59:38 +01:00
Bram Kragten
5e9f97df8e
Add category info (#561)
* Add category info

* Add slash

* Add test
2020-08-27 20:49:56 +01:00
Paul Lamere
651080e3da
Fix playlist add items (#559)
* fixed uri issue in playlist_add_items

All uris were being converted to track uris
making it impossible to add episodes to playlists.

* Added tests for episode adds

also fixed creep uri so those tests no longer fail

* Fixed creep_url to match creep_uri

* revert pip version, added FIX to changelog

Co-authored-by: Paul Lamere <paull@spotify.com>
2020-08-25 19:37:53 +01:00
IdmFoundInHim
3d48d77615
Add code parameter to get_access_token of SpotifyPKCE (#556)
* Add code parameter to oauth2.SpotifyPKCE.get_access_token

* Fix the PKCE integration test cache
2020-08-24 19:57:05 +01:00
DJSdev
c425102659
Adding Initial PKCE Auth Flow Support (#542)
* Added base funtionality for PKCE Authorization - i538

* fixed a mistake with the auth code

* fixed more misunderstandings. fixed grant_access_token to now call authorization if needed

* added comments and references to code verifier and code challenge

* removed debug print statement

* updated unit tests for new PKCE flow

* cleaned up username issues - added doc strings to class

* fixed import issue, added user endpoint tests

* forgot to commit this file

* linted

* clarified comment

* no longer generates code verifier or challenge in constructor, only when needed

* fixed flake8 complaints, added forgotten unit tests

* fixed linting with unit tests

* anotha one

* added python3.5 support

* linting

* added to CHANGELOG

* removed as_dict option from get_access_token()

Co-authored-by: tomCLANCC <26153156+tomCLANCC@users.noreply.github.com>
2020-07-21 17:08:09 +01:00
IdmFoundInHim
88cf75b778
Update Playlist Endpoints and Add Following Endpoints (#531)
* Update playlist endpoints to modern format

Deprecate user_playlist_* in favor of the following replacements:
* user_playlist_change_details -> playlist_change_details
* user_playlist_unfollow -> current_user_unfollow_playlist
* user_playlist_add_tracks -> playlist_add_tracks
* user_playlist_replace_tracks -> playlist_replace_tracks
* user_playlist_reorder_tracks -> playlist_reorder_tracks
* user_playlist_remove_all_occurrences_of_tracks -> playlist_remove_all_occurrences_of_tracks
* user_playlist_remove_specific_occurrences_of_tracks -> playlist_remove_specific_occurrences_of_tracks
* user_playlist_follow_playlist -> current_user_follow_playlist
* user_playlist_is_following -> playlist_is_following

* Add current_user_following_artists and current_user_following_users

* Update tests and examples

Resolve TODO in test_user_endpoints.py > SpotifyFollowApiTests.test_user_follows_and_unfollows_user

Use modern playlist endpoints (no username required) in tests and examples.

* Update changelog

* Deprecate playlist_tracks in favor of playlist_items

* Link deprecated functions to new functions and change tracks to items

* Fix references to playlist_tracks

* Change test_playlist_add_items as requested
2020-07-11 11:23:18 +01:00
Nathan LeRoy
f7fb8757e9
Fix return object formatting for multi-market searches (#527)
* resolve return object formatting issues referened in #526

* resolve comments from @ritiek

* create separate method to search multiple markets

* Use old description again

* market -> markets + fix test

* pep8

* Use break

Co-authored-by: Stephane Bruckert <contact@stephanebruckert.com>
2020-07-07 07:20:23 +01:00
Nathan LeRoy
2bfa7e0151
Add support to search multiple markets at once (#526)
* Add support to search multiple markets. Pass in a list or ALL to search all markets.

* pep8 formatting and verification with flake8

* work on comments from stephanebruckert

* pep8 formatting

* run autopep8 formatting

* fix typo

* allow tuple of markets to be passed. Add unit tests for this case
2020-07-03 19:31:52 +01:00
IdmFoundInHim
38515689bc
Support Implicit Grant Authorization Flow (Fix #499) (#515)
* Add SpotifyImplicitGrant with get_access_token and get_cached_token (and minimum related functions)

* Add some overlooked necessary methods/values in SpotifyImplicitGrant

* Remove unsuppported functionality and make SpotifyImplicitGrant public

* Allow/Expose integration of SpotifyImplicitGrant in client

* Add Implicit Grant tests and decrease abilities of prompt_for_user_token

Remove Implicit Grant and state support from prompt_for_user_token

* Add documentation and changelog entry

* Touch up PEP8 compliance

* Ignore long line with link for flake8

* Correct changelog

* Restore compatibility with Python 2.7

* Correct help(SpotifyImplicitGrant.get_access_token)

* Remove as_dict from SpotifyImplicitGrant.get_access_token

* Combine status check functionality with implicit grant support

In oauth2.py:
* Add state checking to SpotifyImplicitGrant
* Add dedicated SpotifyStateError as subclass of SpotifyOauthError
* Moved `_get_user_input` from SpotifyOAuth to superclass SpotifyAuthBase
* Renamed `parse_oauth_response_url` to `parse_auth_response_url`
* Moved error handling into `parse_auth_response_url`

Made minor changes in tests and client.py accordingly

* Update changelog

* Trim down tests for SpotifyImplicitGrant

* Fix trailing whitespace
2020-06-25 21:39:51 +01:00
foobuzz
ed136d15df
Check the state (#509)
* - Verify that the state received alongside the authorization code is consistent with the one sent
- Refactor URL parsing for the local server way and the interactive way
- Add tests for interactive way

* Resurrect public methods parse_response_code and get_authorization_code

* Use new method parse_oatuh_response_url for parse_response_code implementation.
2020-06-20 21:48:19 +01:00
Stephane Bruckert
c7f2edf343 Deprecate util.prompt_for_user_token() 2020-06-14 18:01:14 +01:00
Stéphane Bruckert
816457b7d5
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
2020-05-29 09:37:59 +01:00
Yasser Sinjab
901b2031a2 Refactor SpotifyOauthError class
- add error and error description to SpotifyOauthError to reflect the data returned by web api when error happens
- unit test to SpotifyClientCredentials.get_access_token is added for invalid client
2020-05-27 23:26:47 +03:00
Yasser Sinjab
7906417c1d Refactor two unittests that could fail for
some users and make them more generic.
2020-05-27 03:28:37 +03:00
Loisaida Sam
ccfda079c8
Propagate refresh token error, fixes #259 (#261)
* Propagate refresh token error #259

https://github.com/plamere/spotipy/issues/259

* Lint

* Format

Co-authored-by: Stephane Bruckert <contact@stephanebruckert.com>
2020-04-02 20:03:24 +01:00
Stephane Bruckert
73aac90bbe Auto-close auth browser window 2020-04-01 21:25:48 +01:00
Dj
024a6c96d4
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
2020-03-29 17:18:23 +01:00
jugdizh
8b84300597
Added endpoints for shows/podcasts and episodes, closes #450
https://developer.spotify.com/documentation/web-api/reference-beta/#category-shows
https://developer.spotify.com/documentation/web-api/reference-beta/#category-episodes
2020-03-24 21:36:25 +00:00
Stephane Bruckert
9ed584b398 Player endpoints example and test 2020-02-22 11:12:29 +00:00
Alexey Paramonov
1f1e90ed39
Add requests_timeout parameter to auth module (#233) 2020-02-13 00:04:40 +00:00