Skip to content
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

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

Merged
merged 3 commits into from
May 15, 2015
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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;"
}
4 changes: 1 addition & 3 deletions 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 PROJECT_ID TRAVIS*
passenv = PYTHONPATH GOOGLE_* GCLOUD_* TEST_* TRAVIS*
basepython =
cover,py27: python2.7
deps =
Expand All @@ -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 \
Expand Down