diff --git a/.travis.yml b/.travis.yml index 74d589a6008..23846b30983 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ cache: directories: - $HOME/gcloud/ env: - - PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/python-docs-samples.json PYTHONPATH=${HOME}/gcloud/google-cloud-sdk/platform/google_appengine #Other environment variables on same line + - PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/python-docs-samples.json PYTHONPATH=${HOME}/gcloud/google-cloud-sdk/platform/google_appengine TEST_BUCKET_NAME=bigquery-devrel-samples-bucket TEST_PROJECT_ID=bigquery-devrel-samples #Other environment variables on same line before_install: #ENCRYPT YOUR PRIVATE KEY (If you need authentication) diff --git a/README.md b/README.md index 50c7c2f0f4d..4ac43111e36 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,11 @@ Google Cloud SDK installation path. $ virtualenv -p python2.7 --no-site-packages /some/where $ source /some/where/bin/activate $ pip install tox - $ env PYTHONPATH=${GCLOUD}/platform/google_appengine 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 diff --git a/bigquery/test/base_test.py b/bigquery/test/base_test.py index 9765b23a9c4..175546d9d4e 100644 --- a/bigquery/test/base_test.py +++ b/bigquery/test/base_test.py @@ -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 diff --git a/resources/constants.json b/resources/constants.json index 66b2964baf1..dd76bb905c9 100644 --- a/resources/constants.json +++ b/resources/constants.json @@ -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;" } diff --git a/tox.ini b/tox.ini index 10685b6ac31..49c4765ffdf 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ skipsdist = True envlist = {py27}-{nosetest,pep8}, cover [testenv] -passenv = PYTHONPATH PROJECT_ID TRAVIS* +passenv = PYTHONPATH GOOGLE_* GCLOUD_* TEST_* TRAVIS* basepython = cover,py27: python2.7 deps = @@ -17,8 +17,6 @@ deps = cover: coverage cover: coveralls cover: nosexcover -setenv = - GOOGLE_APPLICATION_CREDENTIALS=python-docs-samples.json commands = cover: nosetests --with-gae --with-xunit --with-xcoverage \ cover: --cover-tests --cover-branches --cover-min-percentage=70 \