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>
This commit is contained in:
Brennan Pate 2024-06-22 10:35:53 -05:00 committed by GitHub
parent 8f003147f7
commit d92951b356
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 76 additions and 61 deletions

View File

@ -11,6 +11,9 @@ Add your changes below.
### Added ### Added
- Added unit tests for queue functions - Added unit tests for queue functions
- Added detailed function docstrings to 'util.py', including descriptions and special sections that lists arguments, returns, and raises. - 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
### Fixed ### Fixed
- -

View File

@ -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 - 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 for the version and a short name that describes the main addition
- Verify doc uses latest https://readthedocs.org/projects/spotipy/ - Verify doc uses latest https://readthedocs.org/projects/spotipy/

View File

@ -4,25 +4,19 @@ Hello and welcome to the Spotipy Tutorial for Beginners. If you have limited exp
## Prerequisites ## Prerequisites
In order to complete this tutorial successfully, there are a few things that you should already have installed: In order to complete this tutorial successfully, there are a few things that you should already have installed:
**1. pip package manager** **1. python3**
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**
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 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/ 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: 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/
pip install spotipy
```
**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. 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 ## 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. 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. 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 Spotifys 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." 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.
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. 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.
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.
## Step 2. Installation and Setup ## 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``` 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 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", redirect_uri="YOUR_APP_REDIRECT_URI",
scope="user-library-read")) 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 ## 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: 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: Run the command:
``` ```
pip install spotipy pip install spotipy

View File

@ -402,4 +402,3 @@ Indices and tables
* :ref:`genindex` * :ref:`genindex`
* :ref:`modindex` * :ref:`modindex`
* :ref:`search` * :ref:`search`

View File

@ -37,12 +37,19 @@ class AuthTestSpotipy(unittest.TestCase):
creep_urn = 'spotify:track:6b2oQwSGFkzsMtQruIWm2p' creep_urn = 'spotify:track:6b2oQwSGFkzsMtQruIWm2p'
creep_id = '6b2oQwSGFkzsMtQruIWm2p' creep_id = '6b2oQwSGFkzsMtQruIWm2p'
creep_url = 'http://open.spotify.com/track/6b2oQwSGFkzsMtQruIWm2p' creep_url = 'http://open.spotify.com/track/6b2oQwSGFkzsMtQruIWm2p'
el_scorcho_urn = 'spotify:track:0Svkvt5I79wficMFgaqEQJ' el_scorcho_urn = 'spotify:track:0Svkvt5I79wficMFgaqEQJ'
el_scorcho_bad_urn = 'spotify:track:0Svkvt5I79wficMFgaqEQK' el_scorcho_bad_urn = 'spotify:track:0Svkvt5I79wficMFgaqEQK'
pinkerton_urn = 'spotify:album:04xe676vyiTeYNXw15o9jT' pinkerton_urn = 'spotify:album:04xe676vyiTeYNXw15o9jT'
weezer_urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu' weezer_urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu'
pablo_honey_urn = 'spotify:album:6AZv3m27uyRxi8KyJSfUxL' pablo_honey_urn = 'spotify:album:6AZv3m27uyRxi8KyJSfUxL'
radiohead_urn = 'spotify:artist:4Z8W4fKeB5YxbusRsdQVPb' 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' angeles_haydn_urn = 'spotify:album:1vAbqAeuJVWNAe7UR00bdM'
heavyweight_urn = 'spotify:show:5c26B28vZMN8PG0Nppmn5G' heavyweight_urn = 'spotify:show:5c26B28vZMN8PG0Nppmn5G'
heavyweight_id = '5c26B28vZMN8PG0Nppmn5G' heavyweight_id = '5c26B28vZMN8PG0Nppmn5G'
@ -101,11 +108,24 @@ class AuthTestSpotipy(unittest.TestCase):
artist = self.spotify.artist(self.radiohead_urn) artist = self.spotify.artist(self.radiohead_urn)
self.assertTrue(artist['name'] == 'Radiohead') 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): def test_artists(self):
results = self.spotify.artists([self.weezer_urn, self.radiohead_urn]) results = self.spotify.artists([self.weezer_urn, self.radiohead_urn])
self.assertTrue('artists' in results) self.assertTrue('artists' in results)
self.assertTrue(len(results['artists']) == 2) 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): def test_album_urn(self):
album = self.spotify.album(self.pinkerton_urn) album = self.spotify.album(self.pinkerton_urn)
self.assertTrue(album['name'] == 'Pinkerton') self.assertTrue(album['name'] == 'Pinkerton')