Update tests - make client credentials env. vars list a commonly accessible dictionary in spotipy/util.py

This commit is contained in:
Sandeep Murthy authored and Stephane Bruckert committed 2020-01-11 19:54:20 +00:00
1 parent e5ccb9f355
commit 2ce270554a
3 files changed
+17 -8

No files matched your search

+8
View File
@@ -5,6 +5,7 @@
from __future__ import print_function from __future__ import print_function
__all__ = [ __all__ = [
'CLIENT_CREDS_ENV_VARS',
'prompt_for_user_token' 'prompt_for_user_token'
] ]
@@ -14,6 +15,13 @@ from . import oauth2
import spotipy import spotipy
CLIENT_CREDS_ENV_VARS = {
'client_id': 'SPOTIPY_CLIENT_ID',
'client_secret': 'SPOTIPY_CLIENT_SECRET',
'client_username': 'SPOTIPY_CLIENT_USERNAME',
'redirect_uri': 'SPOTIPY_REDIRECT_URI'
}
def prompt_for_user_token(username, scope=None, client_id = None, def prompt_for_user_token(username, scope=None, client_id = None,
client_secret = None, redirect_uri = None, cache_path = None): client_secret = None, redirect_uri = None, cache_path = None):
''' prompts the user to login if necessary and returns ''' prompts the user to login if necessary and returns
+5 -4
View File
@@ -24,6 +24,7 @@ import simplejson as json
sys.path.insert(0, os.path.abspath(os.pardir)) sys.path.insert(0, os.path.abspath(os.pardir))
from spotipy import ( from spotipy import (
CLIENT_CREDS_ENV_VARS as CCEV,
prompt_for_user_token, prompt_for_user_token,
Spotify, Spotify,
SpotifyException, SpotifyException,
@@ -60,13 +61,13 @@ class AuthTestSpotipy(unittest.TestCase):
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
client_cred_env_vars = ['SPOTIPY_CLIENT_USERNAME', 'SPOTIPY_CLIENT_ID', 'SPOTIPY_CLIENT_SECRET', 'SPOTIPY_REDIRECT_URI']
missing = filter(lambda var: not os.getenv(var), client_cred_env_vars) missing = filter(lambda var: not os.getenv(CCEV[var]), CCEV)
if missing: if missing:
raise Exception('Please set the client credetials for the test application using the following environment variables: {}'.format(client_cred_env_vars)) raise Exception('Please set the client credentials for the test application using the following environment variables: {}'.format(CCEV.values()))
self.username = os.getenv('SPOTIPY_CLIENT_USERNAME') self.username = os.getenv(CCEV['client_username'])
self.scope = ( self.scope = (
'playlist-modify-public ' 'playlist-modify-public '
+4 -4
View File
@@ -10,6 +10,7 @@ import requests
sys.path.insert(0, os.path.abspath(os.pardir)) sys.path.insert(0, os.path.abspath(os.pardir))
from spotipy import ( from spotipy import (
CLIENT_CREDS_ENV_VARS as CCEV,
prompt_for_user_token, prompt_for_user_token,
Spotify, Spotify,
SpotifyException, SpotifyException,
@@ -46,13 +47,12 @@ class TestSpotipy(unittest.TestCase):
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
client_cred_env_vars = ['SPOTIPY_CLIENT_USERNAME', 'SPOTIPY_CLIENT_ID', 'SPOTIPY_CLIENT_SECRET', 'SPOTIPY_REDIRECT_URI'] missing = filter(lambda var: not os.getenv(CCEV[var]), CCEV)
missing = filter(lambda var: not os.getenv(var), client_cred_env_vars)
if missing: if missing:
raise Exception('Please set the client credetials for the test application using the following environment variables: {}'.format(client_cred_env_vars)) raise Exception('Please set the client credentials for the test application using the following environment variables: {}'.format(CCEV.values()))
self.username = os.getenv('SPOTIPY_CLIENT_USERNAME') self.username = os.getenv(CCEV['client_username'])
self.scope = 'user-library-read' self.scope = 'user-library-read'