Skip to content

TST: Load integration test creds from env vars #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ Running Google BigQuery Integration Tests
You will need to create a Google BigQuery private key in JSON format in
order to run Google BigQuery integration tests on your local machine and
on Travis-CI. The first step is to create a `service account
<https://console.developers.google.com/iam-admin/serviceaccounts/>`__.
<https://console.cloud.google.com/iam-admin/serviceaccounts/>`__.

To run the integration tests locally, set the following environment variables
before running ``pytest``:

#. ``GBQ_PROJECT_ID`` with the value being the ID of your BigQuery project.
#. ``GBQ_GOOGLE_APPLICATION_CREDENTIALS`` with the value being the *path* to
the JSON key that you downloaded for your service account.

Integration tests are skipped in pull requests because the credentials that
are required for running Google BigQuery integration tests are
Expand All @@ -248,8 +255,8 @@ gbq integration tests on a forked repository:

- ``GBQ_PROJECT_ID`` with the value being the ID of your BigQuery project.

- ``SERVICE_ACCOUNT_KEY`` with the value being the contents of the JSON key
that you downloaded for your service account. Use single quotes around
- ``SERVICE_ACCOUNT_KEY`` with the value being the *contents* of the JSON
key that you downloaded for your service account. Use single quotes around
your JSON key to ensure that it is treated as a string.

For both environment variables, keep the "Display value in build log" option
Expand Down
22 changes: 8 additions & 14 deletions pandas_gbq/tests/test_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
import pandas.util.testing as tm
from pandas.compat.numpy import np_datetime64_compat

PROJECT_ID = None
PRIVATE_KEY_JSON_PATH = None
PRIVATE_KEY_JSON_CONTENTS = None

TABLE_ID = 'new_test'

Expand Down Expand Up @@ -66,27 +63,24 @@ def _get_dataset_prefix_random():


def _get_project_id():
if _in_travis_environment():
return os.environ.get('GBQ_PROJECT_ID')
else:
return PROJECT_ID
return os.environ.get('GBQ_PROJECT_ID')


def _get_private_key_path():
if _in_travis_environment():
return os.path.join(*[os.environ.get('TRAVIS_BUILD_DIR'), 'ci',
'travis_gbq.json'])
else:
return PRIVATE_KEY_JSON_PATH
return os.environ.get('GBQ_GOOGLE_APPLICATION_CREDENTIALS')


def _get_private_key_contents():
if _in_travis_environment():
with open(os.path.join(*[os.environ.get('TRAVIS_BUILD_DIR'), 'ci',
'travis_gbq.json'])) as f:
return f.read()
else:
return PRIVATE_KEY_JSON_CONTENTS
key_path = _get_private_key_path()
if key_path is None:
return None

with open(key_path) as f:
return f.read()


def _test_imports():
Expand Down