From 2ce270554ad503390bcb6c15ce6eab38bf8ecbcb Mon Sep 17 00:00:00 2001 From: Sandeep Murthy Date: Sat, 17 Feb 2018 20:33:10 +0000 Subject: [PATCH] Update tests - make client credentials env. vars list a commonly accessible dictionary in `spotipy/util.py` --- spotipy/util.py | 8 ++++++++ tests/test_auth.py | 9 +++++---- tests/tests.py | 8 ++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/spotipy/util.py b/spotipy/util.py index 0480fd6..3eb1c52 100644 --- a/spotipy/util.py +++ b/spotipy/util.py @@ -5,6 +5,7 @@ from __future__ import print_function __all__ = [ + 'CLIENT_CREDS_ENV_VARS', 'prompt_for_user_token' ] @@ -14,6 +15,13 @@ from . import oauth2 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, client_secret = None, redirect_uri = None, cache_path = None): ''' prompts the user to login if necessary and returns diff --git a/tests/test_auth.py b/tests/test_auth.py index bd8f77c..e72807b 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -24,6 +24,7 @@ import simplejson as json sys.path.insert(0, os.path.abspath(os.pardir)) from spotipy import ( + CLIENT_CREDS_ENV_VARS as CCEV, prompt_for_user_token, Spotify, SpotifyException, @@ -60,13 +61,13 @@ class AuthTestSpotipy(unittest.TestCase): @classmethod 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: - 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 = ( 'playlist-modify-public ' diff --git a/tests/tests.py b/tests/tests.py index babc375..63ab860 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -10,6 +10,7 @@ import requests sys.path.insert(0, os.path.abspath(os.pardir)) from spotipy import ( + CLIENT_CREDS_ENV_VARS as CCEV, prompt_for_user_token, Spotify, SpotifyException, @@ -46,13 +47,12 @@ class TestSpotipy(unittest.TestCase): @classmethod 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: - 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'