Skip to content

Commit

Permalink
Use environment variables to pass the credentials file to tests. When…
Browse files Browse the repository at this point in the history
… credentials are missing, use the dummy creds.
  • Loading branch information
burnash committed Oct 9, 2018
1 parent ee7a1b4 commit e0cf929
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
basestring = unicode = str


CREDS_FILENAME = os.path.join(os.path.dirname(__file__), 'creds.json')
CREDS_FILENAME = os.getenv('GS_CREDS_FILENAME')

SCOPE = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive.file',
Expand Down Expand Up @@ -51,6 +52,9 @@ def sanitize_token(interaction, current_cassette):
config.default_cassette_options['serialize_with'] = 'json_body'
config.before_record(callback=sanitize_token)

record_mode = os.environ.get('GS_RECORD_MODE', 'once')
config.default_cassette_options['record_mode'] = record_mode


def read_credentials(filename):
return ServiceAccountCredentials.from_json_keyfile_name(filename, SCOPE)
Expand All @@ -76,13 +80,12 @@ def get_temporary_spreadsheet_title(cls):

@classmethod
def setUpClass(cls):
try:
if CREDS_FILENAME:
cls.auth_credentials = read_credentials(CREDS_FILENAME)
cls.base_gc = gspread.authorize(cls.auth_credentials)
title = 'Test %s' % cls.__name__
cls.temporary_spreadsheet = cls.base_gc.create(title)

except IOError as e:
else:
cls.auth_credentials = DummyCredentials(DUMMY_ACCESS_TOKEN)

@classmethod
Expand Down

0 comments on commit e0cf929

Please sign in to comment.