From d79596c55abad79f8655d0484fb77e28a094ec8f Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Fri, 28 Oct 2016 11:08:57 -0700 Subject: [PATCH 1/2] Move GAE environment setup to nox --- system_tests/app_engine/test_app_engine.py | 42 ++------------------- system_tests/nox.py | 43 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/system_tests/app_engine/test_app_engine.py b/system_tests/app_engine/test_app_engine.py index a6ccb718f..834f9c870 100644 --- a/system_tests/app_engine/test_app_engine.py +++ b/system_tests/app_engine/test_app_engine.py @@ -13,46 +13,10 @@ # limitations under the License. import os -import subprocess -from google.auth import _cloud_sdk -import pytest +TEST_APP_URL = os.environ['TEST_APP_URL'] -SKIP_TEST_ENV = 'SKIP_APP_ENGINE_SYSTEM_TEST' -HERE = os.path.dirname(__file__) -TEST_APP_DIR = os.path.join(HERE, 'app') -TEST_APP_SERVICE = 'google-auth-system-tests' - -def vendor_app_dependencies(): - """Vendors in the test application's third-party dependencies.""" - subprocess.check_call( - ['pip', 'install', '--target', 'lib', '-r', 'requirements.txt']) - - -def deploy_app(): - """Deploys the test application using gcloud.""" - subprocess.check_call( - ['gcloud', 'app', 'deploy', '-q', 'app.yaml']) - - -@pytest.fixture -def app(monkeypatch): - monkeypatch.chdir(TEST_APP_DIR) - - vendor_app_dependencies() - deploy_app() - - application_id = _cloud_sdk.get_project_id() - application_url = 'https://{}-dot-{}.appspot.com'.format( - TEST_APP_SERVICE, application_id) - - yield application_url - - -@pytest.mark.skipif( - SKIP_TEST_ENV in os.environ, - reason='Explicitly skipping App Engine system tests.') -def test_live_application(app, http_request): - response = http_request(method='GET', url=app) +def test_live_application(http_request): + response = http_request(method='GET', url=TEST_APP_URL) assert response.status == 200, response.data.decode('utf-8') diff --git a/system_tests/nox.py b/system_tests/nox.py index 67f99004d..680318d88 100644 --- a/system_tests/nox.py +++ b/system_tests/nox.py @@ -23,12 +23,13 @@ """ 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') @@ -36,6 +37,10 @@ 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 = ( @@ -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(): @@ -208,4 +214,37 @@ def session_compute_engine(session): def session_app_engine(session): session.virtualenv = False + + if SKIP_GAE_TEST_ENV in os.environ: + 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() + + 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', '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', 'app_engine/test_app_engine.py') From dca9ce8eddc2135963d126b419b47dbdcd027bab Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Fri, 28 Oct 2016 11:11:10 -0700 Subject: [PATCH 2/2] Re-organize GAE test files. --- .../{app_engine/app => app_engine_test_app}/.gitignore | 0 system_tests/{app_engine/app => app_engine_test_app}/app.yaml | 0 .../app => app_engine_test_app}/appengine_config.py | 0 system_tests/{app_engine/app => app_engine_test_app}/main.py | 0 .../{app_engine/app => app_engine_test_app}/requirements.txt | 0 system_tests/nox.py | 4 ++-- system_tests/{app_engine => }/test_app_engine.py | 0 7 files changed, 2 insertions(+), 2 deletions(-) rename system_tests/{app_engine/app => app_engine_test_app}/.gitignore (100%) rename system_tests/{app_engine/app => app_engine_test_app}/app.yaml (100%) rename system_tests/{app_engine/app => app_engine_test_app}/appengine_config.py (100%) rename system_tests/{app_engine/app => app_engine_test_app}/main.py (100%) rename system_tests/{app_engine/app => app_engine_test_app}/requirements.txt (100%) rename system_tests/{app_engine => }/test_app_engine.py (100%) diff --git a/system_tests/app_engine/app/.gitignore b/system_tests/app_engine_test_app/.gitignore similarity index 100% rename from system_tests/app_engine/app/.gitignore rename to system_tests/app_engine_test_app/.gitignore diff --git a/system_tests/app_engine/app/app.yaml b/system_tests/app_engine_test_app/app.yaml similarity index 100% rename from system_tests/app_engine/app/app.yaml rename to system_tests/app_engine_test_app/app.yaml diff --git a/system_tests/app_engine/app/appengine_config.py b/system_tests/app_engine_test_app/appengine_config.py similarity index 100% rename from system_tests/app_engine/app/appengine_config.py rename to system_tests/app_engine_test_app/appengine_config.py diff --git a/system_tests/app_engine/app/main.py b/system_tests/app_engine_test_app/main.py similarity index 100% rename from system_tests/app_engine/app/main.py rename to system_tests/app_engine_test_app/main.py diff --git a/system_tests/app_engine/app/requirements.txt b/system_tests/app_engine_test_app/requirements.txt similarity index 100% rename from system_tests/app_engine/app/requirements.txt rename to system_tests/app_engine_test_app/requirements.txt diff --git a/system_tests/nox.py b/system_tests/nox.py index 680318d88..6429f7b66 100644 --- a/system_tests/nox.py +++ b/system_tests/nox.py @@ -236,7 +236,7 @@ def session_app_engine(session): GAE_TEST_APP_SERVICE, project_id) # Vendor in the test application's dependencies - session.chdir(os.path.join(HERE, 'app_engine', 'app')) + session.chdir(os.path.join(HERE, 'app_engine_test_app')) session.run( 'pip', 'install', '--target', 'lib', '-r', 'requirements.txt', silent=True) @@ -247,4 +247,4 @@ def session_app_engine(session): # Run the tests session.env['TEST_APP_URL'] = application_url session.chdir(HERE) - session.run('pytest', 'app_engine/test_app_engine.py') + session.run('pytest', 'test_app_engine.py') diff --git a/system_tests/app_engine/test_app_engine.py b/system_tests/test_app_engine.py similarity index 100% rename from system_tests/app_engine/test_app_engine.py rename to system_tests/test_app_engine.py