diff --git a/system_tests/app_engine/test_app_engine.py b/system_tests/app_engine/test_app_engine.py deleted file mode 100644 index a6ccb718f..000000000 --- a/system_tests/app_engine/test_app_engine.py +++ /dev/null @@ -1,58 +0,0 @@ -# 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 -import subprocess - -from google.auth import _cloud_sdk -import pytest - -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) - assert response.status == 200, response.data.decode('utf-8') 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 67f99004d..6429f7b66 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 - session.run('pytest', 'app_engine/test_app_engine.py') + + 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_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') diff --git a/system_tests/test_app_engine.py b/system_tests/test_app_engine.py new file mode 100644 index 000000000..834f9c870 --- /dev/null +++ b/system_tests/test_app_engine.py @@ -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'] + + +def test_live_application(http_request): + response = http_request(method='GET', url=TEST_APP_URL) + assert response.status == 200, response.data.decode('utf-8')