diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index f6b6eac9..a203147a 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -1,6 +1,6 @@ name: Integration tests -on: [push, pull_request_target] +on: [push] jobs: build: diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c8fda84..e33ce1e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,15 @@ Add your changes below. ### Added - Added unit tests for queue functions +- Added detailed function docstrings to 'util.py', including descriptions and special sections that lists arguments, returns, and raises. +- Updated order of instructions for Python and pip package manager installation in TUTORIAL.md +- Updated TUTORIAL.md instructions to match current layout of Spotify Developer Dashboard +- Added test_artist_id, test_artist_url, and test_artists_mixed_ids to non_user_endpoints test.py - Added custom `urllib3.Retry` class for printing a warning when a rate/request limit is reached. ### Fixed -- +- Audiobook integration tests +- Edited docstrings for certain functions in client.py for functions that are no longer in use and have been replaced. ### Removed - `mock` no longer listed as a test dependency. Only built-in `unittest.mock` is actually used. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aa99374d..11558a0c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,3 +68,4 @@ Don't forget to add a short description of your change in the [CHANGELOG](CHANGE - Create github release https://github.com/plamere/spotipy/releases with the changelog content for the version and a short name that describes the main addition - Verify doc uses latest https://readthedocs.org/projects/spotipy/ + \ No newline at end of file diff --git a/TUTORIAL.md b/TUTORIAL.md index 54d49b29..b3dd15dc 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -4,25 +4,19 @@ Hello and welcome to the Spotipy Tutorial for Beginners. If you have limited exp ## Prerequisites In order to complete this tutorial successfully, there are a few things that you should already have installed: -**1. pip package manager** - -You can check to see if you have pip installed by opening up Terminal and typing the following command: pip --version -If you see a version number, pip is installed, and you're ready to proceed. If not, instructions for downloading the latest version of pip can be found here: https://pip.pypa.io/en/stable/cli/pip_download/ - - -**2. python3** +**1. python3** Spotipy is written in Python, so you'll need to have the latest version of Python installed in order to use Spotipy. Check if you already have Python installed with the Terminal command: python --version If you see a version number, Python is already installed. If not, you can download it here: https://www.python.org/downloads/ -**3. spotipy** +**2. pip package manager** -You'll need to install the packages necessary for this project. Run the following command: -``` -pip install spotipy -``` +You can check to see if you have pip installed by opening up Terminal and typing the following command: pip --version +If you see a version number, pip is installed, and you're ready to proceed. If not, instructions for downloading the latest version of pip can be found here: https://pip.pypa.io/en/stable/cli/pip_download/ -**4. experience with basic Linux commands** +A. After ensuring that pip is installed, run the following command in Terminal to install Spotipy: pip install spotipy --upgrade + +**3. Experience with Basic Linux Commands** This tutorial will be easiest if you have some knowledge of how to use Linux commands to create and navigate folders and files on your computer. If you're not sure how to create, edit and delete files and directories from Terminal, learn about basic Linux commands [here](https://ubuntu.com/tutorials/command-line-for-beginners#1-overview) before continuing. @@ -31,19 +25,17 @@ Once those three setup items are taken care of, you're ready to start learning h ## Step 1. Creating a Spotify Account Spotipy relies on the Spotify API. In order to use the Spotify API, you'll need to create a Spotify developer account. -A. Visit the [Spotify developer portal](https://developer.spotify.com/dashboard/). If you already have a Spotify account, click "Log in" and enter your username and password. Otherwise, click "Sign up" and follow the steps to create an account. After you've signed in or signed up, you should be redirected to your developer dashboard. - -B. Click the "Create an App" button. Enter any name and description you'd like for your new app. Add "http://localhost:1234" (or any other port number of your choosing) as your "Redirect URI". Accept the terms of service and click "Create." +A. Visit the [Spotify developer portal](https://developer.spotify.com/dashboard/). If you already have a Spotify account, click "Log in" and enter your username and password. Otherwise, click "Sign up" and follow the steps to create an account. After you've signed in or signed up, begin by clicking on your profile name at the top right of your screen and then click “Dashboard” to go to Spotify’s Developer Dashboard. -C. In your new app's Overview screen, click the "Settings" button and then under the "Basic Information" tab click "View client secret", then copy both your Client Secret and your Client ID somewhere on your computer. You'll need to access them later. +B. Check the box "Accept the Spotify Developer Terms of Service" and then click "Accept the terms". On the next page, verify your email address if you haven't already. Click the "Create an App" button. Enter any name and description you'd like for your new app. Next, add "http://localhost:1234" (or any other port number of your choosing) to the "Redirect URI" secction. Check the box "I understand and agree with Spotify's Developer Terms of Service and Design Guidelines" and then click the "Save" button. -D. Underneath your app name and description on the left-hand side, you'll see a "Show Client Secret" link. Click that link to reveal your Client Secret, then copy both your Client Secret and your Client ID somewhere on your computer. You'll need to access them later. +C. Click on "Settings". Underneath "Client ID", you'll see a "View Client Secret" link. Click the link to reveal your Client secret and copy both your Client secret and your Client ID somewhere so that you can access them later. ## Step 2. Installation and Setup A. Create a folder somewhere on your computer where you'd like to store the code for your Spotipy app. You can create a folder in terminal with this command: ```mkdir folder_name``` -B. Install the Spotipy library. You can do this by using this command in the terminal: ```pip install spotipy``` +B. In your new folder, create a Python file named main.py. You can create the file directly from Terminal using a built in text editor like Vim, which comes preinstalled on Linux operating systems. To create the file with Vim, ensure that you are in your new directory, then run: vim main.py C. In that folder, create a Python file named main.py. You can create the file directly from Terminal using a built in text editor like Vim, which comes preinstalled on Linux operating systems. To create the file with Vim, ensure that you are in your new directory, then run: vim main.py @@ -57,7 +49,7 @@ sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="YOUR_APP_CLIENT_ID", redirect_uri="YOUR_APP_REDIRECT_URI", scope="user-library-read")) ``` -E. Replace YOUR_APP_CLIENT_ID and YOUR_APP_CLIENT_SECRET with the values you copied and saved in step 1D. Replace YOUR_APP_REDIRECT_URI with the URI you set in step 1C. +D. Replace YOUR_APP_CLIENT_ID and YOUR_APP_CLIENT_SECRET with the values you copied and saved in step 1D. Replace YOUR_APP_REDIRECT_URI with the URI you set in step 1B. ## Step 3. Start Using Spotipy @@ -100,7 +92,7 @@ In most cases, the recent Python version is Python 3. You may need to update Pyt B. Encountering package error: -If you are seeing an error "ModuleNotFoundError: No module named 'spotipy'", this means you have not installed the package. This may occur if you followed the installation and setup (up to Step 3, Part D) and attempted to run the app with the missing package. +If you are seeing an error "ModuleNotFoundError: No module named 'spotipy'", this means you have not installed the package. Run the command: ``` pip install spotipy diff --git a/docs/conf.py b/docs/conf.py index df657248..69d99433 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -16,7 +16,7 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath("..")) @@ -25,7 +25,7 @@ # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. @@ -41,7 +41,7 @@ source_suffix = '.rst' # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' @@ -61,37 +61,37 @@ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- @@ -103,26 +103,26 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -131,44 +131,44 @@ # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'spotipydoc' @@ -196,23 +196,23 @@ # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output -------------------------------------------- @@ -225,7 +225,7 @@ ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ @@ -240,10 +240,10 @@ ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' diff --git a/docs/index.rst b/docs/index.rst index 3534bfac..c7ef2bc8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -302,30 +302,6 @@ If you think you've found a bug, let us know at Contribute ========== -Spotipy authored by Paul Lamere (plamere) with contributions by: - - - Daniel Beaudry (`danbeaudry on Github `_) - - Faruk Emre Sahin (`fsahin on Github `_) - - George (`rogueleaderr on Github `_) - - Henry Greville (`sethaurus on Github `_) - - Hugo van Kemanade (`hugovk on Github `_) - - José Manuel Pérez (`JMPerez on Github `_) - - Lucas Nunno (`lnunno on Github `_) - - Lynn Root (`econchick on Github `_) - - Matt Dennewitz (`mattdennewitz on Github `_) - - Matthew Duck (`mattduck on Github `_) - - Michael Thelin (`thelinmichael on Github `_) - - Ryan Choi (`ryankicks on Github `_) - - Simon Metson (`drsm79 on Github `_) - - Steve Winton (`swinton on Github `_) - - Tim Balzer (`timbalzer on Github `_) - - `corycorycory on Github `_ - - Nathan Coleman (`nathancoleman on Github `_) - - Michael Birtwell (`mbirtwell on Github `_) - - Harrison Hayes (`Harrison97 on Github `_) - - Stephane Bruckert (`stephanebruckert on Github `_) - - Ritiek Malhotra (`ritiek on Github `_) - If you are a developer with Python experience, and you would like to contribute to Spotipy, please be sure to follow the guidelines listed below: @@ -402,4 +378,3 @@ Indices and tables * :ref:`genindex` * :ref:`modindex` * :ref:`search` - diff --git a/spotipy/client.py b/spotipy/client.py index 6087732b..caaf9ca9 100644 --- a/spotipy/client.py +++ b/spotipy/client.py @@ -841,11 +841,9 @@ def user_playlist_change_details( collaborative=None, description=None, ): - warnings.warn( - "You should use `playlist_change_details(playlist_id, ...)` instead", - DeprecationWarning, - ) - """ Changes a playlist's name and/or public/private state + """ This function is no longer in use, please use the recommended function in the warning! + + Changes a playlist's name and/or public/private state Parameters: - user - the id of the user @@ -855,12 +853,18 @@ def user_playlist_change_details( - collaborative - optional is the playlist collaborative - description - optional description of the playlist """ + warnings.warn( + "You should use `playlist_change_details(playlist_id, ...)` instead", + DeprecationWarning, + ) return self.playlist_change_details(playlist_id, name, public, collaborative, description) def user_playlist_unfollow(self, user, playlist_id): - """ Unfollows (deletes) a playlist for a user + """ This function is no longer in use, please use the recommended function in the warning! + + Unfollows (deletes) a playlist for a user Parameters: - user - the id of the user @@ -875,11 +879,9 @@ def user_playlist_unfollow(self, user, playlist_id): def user_playlist_add_tracks( self, user, playlist_id, tracks, position=None ): - warnings.warn( - "You should use `playlist_add_items(playlist_id, tracks)` instead", - DeprecationWarning, - ) - """ Adds tracks to a playlist + """ This function is no longer in use, please use the recommended function in the warning! + + Adds tracks to a playlist Parameters: - user - the id of the user @@ -887,17 +889,20 @@ def user_playlist_add_tracks( - tracks - a list of track URIs, URLs or IDs - position - the position to add the tracks """ + warnings.warn( + "You should use `playlist_add_items(playlist_id, tracks)` instead", + DeprecationWarning, + ) + tracks = [self._get_uri("track", tid) for tid in tracks] return self.playlist_add_items(playlist_id, tracks, position) def user_playlist_add_episodes( self, user, playlist_id, episodes, position=None ): - warnings.warn( - "You should use `playlist_add_items(playlist_id, episodes)` instead", - DeprecationWarning, - ) - """ Adds episodes to a playlist + """ This function is no longer in use, please use the recommended function in the warning! + + Adds episodes to a playlist Parameters: - user - the id of the user @@ -905,11 +910,18 @@ def user_playlist_add_episodes( - episodes - a list of track URIs, URLs or IDs - position - the position to add the episodes """ + warnings.warn( + "You should use `playlist_add_items(playlist_id, episodes)` instead", + DeprecationWarning, + ) + episodes = [self._get_uri("episode", tid) for tid in episodes] return self.playlist_add_items(playlist_id, episodes, position) def user_playlist_replace_tracks(self, user, playlist_id, tracks): - """ Replace all tracks in a playlist for a user + """ This function is no longer in use, please use the recommended function in the warning! + + Replace all tracks in a playlist for a user Parameters: - user - the id of the user @@ -931,7 +943,9 @@ def user_playlist_reorder_tracks( range_length=1, snapshot_id=None, ): - """ Reorder tracks in a playlist from a user + """ This function is no longer in use, please use the recommended function in the warning! + + Reorder tracks in a playlist from a user Parameters: - user - the id of the user @@ -954,14 +968,15 @@ def user_playlist_reorder_tracks( def user_playlist_remove_all_occurrences_of_tracks( self, user, playlist_id, tracks, snapshot_id=None ): - """ Removes all occurrences of the given tracks from the given playlist + """ This function is no longer in use, please use the recommended function in the warning! + + Removes all occurrences of the given tracks from the given playlist Parameters: - user - the id of the user - playlist_id - the id of the playlist - tracks - the list of track ids to remove from the playlist - snapshot_id - optional id of the playlist snapshot - """ warnings.warn( "You should use `playlist_remove_all_occurrences_of_items" @@ -975,7 +990,9 @@ def user_playlist_remove_all_occurrences_of_tracks( def user_playlist_remove_specific_occurrences_of_tracks( self, user, playlist_id, tracks, snapshot_id=None ): - """ Removes all occurrences of the given tracks from the given playlist + """ This function is no longer in use, please use the recommended function in the warning! + + Removes all occurrences of the given tracks from the given playlist Parameters: - user - the id of the user @@ -1009,13 +1026,13 @@ def user_playlist_remove_specific_occurrences_of_tracks( ) def user_playlist_follow_playlist(self, playlist_owner_id, playlist_id): - """ - Add the current authenticated user as a follower of a playlist. + """ This function is no longer in use, please use the recommended function in the warning! - Parameters: - - playlist_owner_id - the user id of the playlist owner - - playlist_id - the id of the playlist + Add the current authenticated user as a follower of a playlist. + Parameters: + - playlist_owner_id - the user id of the playlist owner + - playlist_id - the id of the playlist """ warnings.warn( "You should use `current_user_follow_playlist(playlist_id)` instead", @@ -1026,15 +1043,15 @@ def user_playlist_follow_playlist(self, 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 + """ This function is no longer in use, please use the recommended function in the warning! - 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. + 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. """ warnings.warn( "You should use `playlist_is_following(playlist_id, user_ids)` instead", diff --git a/spotipy/util.py b/spotipy/util.py index 30eb9d43..cf72d7ec 100644 --- a/spotipy/util.py +++ b/spotipy/util.py @@ -1,5 +1,6 @@ from __future__ import annotations -""" Shows a user's playlists (need to be authenticated via oauth) """ + +""" Shows a user's playlists. This needs to be authenticated via OAuth. """ __all__ = ["CLIENT_CREDS_ENV_VARS", "prompt_for_user_token"] @@ -39,21 +40,18 @@ def prompt_for_user_token( " spotipy.Spotify(auth_manager=auth_manager)", DeprecationWarning ) - """ prompts the user to login if necessary and returns - the user token suitable for use with the spotipy.Spotify - constructor + """Prompt the user to login if necessary and returns a user token + suitable for use with the spotipy.Spotify constructor. Parameters: - - - username - the Spotify username (optional) - - scope - the desired scope of the request (optional) - - client_id - the client id of your app (required) - - client_secret - the client secret of your app (required) - - redirect_uri - the redirect URI of your app (required) - - cache_path - path to location to save tokens (optional) - - oauth_manager - Oauth manager object (optional) - - show_dialog - If true, a login prompt always shows (optional, defaults to False) - + - username - the Spotify username. (optional) + - scope - the desired scope of the request. (optional) + - client_id - the client ID of your app. (required) + - client_secret - the client secret of your app. (required) + - redirect_uri - the redirect URI of your app. (required) + - cache_path - path to location to save tokens. (required) + - oauth_manager - OAuth manager object. (optional) + - show_dialog - If True, a login prompt always shows or defaults to False. (optional) """ if not oauth_manager: if not client_id: @@ -111,6 +109,12 @@ def prompt_for_user_token( def get_host_port(netloc): + """ Split the network location string into host and port and returns a tuple + where the host is a string and the the port is an integer. + + Parameters: + - netloc - a string representing the network location. + """ if ":" in netloc: host, port = netloc.split(":", 1) port = int(port) @@ -122,6 +126,14 @@ def get_host_port(netloc): def normalize_scope(scope): + """Normalize the scope to verify that it is a list or tuple. A string + input will split the string by commas to create a list of scopes. + A list or tuple input is used directly. + + Parameters: + - scope - a string representing scopes separated by commas, + or a list/tuple of scopes. + """ if scope: if isinstance(scope, str): scopes = scope.split(',') @@ -130,7 +142,7 @@ def normalize_scope(scope): else: raise Exception( "Unsupported scope value, please either provide a list of scopes, " - "or a string of scopes separated by commas" + "or a string of scopes separated by commas." ) return " ".join(sorted(scopes)) else: diff --git a/tests/integration/non_user_endpoints/test.py b/tests/integration/non_user_endpoints/test.py index e4f222a9..2aa878b5 100644 --- a/tests/integration/non_user_endpoints/test.py +++ b/tests/integration/non_user_endpoints/test.py @@ -37,12 +37,19 @@ class AuthTestSpotipy(unittest.TestCase): creep_urn = 'spotify:track:6b2oQwSGFkzsMtQruIWm2p' creep_id = '6b2oQwSGFkzsMtQruIWm2p' creep_url = 'http://open.spotify.com/track/6b2oQwSGFkzsMtQruIWm2p' + el_scorcho_urn = 'spotify:track:0Svkvt5I79wficMFgaqEQJ' el_scorcho_bad_urn = 'spotify:track:0Svkvt5I79wficMFgaqEQK' pinkerton_urn = 'spotify:album:04xe676vyiTeYNXw15o9jT' weezer_urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu' + pablo_honey_urn = 'spotify:album:6AZv3m27uyRxi8KyJSfUxL' radiohead_urn = 'spotify:artist:4Z8W4fKeB5YxbusRsdQVPb' + radiohead_id = "4Z8W4fKeB5YxbusRsdQVPb" + radiohead_url = "https://open.spotify.com/artist/4Z8W4fKeB5YxbusRsdQVPb" + + qotsa_url = "https://open.spotify.com/artist/4pejUc4iciQfgdX6OKulQn" + angeles_haydn_urn = 'spotify:album:1vAbqAeuJVWNAe7UR00bdM' heavyweight_urn = 'spotify:show:5c26B28vZMN8PG0Nppmn5G' heavyweight_id = '5c26B28vZMN8PG0Nppmn5G' @@ -53,15 +60,12 @@ class AuthTestSpotipy(unittest.TestCase): heavyweight_ep1_url = 'https://open.spotify.com/episode/68kq3bNz6hEuq8NtdfwERG' reply_all_ep1_urn = 'spotify:episode:1KHjbpnmNpFmNTczQmTZlR' - american_gods_urn = 'spotify:audiobook:1IcM9Untg6d3ktuwObYGcN' - american_gods_id = '1IcM9Untg6d3ktuwObYGcN' - american_gods_url = 'https://open.spotify.com/audiobook/1IcM9Untg6d3ktuwObYGcN' - - four_books = [ - 'spotify:audiobook:1IcM9Untg6d3ktuwObYGcN', - 'spotify:audiobook:37sRC6carIX2Vf3Vv716T7', - 'spotify:audiobook:1Gep4UJ95xQawA55OgRI8n', - 'spotify:audiobook:4Sm381mcf5gBsi9yfhqgVB'] + dune_urn = 'spotify:audiobook:7iHfbu1YPACw6oZPAFJtqe' + dune_id = '7iHfbu1YPACw6oZPAFJtqe' + dune_url = 'https://open.spotify.com/audiobook/7iHfbu1YPACw6oZPAFJtqe' + two_books = [ + 'spotify:audiobook:7iHfbu1YPACw6oZPAFJtqe', + 'spotify:audiobook:67VtmjZitn25TWocsyAEyh'] @classmethod def setUpClass(self): @@ -101,11 +105,24 @@ def test_artist_urn(self): artist = self.spotify.artist(self.radiohead_urn) self.assertTrue(artist['name'] == 'Radiohead') + def test_artist_url(self): + artist = self.spotify.artist(self.radiohead_url) + self.assertTrue(artist['name'] == 'Radiohead') + + def test_artist_id(self): + artist = self.spotify.artist(self.radiohead_id) + self.assertTrue(artist['name'] == 'Radiohead') + def test_artists(self): results = self.spotify.artists([self.weezer_urn, self.radiohead_urn]) self.assertTrue('artists' in results) self.assertTrue(len(results['artists']) == 2) + def test_artists_mixed_ids(self): + results = self.spotify.artists([self.weezer_urn, self.radiohead_id, self.qotsa_url]) + self.assertTrue('artists' in results) + self.assertTrue(len(results['artists']) == 3) + def test_album_urn(self): album = self.spotify.album(self.pinkerton_urn) self.assertTrue(album['name'] == 'Pinkerton') @@ -317,7 +334,7 @@ def test_artist_albums(self): def find_album(): for album in results['items']: - if album['name'] == 'Death to False Metal': + if 'Weezer' in album['name']: # Weezer has many albums containing Weezer return True return False @@ -465,27 +482,25 @@ def test_available_markets(self): self.assertIn("GB", markets) def test_get_audiobook(self): - audiobook = self.spotify.get_audiobook(self.american_gods_urn, market="US") + audiobook = self.spotify.get_audiobook(self.dune_urn, market="US") self.assertTrue(audiobook['name'] == - 'American Gods: The Tenth Anniversary Edition: A Novel') + 'Dune: Book One in the Dune Chronicles') def test_get_audiobook_bad_urn(self): with self.assertRaises(SpotifyException): self.spotify.get_audiobook("bogus_urn", market="US") def test_get_audiobooks(self): - results = self.spotify.get_audiobooks(self.four_books, market="US") + results = self.spotify.get_audiobooks(self.two_books, market="US") self.assertTrue('audiobooks' in results) - self.assertTrue(len(results['audiobooks']) == 4) - self.assertTrue(results['audiobooks'][0]['name'] == - 'American Gods: The Tenth Anniversary Edition: A Novel') - self.assertTrue(results['audiobooks'][1]['name'] == 'The Da Vinci Code: A Novel') - self.assertTrue(results['audiobooks'][2]['name'] == 'Outlander') - self.assertTrue(results['audiobooks'][3]['name'] == 'Pachinko: A Novel') + self.assertTrue(len(results['audiobooks']) == 2) + self.assertTrue(results['audiobooks'][0]['name'] + == 'Dune: Book One in the Dune Chronicles') + self.assertTrue(results['audiobooks'][1]['name'] == 'The Helper') def test_get_audiobook_chapters(self): results = self.spotify.get_audiobook_chapters( - self.american_gods_urn, market="US", limit=10, offset=5) + self.dune_urn, market="US", limit=10, offset=5) self.assertTrue('items' in results) self.assertTrue(len(results['items']) == 10) self.assertTrue(results['items'][0]['chapter_number'] == 5)