Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 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 | """Noxfile for automating system tests. |
| 16 | |
| 17 | This file handles setting up environments needed by the system tests. This |
| 18 | separates the tests from their environment configuration. |
| 19 | |
| 20 | See the `nox docs`_ for details on how this file works: |
| 21 | |
| 22 | .. _nox docs: http://nox.readthedocs.io/en/latest/ |
| 23 | """ |
| 24 | |
| 25 | import os |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 26 | import subprocess |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 27 | |
| 28 | from nox.command import which |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 29 | import nox |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 30 | import py.path |
| 31 | |
| 32 | |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 33 | HERE = os.path.abspath(os.path.dirname(__file__)) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 34 | LIBRARY_DIR = os.path.join(HERE, "..") |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 35 | DATA_DIR = os.path.join(HERE, "data") |
| 36 | SERVICE_ACCOUNT_FILE = os.path.join(DATA_DIR, "service_account.json") |
| 37 | AUTHORIZED_USER_FILE = os.path.join(DATA_DIR, "authorized_user.json") |
| 38 | EXPLICIT_CREDENTIALS_ENV = "GOOGLE_APPLICATION_CREDENTIALS" |
| 39 | EXPLICIT_PROJECT_ENV = "GOOGLE_CLOUD_PROJECT" |
| 40 | EXPECT_PROJECT_ENV = "EXPECT_PROJECT_ID" |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 41 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 42 | SKIP_GAE_TEST_ENV = "SKIP_APP_ENGINE_SYSTEM_TEST" |
| 43 | GAE_APP_URL_TMPL = "https://{}-dot-{}.appspot.com" |
| 44 | GAE_TEST_APP_SERVICE = "google-auth-system-tests" |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 45 | |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 46 | # The download location for the Cloud SDK |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 47 | CLOUD_SDK_DIST_FILENAME = "google-cloud-sdk.tar.gz" |
| 48 | CLOUD_SDK_DOWNLOAD_URL = "https://dl.google.com/dl/cloudsdk/release/{}".format( |
| 49 | CLOUD_SDK_DIST_FILENAME |
| 50 | ) |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 51 | |
| 52 | # This environment variable is recognized by the Cloud SDK and overrides |
| 53 | # the location of the SDK's configuration files (which is usually at |
| 54 | # ${HOME}/.config). |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 55 | CLOUD_SDK_CONFIG_ENV = "CLOUDSDK_CONFIG" |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 56 | |
| 57 | # If set, this is where the environment setup will install the Cloud SDK. |
| 58 | # If unset, it will download the SDK to a temporary directory. |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 59 | CLOUD_SDK_ROOT = os.environ.get("CLOUD_SDK_ROOT") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 60 | |
| 61 | if CLOUD_SDK_ROOT is not None: |
| 62 | CLOUD_SDK_ROOT = py.path.local(CLOUD_SDK_ROOT) |
| 63 | CLOUD_SDK_ROOT.ensure(dir=True) # Makes sure the directory exists. |
| 64 | else: |
| 65 | CLOUD_SDK_ROOT = py.path.local.mkdtemp() |
| 66 | |
| 67 | # The full path the cloud sdk install directory |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 68 | CLOUD_SDK_INSTALL_DIR = CLOUD_SDK_ROOT.join("google-cloud-sdk") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 69 | |
| 70 | # The full path to the gcloud cli executable. |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 71 | GCLOUD = str(CLOUD_SDK_INSTALL_DIR.join("bin", "gcloud")) |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 72 | |
| 73 | # gcloud requires Python 2 and doesn't work on 3, so we need to tell it |
| 74 | # where to find 2 when we're running in a 3 environment. |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 75 | CLOUD_SDK_PYTHON_ENV = "CLOUDSDK_PYTHON" |
| 76 | CLOUD_SDK_PYTHON = which("python2", None) |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 77 | |
| 78 | # Cloud SDK helpers |
| 79 | |
| 80 | |
| 81 | def install_cloud_sdk(session): |
| 82 | """Downloads and installs the Google Cloud SDK.""" |
| 83 | # Configure environment variables needed by the SDK. |
| 84 | # This sets the config root to the tests' config root. This prevents |
| 85 | # our tests from clobbering a developer's configuration when running |
| 86 | # these tests locally. |
| 87 | session.env[CLOUD_SDK_CONFIG_ENV] = str(CLOUD_SDK_ROOT) |
| 88 | # This tells gcloud which Python interpreter to use (always use 2.7) |
| 89 | session.env[CLOUD_SDK_PYTHON_ENV] = CLOUD_SDK_PYTHON |
Jon Wayne Parrott | 0c09c73 | 2017-03-24 12:10:44 -0700 | [diff] [blame] | 90 | # This set the $PATH for the subprocesses so they can find the gcloud |
| 91 | # executable. |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 92 | session.env["PATH"] = ( |
| 93 | str(CLOUD_SDK_INSTALL_DIR.join("bin")) + os.pathsep + os.environ["PATH"] |
| 94 | ) |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 95 | |
Jon Wayne Parrott | 8716141 | 2017-03-01 09:28:15 -0800 | [diff] [blame] | 96 | # If gcloud cli executable already exists, just update it. |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 97 | if py.path.local(GCLOUD).exists(): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 98 | session.run(GCLOUD, "components", "update", "-q") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 99 | return |
| 100 | |
| 101 | tar_path = CLOUD_SDK_ROOT.join(CLOUD_SDK_DIST_FILENAME) |
| 102 | |
| 103 | # Download the release. |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 104 | session.run("wget", CLOUD_SDK_DOWNLOAD_URL, "-O", str(tar_path), silent=True) |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 105 | |
| 106 | # Extract the release. |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 107 | session.run("tar", "xzf", str(tar_path), "-C", str(CLOUD_SDK_ROOT)) |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 108 | session.run(tar_path.remove) |
| 109 | |
| 110 | # Run the install script. |
| 111 | session.run( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 112 | str(CLOUD_SDK_INSTALL_DIR.join("install.sh")), |
| 113 | "--usage-reporting", |
| 114 | "false", |
| 115 | "--path-update", |
| 116 | "false", |
| 117 | "--command-completion", |
| 118 | "false", |
| 119 | silent=True, |
| 120 | ) |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 121 | |
| 122 | |
| 123 | def copy_credentials(credentials_path): |
| 124 | """Copies credentials into the SDK root as the application default |
| 125 | credentials.""" |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 126 | dest = CLOUD_SDK_ROOT.join("application_default_credentials.json") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 127 | if dest.exists(): |
| 128 | dest.remove() |
| 129 | py.path.local(credentials_path).copy(dest) |
| 130 | |
| 131 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 132 | def configure_cloud_sdk(session, application_default_credentials, project=False): |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 133 | """Installs and configures the Cloud SDK with the given application default |
| 134 | credentials. |
| 135 | |
| 136 | If project is True, then a project will be set in the active config. |
| 137 | If it is false, this will ensure no project is set. |
| 138 | """ |
| 139 | install_cloud_sdk(session) |
| 140 | |
Jon Wayne Parrott | 0c09c73 | 2017-03-24 12:10:44 -0700 | [diff] [blame] | 141 | # Setup the service account as the default user account. This is |
| 142 | # needed for the project ID detection to work. Note that this doesn't |
| 143 | # change the application default credentials file, which is user |
| 144 | # credentials instead of service account credentials sometimes. |
| 145 | session.run( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 146 | GCLOUD, "auth", "activate-service-account", "--key-file", SERVICE_ACCOUNT_FILE |
| 147 | ) |
Jon Wayne Parrott | 0c09c73 | 2017-03-24 12:10:44 -0700 | [diff] [blame] | 148 | |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 149 | if project: |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 150 | session.run(GCLOUD, "config", "set", "project", "example-project") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 151 | else: |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 152 | session.run(GCLOUD, "config", "unset", "project") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 153 | |
| 154 | # Copy the credentials file to the config root. This is needed because |
| 155 | # unfortunately gcloud doesn't provide a clean way to tell it to use |
| 156 | # a particular set of credentials. However, this does verify that gcloud |
| 157 | # also considers the credentials valid by calling application-default |
| 158 | # print-access-token |
| 159 | session.run(copy_credentials, application_default_credentials) |
| 160 | |
| 161 | # Calling this forces the Cloud SDK to read the credentials we just wrote |
| 162 | # and obtain a new access token with those credentials. This validates |
| 163 | # that our credentials matches the format expected by gcloud. |
| 164 | # Silent is set to True to prevent leaking secrets in test logs. |
| 165 | session.run( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 166 | GCLOUD, "auth", "application-default", "print-access-token", silent=True |
| 167 | ) |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 168 | |
| 169 | |
| 170 | # Test sesssions |
| 171 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 172 | TEST_DEPENDENCIES = ["pytest", "requests"] |
| 173 | PYTHON_VERSIONS=['2.7', '3.7'] |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 174 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 175 | @nox.session(python=PYTHON_VERSIONS) |
| 176 | def service_account(session): |
| 177 | session.install(*TEST_DEPENDENCIES) |
| 178 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 179 | session.run("pytest", "test_service_account.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 180 | |
| 181 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 182 | @nox.session(python=PYTHON_VERSIONS) |
| 183 | def oauth2_credentials(session): |
| 184 | session.install(*TEST_DEPENDENCIES) |
| 185 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 186 | session.run("pytest", "test_oauth2_credentials.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 187 | |
| 188 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 189 | @nox.session(python=PYTHON_VERSIONS) |
| 190 | def default_explicit_service_account(session): |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 191 | session.env[EXPLICIT_CREDENTIALS_ENV] = SERVICE_ACCOUNT_FILE |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 192 | session.env[EXPECT_PROJECT_ENV] = "1" |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 193 | session.install(*TEST_DEPENDENCIES) |
| 194 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 195 | session.run("pytest", "test_default.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 196 | |
| 197 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 198 | @nox.session(python=PYTHON_VERSIONS) |
| 199 | def default_explicit_authorized_user(session): |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 200 | session.env[EXPLICIT_CREDENTIALS_ENV] = AUTHORIZED_USER_FILE |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 201 | session.install(*TEST_DEPENDENCIES) |
| 202 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 203 | session.run("pytest", "test_default.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 204 | |
| 205 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 206 | @nox.session(python=PYTHON_VERSIONS) |
| 207 | def default_explicit_authorized_user_explicit_project(session): |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 208 | session.env[EXPLICIT_CREDENTIALS_ENV] = AUTHORIZED_USER_FILE |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 209 | session.env[EXPLICIT_PROJECT_ENV] = "example-project" |
| 210 | session.env[EXPECT_PROJECT_ENV] = "1" |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 211 | session.install(*TEST_DEPENDENCIES) |
| 212 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 213 | session.run("pytest", "test_default.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 214 | |
| 215 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 216 | @nox.session(python=PYTHON_VERSIONS) |
| 217 | def default_cloud_sdk_service_account(session): |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 218 | configure_cloud_sdk(session, SERVICE_ACCOUNT_FILE) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 219 | session.env[EXPECT_PROJECT_ENV] = "1" |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 220 | session.install(*TEST_DEPENDENCIES) |
| 221 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 222 | session.run("pytest", "test_default.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 223 | |
| 224 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 225 | @nox.session(python=PYTHON_VERSIONS) |
| 226 | def default_cloud_sdk_authorized_user(session): |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 227 | configure_cloud_sdk(session, AUTHORIZED_USER_FILE) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 228 | session.install(*TEST_DEPENDENCIES) |
| 229 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 230 | session.run("pytest", "test_default.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 231 | |
| 232 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 233 | @nox.session(python=PYTHON_VERSIONS) |
| 234 | def default_cloud_sdk_authorized_user_configured_project(session): |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 235 | configure_cloud_sdk(session, AUTHORIZED_USER_FILE, project=True) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 236 | session.env[EXPECT_PROJECT_ENV] = "1" |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 237 | session.install(*TEST_DEPENDENCIES) |
| 238 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 239 | session.run("pytest", "test_default.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 240 | |
| 241 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 242 | @nox.session(python=PYTHON_VERSIONS) |
| 243 | def compute_engine(session): |
| 244 | session.install(*TEST_DEPENDENCIES) |
| 245 | # unset Application Default Credentials so |
| 246 | # credentials are detected from environment |
| 247 | del session.virtualenv.env["GOOGLE_APPLICATION_CREDENTIALS"] |
| 248 | session.install(LIBRARY_DIR) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 249 | session.run("pytest", "test_compute_engine.py") |
Jon Wayne Parrott | bbc3943 | 2016-10-27 23:12:39 -0700 | [diff] [blame] | 250 | |
| 251 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 252 | @nox.session(python=["2.7"]) |
| 253 | def app_engine(session): |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 254 | if SKIP_GAE_TEST_ENV in os.environ: |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 255 | session.log("Skipping App Engine tests.") |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 256 | return |
| 257 | |
| 258 | # Unlike the default tests above, the App Engine system test require a |
| 259 | # 'real' gcloud sdk installation that is configured to deploy to an |
| 260 | # app engine project. |
| 261 | # Grab the project ID from the cloud sdk. |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 262 | project_id = ( |
| 263 | subprocess.check_output( |
| 264 | ["gcloud", "config", "list", "project", "--format", "value(core.project)"] |
| 265 | ) |
| 266 | .decode("utf-8") |
| 267 | .strip() |
| 268 | ) |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 269 | |
| 270 | if not project_id: |
| 271 | session.error( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 272 | "The Cloud SDK must be installed and configured to deploy to App " "Engine." |
| 273 | ) |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 274 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 275 | application_url = GAE_APP_URL_TMPL.format(GAE_TEST_APP_SERVICE, project_id) |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 276 | |
| 277 | # Vendor in the test application's dependencies |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 278 | session.chdir(os.path.join(HERE, "app_engine_test_app")) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 279 | session.install(*TEST_DEPENDENCIES) |
| 280 | session.install(LIBRARY_DIR) |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 281 | session.run( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 282 | "pip", "install", "--target", "lib", "-r", "requirements.txt", silent=True |
| 283 | ) |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 284 | |
| 285 | # Deploy the application. |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 286 | session.run("gcloud", "app", "deploy", "-q", "app.yaml") |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 287 | |
| 288 | # Run the tests |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 289 | session.env["TEST_APP_URL"] = application_url |
Jon Wayne Parrott | b551ef2 | 2016-10-28 12:35:15 -0700 | [diff] [blame] | 290 | session.chdir(HERE) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 291 | session.run("pytest", "test_app_engine.py") |
Jon Wayne Parrott | b9897dc | 2016-11-02 20:31:14 -0700 | [diff] [blame] | 292 | |
| 293 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame^] | 294 | @nox.session(python=PYTHON_VERSIONS) |
| 295 | def grpc(session): |
| 296 | session.install(LIBRARY_DIR) |
| 297 | session.install(*TEST_DEPENDENCIES, "google-cloud-pubsub==1.0.0") |
Jon Wayne Parrott | b9897dc | 2016-11-02 20:31:14 -0700 | [diff] [blame] | 298 | session.env[EXPLICIT_CREDENTIALS_ENV] = SERVICE_ACCOUNT_FILE |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 299 | session.run("pytest", "test_grpc.py") |