Skip to content

Commit b551ef2

Browse files
author
Jon Wayne Parrott
authored
Move GAE environment setup to nox (#61)
* Move GAE environment setup to nox * Re-organize GAE test files.
1 parent bbc3943 commit b551ef2

File tree

8 files changed

+64
-61
lines changed

8 files changed

+64
-61
lines changed

system_tests/app_engine/test_app_engine.py

Lines changed: 0 additions & 58 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

system_tests/nox.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,24 @@
2323
"""
2424

2525
import os
26+
import subprocess
2627

2728
from nox.command import which
2829
import py.path
2930

3031

31-
HERE = os.path.dirname(__file__)
32+
HERE = os.path.abspath(os.path.dirname(__file__))
3233
DATA_DIR = os.path.join(HERE, 'data')
3334
SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, 'service_account.json')
3435
AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, 'authorized_user.json')
3536
EXPLICIT_CREDENTIALS_ENV = 'GOOGLE_APPLICATION_CREDENTIALS'
3637
EXPLICIT_PROJECT_ENV = 'GOOGLE_CLOUD_PROJECT'
3738
EXPECT_PROJECT_ENV = 'EXPECT_PROJECT_ID'
3839

40+
SKIP_GAE_TEST_ENV = 'SKIP_APP_ENGINE_SYSTEM_TEST'
41+
GAE_APP_URL_TMPL = 'https://{}-dot-{}.appspot.com'
42+
GAE_TEST_APP_SERVICE = 'google-auth-system-tests'
43+
3944
# The download location for the Cloud SDK
4045
CLOUD_SDK_DIST_FILENAME = 'google-cloud-sdk.tar.gz'
4146
CLOUD_SDK_DOWNLOAD_URL = (
@@ -81,7 +86,8 @@ def install_cloud_sdk(session):
8186
# This tells gcloud which Python interpreter to use (always use 2.7)
8287
session.env[CLOUD_SDK_PYTHON_ENV] = CLOUD_SDK_PYTHON
8388

84-
# If the glcoud already exists, we don't need to do anything else.
89+
# If gcloud cli executable already exists, we don't need to do anything
90+
# else.
8591
# Note that because of this we do not attempt to update the sdk -
8692
# if the CLOUD_SDK_ROOT is cached, it will need to be periodically cleared.
8793
if py.path.local(GCLOUD).exists():
@@ -208,4 +214,37 @@ def session_compute_engine(session):
208214

209215
def session_app_engine(session):
210216
session.virtualenv = False
211-
session.run('pytest', 'app_engine/test_app_engine.py')
217+
218+
if SKIP_GAE_TEST_ENV in os.environ:
219+
session.log('Skipping App Engine tests.')
220+
return
221+
222+
# Unlike the default tests above, the App Engine system test require a
223+
# 'real' gcloud sdk installation that is configured to deploy to an
224+
# app engine project.
225+
# Grab the project ID from the cloud sdk.
226+
project_id = subprocess.check_output([
227+
'gcloud', 'config', 'list', 'project', '--format',
228+
'value(core.project)']).strip()
229+
230+
if not project_id:
231+
session.error(
232+
'The Cloud SDK must be installed and configured to deploy to App '
233+
'Engine.')
234+
235+
application_url = GAE_APP_URL_TMPL.format(
236+
GAE_TEST_APP_SERVICE, project_id)
237+
238+
# Vendor in the test application's dependencies
239+
session.chdir(os.path.join(HERE, 'app_engine_test_app'))
240+
session.run(
241+
'pip', 'install', '--target', 'lib', '-r', 'requirements.txt',
242+
silent=True)
243+
244+
# Deploy the application.
245+
session.run('gcloud', 'app', 'deploy', '-q', 'app.yaml')
246+
247+
# Run the tests
248+
session.env['TEST_APP_URL'] = application_url
249+
session.chdir(HERE)
250+
session.run('pytest', 'test_app_engine.py')

system_tests/test_app_engine.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
TEST_APP_URL = os.environ['TEST_APP_URL']
18+
19+
20+
def test_live_application(http_request):
21+
response = http_request(method='GET', url=TEST_APP_URL)
22+
assert response.status == 200, response.data.decode('utf-8')

0 commit comments

Comments
 (0)