Skip to content

Commit 2299bfa

Browse files
author
Takashi Matsuo
committed
Introduced TEST_PROJECT_ID and TEST_BUCKET_NAME envvars.
1 parent 03af64b commit 2299bfa

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Google Cloud SDK installation path.
3131
$ pip install tox
3232
$ export PYTHONPATH=${GCLOUD}/platform/google_appengine
3333
$ export GOOGLE_APPLICATION_CREDENTIALS=your-service-account-json-file
34+
$ export TEST_PROJECT_ID={YOUR_PROJECT_ID}
35+
$ export TEST_BUCKET={YOUR_BUCKET_NAME}
3436
$ tox
3537

3638
## Licensing

bigquery/test/base_test.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,32 @@
1818
from bigquery.test import RESOURCE_PATH
1919

2020

21+
BUCKET_NAME_ENV = 'TEST_BUCKET_NAME'
22+
PROJECT_ID_ENV = 'TEST_PROJECT_ID'
23+
24+
2125
class BaseBigqueryTest(unittest.TestCase):
2226

2327
def setUp(self):
24-
# A hack to prevent get_application_default to choose App Engine route.
28+
# A hack to prevent get_application_default from going GAE route.
2529
self._server_software_org = os.environ.get('SERVER_SOFTWARE')
2630
os.environ['SERVER_SOFTWARE'] = ''
27-
31+
test_bucket_name = os.environ.get(BUCKET_NAME_ENV, '')
32+
test_project_id = os.environ.get(PROJECT_ID_ENV, '')
33+
if not test_project_id or not test_bucket_name:
34+
raise Exception('You need to define an env var "%s" and "%s" to '
35+
'run the test.'
36+
% (PROJECT_ID_ENV, BUCKET_NAME_ENV))
2837
with open(
2938
os.path.join(RESOURCE_PATH, 'constants.json'),
3039
'r') as constants_file:
3140

3241
self.constants = json.load(constants_file)
42+
self.constants['projectId'] = test_project_id
43+
self.constants['cloudStorageInputURI'] = (
44+
self.constants['cloudStorageInputURI'] % test_bucket_name)
45+
self.constants['cloudStorageOutputURI'] = (
46+
self.constants['cloudStorageOutputURI'] % test_bucket_name)
3347

3448
def tearDown(self):
3549
os.environ['SERVER_SOFTWARE'] = self._server_software_org

resources/constants.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"projectId": "bigquery-devrel-samples",
32
"datasetId": "test_dataset",
43
"currentTableId": "test_table",
54
"newTableId": "test_table2",
6-
"cloudStorageInputURI": "gs://bigquery-devrel-samples-bucket/data.csv",
7-
"cloudStorageOutputURI": "gs://bigquery-devrel-samples-bucket/output.csv",
5+
"cloudStorageInputURI": "gs://%s/data.csv",
6+
"cloudStorageOutputURI": "gs://%s/output.csv",
87
"query": "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;"
98
}

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ skipsdist = True
33
envlist = {py27}-{nosetest,pep8}, cover
44

55
[testenv]
6-
passenv = PYTHONPATH GOOGLE_* GCLOUD_* PROJECT_ID TRAVIS*
6+
passenv = PYTHONPATH GOOGLE_* GCLOUD_* TEST_* TRAVIS*
77
basepython =
88
cover,py27: python2.7
99
deps =

0 commit comments

Comments
 (0)