|
23 | 23 | """ |
24 | 24 |
|
25 | 25 | import os |
| 26 | +import subprocess |
26 | 27 |
|
27 | 28 | from nox.command import which |
28 | 29 | import py.path |
29 | 30 |
|
30 | 31 |
|
31 | | -HERE = os.path.dirname(__file__) |
| 32 | +HERE = os.path.abspath(os.path.dirname(__file__)) |
32 | 33 | DATA_DIR = os.path.join(HERE, 'data') |
33 | 34 | SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, 'service_account.json') |
34 | 35 | AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, 'authorized_user.json') |
35 | 36 | EXPLICIT_CREDENTIALS_ENV = 'GOOGLE_APPLICATION_CREDENTIALS' |
36 | 37 | EXPLICIT_PROJECT_ENV = 'GOOGLE_CLOUD_PROJECT' |
37 | 38 | EXPECT_PROJECT_ENV = 'EXPECT_PROJECT_ID' |
38 | 39 |
|
| 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 | + |
39 | 44 | # The download location for the Cloud SDK |
40 | 45 | CLOUD_SDK_DIST_FILENAME = 'google-cloud-sdk.tar.gz' |
41 | 46 | CLOUD_SDK_DOWNLOAD_URL = ( |
@@ -81,7 +86,8 @@ def install_cloud_sdk(session): |
81 | 86 | # This tells gcloud which Python interpreter to use (always use 2.7) |
82 | 87 | session.env[CLOUD_SDK_PYTHON_ENV] = CLOUD_SDK_PYTHON |
83 | 88 |
|
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. |
85 | 91 | # Note that because of this we do not attempt to update the sdk - |
86 | 92 | # if the CLOUD_SDK_ROOT is cached, it will need to be periodically cleared. |
87 | 93 | if py.path.local(GCLOUD).exists(): |
@@ -208,4 +214,37 @@ def session_compute_engine(session): |
208 | 214 |
|
209 | 215 | def session_app_engine(session): |
210 | 216 | 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') |
0 commit comments