Skip to content

Added GCLOUD_* and TEST_* envvar to passenv section. #18

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 3 commits into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Introduced TEST_PROJECT_ID and TEST_BUCKET_NAME envvars.
  • Loading branch information
Takashi Matsuo committed May 15, 2015
commit 2299bfa2a290b1eca68f90f43db0fe563418456f
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Google Cloud SDK installation path.
$ pip install tox
$ export PYTHONPATH=${GCLOUD}/platform/google_appengine
$ export GOOGLE_APPLICATION_CREDENTIALS=your-service-account-json-file
$ export TEST_PROJECT_ID={YOUR_PROJECT_ID}
$ export TEST_BUCKET={YOUR_BUCKET_NAME}
$ tox

## Licensing
Expand Down
18 changes: 16 additions & 2 deletions bigquery/test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,32 @@
from bigquery.test import RESOURCE_PATH


BUCKET_NAME_ENV = 'TEST_BUCKET_NAME'
PROJECT_ID_ENV = 'TEST_PROJECT_ID'


class BaseBigqueryTest(unittest.TestCase):

def setUp(self):
# A hack to prevent get_application_default to choose App Engine route.
# A hack to prevent get_application_default from going GAE route.
self._server_software_org = os.environ.get('SERVER_SOFTWARE')
os.environ['SERVER_SOFTWARE'] = ''

test_bucket_name = os.environ.get(BUCKET_NAME_ENV, '')
test_project_id = os.environ.get(PROJECT_ID_ENV, '')
if not test_project_id or not test_bucket_name:
raise Exception('You need to define an env var "%s" and "%s" to '
'run the test.'
% (PROJECT_ID_ENV, BUCKET_NAME_ENV))
with open(
os.path.join(RESOURCE_PATH, 'constants.json'),
'r') as constants_file:

self.constants = json.load(constants_file)
self.constants['projectId'] = test_project_id
self.constants['cloudStorageInputURI'] = (
self.constants['cloudStorageInputURI'] % test_bucket_name)
self.constants['cloudStorageOutputURI'] = (
self.constants['cloudStorageOutputURI'] % test_bucket_name)

def tearDown(self):
os.environ['SERVER_SOFTWARE'] = self._server_software_org
5 changes: 2 additions & 3 deletions resources/constants.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"projectId": "bigquery-devrel-samples",
"datasetId": "test_dataset",
"currentTableId": "test_table",
"newTableId": "test_table2",
"cloudStorageInputURI": "gs://bigquery-devrel-samples-bucket/data.csv",
"cloudStorageOutputURI": "gs://bigquery-devrel-samples-bucket/output.csv",
"cloudStorageInputURI": "gs://%s/data.csv",
"cloudStorageOutputURI": "gs://%s/output.csv",
"query": "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;"
}
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ skipsdist = True
envlist = {py27}-{nosetest,pep8}, cover

[testenv]
passenv = PYTHONPATH GOOGLE_* GCLOUD_* PROJECT_ID TRAVIS*
passenv = PYTHONPATH GOOGLE_* GCLOUD_* TEST_* TRAVIS*
basepython =
cover,py27: python2.7
deps =
Expand Down