Skip to content

Commit d14cd7b

Browse files
author
Jon Wayne Parrott
committed
Cleaning up
* Moving appengine config files into tests/resources * Fixing our GAE downloader to match oauth2client & urllib3's.
1 parent 89880d7 commit d14cd7b

File tree

7 files changed

+139
-30
lines changed

7 files changed

+139
-30
lines changed

.travis.yml

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,24 @@ language: python
44

55
cache:
66
directories:
7-
- $HOME/gcloud/
7+
- $HOME/.cache
8+
89
env:
9-
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/python-docs-samples.json GAE_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
10+
global:
11+
- PATH=${PATH}:${HOME}/gcloud/google-cloud-sdk/bin
12+
- GOOGLE_APPLICATION_CREDENTIALS=${TRAVIS_BUILD_DIR}/python-docs-samples.json
13+
- GAE_PYTHONPATH=${HOME}/.cache/google_appengine
14+
- TEST_BUCKET_NAME=bigquery-devrel-samples-bucket
15+
- TEST_PROJECT_ID=bigquery-devrel-samples
1016

1117
before_install:
12-
#ENCRYPT YOUR PRIVATE KEY (If you need authentication)
13-
# 1. Install and login to the Travis CLI:
14-
# $ gem install travis
15-
# $ travis login
16-
# 2. Move your json private key to client_secrets.json
17-
# 3. Run:
18-
# $ travis encrypt-file client_secrets.json --add
19-
# 4. Commit changes:
20-
# $ git add client_secrets.json.enc
21-
# $ git commit client_secrets.json.enc .travis.yml
22-
23-
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then
24-
mkdir -p $HOME/gcloud &&
25-
wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz --directory-prefix=$HOME/gcloud &&
26-
cd $HOME/gcloud &&
27-
tar xzf google-cloud-sdk.tar.gz &&
28-
printf '\ny\n\ny\ny\n' | ./google-cloud-sdk/install.sh &&
29-
cd $TRAVIS_BUILD_DIR;
30-
fi
31-
- gcloud -q components update app-engine-python
32-
- openssl aes-256-cbc -K $encrypted_4fda24e244ca_key -iv $encrypted_4fda24e244ca_iv -in python-docs-samples.json.enc -out python-docs-samples.json -d
33-
- if [ -a python-docs-samples.json ]; then
34-
gcloud auth activate-service-account --key-file python-docs-samples.json;
35-
fi
18+
- tests/scripts/travis-before-install.sh
3619

3720
install:
38-
- pip install tox coveralls
21+
- pip install tox coveralls
3922

4023
script:
41-
- tox
24+
- tox
4225

4326
after_success:
44-
coveralls
27+
- coveralls

appengine/localtesting/test_task_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setUp(self):
2828

2929
# root_path must be set the the location of queue.yaml.
3030
# Otherwise, only the 'default' queue will be available.
31-
self.testbed.init_taskqueue_stub(root_path='.')
31+
self.testbed.init_taskqueue_stub(root_path='tests/resources')
3232
self.taskqueue_stub = self.testbed.get_stub(
3333
testbed.TASKQUEUE_SERVICE_NAME)
3434

File renamed without changes.
File renamed without changes.

tests/scripts/fetch_gae_sdk.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2015 Google Inc. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Retrieved from https://github.com/Google/oauth2client
18+
"""Fetch the most recent GAE SDK and decompress it in the current directory.
19+
20+
Usage:
21+
fetch_gae_sdk.py [<dest_dir>]
22+
23+
Current releases are listed here:
24+
https://www.googleapis.com/storage/v1/b/appengine-sdks/o?prefix=featured
25+
"""
26+
27+
import json
28+
import os
29+
import StringIO
30+
import sys
31+
import urllib2
32+
import zipfile
33+
34+
_SDK_URL = (
35+
'https://www.googleapis.com/storage/v1/b/appengine-sdks/o?prefix=featured')
36+
37+
38+
def get_gae_versions():
39+
try:
40+
version_info_json = urllib2.urlopen(_SDK_URL).read()
41+
except:
42+
return {}
43+
try:
44+
version_info = json.loads(version_info_json)
45+
except:
46+
return {}
47+
return version_info.get('items', {})
48+
49+
50+
def _version_tuple(v):
51+
version_string = os.path.splitext(v['name'])[0].rpartition('_')[2]
52+
return tuple(int(x) for x in version_string.split('.'))
53+
54+
55+
def get_sdk_urls(sdk_versions):
56+
python_releases = [
57+
v for v in sdk_versions
58+
if v['name'].startswith('featured/google_appengine')]
59+
current_releases = sorted(
60+
python_releases, key=_version_tuple, reverse=True)
61+
return [release['mediaLink'] for release in current_releases]
62+
63+
64+
def main(argv):
65+
if len(argv) > 2:
66+
print('Usage: {} [<destination_dir>]'.format(argv[0]))
67+
return 1
68+
dest_dir = argv[1] if len(argv) > 1 else '.'
69+
if not os.path.exists(dest_dir):
70+
os.makedirs(dest_dir)
71+
72+
if os.path.exists(os.path.join(dest_dir, 'google_appengine')):
73+
print('GAE SDK already installed at {}, exiting.'.format(dest_dir))
74+
return 0
75+
76+
sdk_versions = get_gae_versions()
77+
if not sdk_versions:
78+
print('Error fetching GAE SDK version info')
79+
return 1
80+
sdk_urls = get_sdk_urls(sdk_versions)
81+
for sdk_url in sdk_urls:
82+
try:
83+
sdk_contents = StringIO.StringIO(urllib2.urlopen(sdk_url).read())
84+
break
85+
except:
86+
pass
87+
else:
88+
print('Could not read SDK from any of {}'.format(sdk_urls))
89+
return 1
90+
sdk_contents.seek(0)
91+
try:
92+
zip_contents = zipfile.ZipFile(sdk_contents)
93+
zip_contents.extractall(dest_dir)
94+
print('GAE SDK Installed to {}.'.format(dest_dir))
95+
except:
96+
print('Error extracting SDK contents')
97+
return 1
98+
99+
if __name__ == '__main__':
100+
sys.exit(main(sys.argv[:]))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -ev
4+
5+
# Install Google App Engine Python SDK
6+
if [[ ! -d "${GAE_PYTHONPATH}" ]]; then
7+
python tests/scripts/fetch_gae_sdk.py `dirname "${GAE_PYTHONPATH}"`
8+
fi
9+
10+
# Google Cloud Service account key.
11+
# ENCRYPT YOUR PRIVATE KEY (If you need authentication)
12+
# 1. Install and login to the Travis CLI:
13+
# $ gem install travis
14+
# $ travis login
15+
# 2. Move your json private key to client_secrets.json
16+
# 3. Run:
17+
# $ travis encrypt-file client_secrets.json --add
18+
# 4. Commit changes:
19+
# $ git add client_secrets.json.enc
20+
# $ git commit client_secrets.json.enc .travis.yml
21+
openssl aes-256-cbc \
22+
-K $encrypted_4fda24e244ca_key \
23+
-iv $encrypted_4fda24e244ca_iv \
24+
-in ${TRAVIS_BUILD_DIR}/python-docs-samples.json.enc \
25+
-out ${TRAVIS_BUILD_DIR}/python-docs-samples.json -d

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ deps =
2525
nosegae
2626
commands =
2727
nosetests --with-gae \
28+
--gae-app=tests/resources/app.yaml \
2829
--logging-level=INFO \
2930
{[testenv]coverargs} \
3031
{posargs:appengine}

0 commit comments

Comments
 (0)