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

This commit is contained in:
Sandeep Murthy 2018-02-17 20:33:10 +00:00 committed by Stephane Bruckert
parent e5ccb9f355
commit 2ce270554a
3 changed files with 17 additions and 8 deletions

View File

@ -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

View File

@ -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 '

View File

@ -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'