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

Move GAE environment setup to nox #61

Merged
merged 2 commits into from
Oct 28, 2016
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
58 changes: 0 additions & 58 deletions system_tests/app_engine/test_app_engine.py

This file was deleted.

45 changes: 42 additions & 3 deletions system_tests/nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@
"""

import os
import subprocess

from nox.command import which
import py.path


HERE = os.path.dirname(__file__)
HERE = os.path.abspath(os.path.dirname(__file__))
DATA_DIR = os.path.join(HERE, 'data')
SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, 'service_account.json')
AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, 'authorized_user.json')
EXPLICIT_CREDENTIALS_ENV = 'GOOGLE_APPLICATION_CREDENTIALS'
EXPLICIT_PROJECT_ENV = 'GOOGLE_CLOUD_PROJECT'
EXPECT_PROJECT_ENV = 'EXPECT_PROJECT_ID'

SKIP_GAE_TEST_ENV = 'SKIP_APP_ENGINE_SYSTEM_TEST'
GAE_APP_URL_TMPL = 'https://{}-dot-{}.appspot.com'
GAE_TEST_APP_SERVICE = 'google-auth-system-tests'

# The download location for the Cloud SDK
CLOUD_SDK_DIST_FILENAME = 'google-cloud-sdk.tar.gz'
CLOUD_SDK_DOWNLOAD_URL = (
Expand Down Expand Up @@ -81,7 +86,8 @@ def install_cloud_sdk(session):
# This tells gcloud which Python interpreter to use (always use 2.7)
session.env[CLOUD_SDK_PYTHON_ENV] = CLOUD_SDK_PYTHON

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

def session_app_engine(session):
session.virtualenv = False
session.run('pytest', 'app_engine/test_app_engine.py')

if SKIP_GAE_TEST_ENV in os.environ:

This comment was marked as spam.

This comment was marked as spam.

session.log('Skipping App Engine tests.')
return

# Unlike the default tests above, the App Engine system test require a
# 'real' gcloud sdk installation that is configured to deploy to an
# app engine project.
# Grab the project ID from the cloud sdk.
project_id = subprocess.check_output([
'gcloud', 'config', 'list', 'project', '--format',
'value(core.project)']).strip()

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


if not project_id:
session.error(
'The Cloud SDK must be installed and configured to deploy to App '
'Engine.')

application_url = GAE_APP_URL_TMPL.format(
GAE_TEST_APP_SERVICE, project_id)

# Vendor in the test application's dependencies
session.chdir(os.path.join(HERE, 'app_engine_test_app'))
session.run(
'pip', 'install', '--target', 'lib', '-r', 'requirements.txt',
silent=True)

# Deploy the application.
session.run('gcloud', 'app', 'deploy', '-q', 'app.yaml')

# Run the tests
session.env['TEST_APP_URL'] = application_url
session.chdir(HERE)
session.run('pytest', 'test_app_engine.py')
22 changes: 22 additions & 0 deletions system_tests/test_app_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

TEST_APP_URL = os.environ['TEST_APP_URL']

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.



def test_live_application(http_request):
response = http_request(method='GET', url=TEST_APP_URL)
assert response.status == 200, response.data.decode('utf-8')