Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.
Closed
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
20 changes: 14 additions & 6 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

set -eo pipefail

CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}")

if [[ -z "${PROJECT_ROOT:-}" ]]; then
PROJECT_ROOT="github/python-test-utils"
PROJECT_ROOT=$(realpath "${CURRENT_DIR}/..")
fi

cd "${PROJECT_ROOT}"
pushd "${PROJECT_ROOT}"

# Disable buffering, so that the logs stream through.
export PYTHONUNBUFFERED=1
Expand All @@ -28,10 +30,16 @@ export PYTHONUNBUFFERED=1
env | grep KOKORO

# Setup service account credentials.
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json
if [[ -f "${KOKORO_GFILE_DIR}/service-account.json" ]]
then
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json
fi

# Setup project id.
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
if [[ -f "${KOKORO_GFILE_DIR}/project-id.json" ]]
then
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
fi

# If this is a continuous build, send the test log to the FlakyBot.
# See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot.
Expand All @@ -46,7 +54,7 @@ fi
# If NOX_SESSION is set, it only runs the specified session,
# otherwise run all the sessions.
if [[ -n "${NOX_SESSION:-}" ]]; then
python3 -m nox -s ${NOX_SESSION:-}
python3 -m nox -s ${NOX_SESSION:-}
else
python3 -m nox
python3 -m nox
fi
21 changes: 1 addition & 20 deletions .kokoro/presubmit/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@
# Build logs will be here
action {
define_artifacts {
regex: "**/*sponge_log.xml"
regex: "github/python-test-utils/logs/*sponge_log.xml"
}
}

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Download resources for system tests (service account key, etc.)
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Use the trampoline script to run in docker.
build_file: "python-test-utils/.kokoro/trampoline.sh"

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/python-multi"
}
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-test-utils/.kokoro/build.sh"
}
14 changes: 14 additions & 0 deletions .kokoro/presubmit/presubmit-instance.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# proto-file: //devtools/kokoro/config/proto/build.proto
# proto-message: BuildConfig

container_properties {
docker_image: "us-central1-docker.pkg.dev/chingor-test/testing-images/python-multi@sha256:c6e49e2dabfb0a892f30fea57045575860f8804d8c838505341bb8e92f443705"
}

build_file: "python-test-utils/.kokoro/build.sh"

# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
value: "integration"
}
22 changes: 21 additions & 1 deletion .kokoro/presubmit/presubmit.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# Format: //devtools/kokoro/config/proto/build.proto
# proto-file: //devtools/kokoro/config/proto/build.proto
# proto-message: BuildConfig

# Download trampoline resources.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Download resources for system tests (service account key, etc.)
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"

# Use the trampoline script to run in docker.
build_file: "python-test-utils/.kokoro/trampoline.sh"

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/python-multi"
}
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-test-utils/.kokoro/build.sh"
}
34 changes: 32 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def mypy(session):
session.install(
"mypy",
"types-mock",
"types-requests",
"types-setuptools",
)
session.run("mypy", "test_utils/", "tests/")
Expand All @@ -99,15 +100,15 @@ def unit(session):
session.install(
"-e", "tests/unit/resources/good_package", "tests/unit/resources/bad_package"
)

session.install("google-auth")
session.install("pytest", "pytest-cov")
session.install("-e", ".", "-c", constraints_path)

# Run py.test against the unit tests.
session.run(
"py.test",
"--quiet",
f"--junitxml=unit_{session.python}_sponge_log.xml",
f"--junitxml=logs/unit_{session.python}_sponge_log.xml",
"--cov=test_utils",
"--cov=tests/unit",
"--cov-append",
Expand All @@ -118,6 +119,35 @@ def unit(session):
*session.posargs,
)

@nox.session(python=["3.11"])
def integration(session):
constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)

# Install two fake packages for the lower-bound-checker tests
session.install(
"-e", "tests/unit/resources/good_package", "tests/unit/resources/bad_package"
)
session.install("google-auth")
session.install("pytest", "pytest-cov")
session.install("-e", ".", "-c", constraints_path)

# Run py.test against the unit tests.
session.run(
"py.test",
"--quiet",
f"--junitxml=logs/unit_{session.python}_sponge_log.xml",
"--cov=test_utils",
"--cov=tests/integration",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=0",
os.path.join("tests", "integration"),
*session.posargs,
)


@nox.session(python="3.8")
def check_lower_bounds(session):
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/test_iam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2021 Google LLC
#
# 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 pytest # type: ignore

import google.auth
import requests
import google.auth.transport.requests


def test_iam():
credentials, project_id = google.auth.default()
request = google.auth.transport.requests.Request()
credentials.refresh(request)
token = credentials.token
resp = requests.post(f"https://oauth2.googleapis.com/tokeninfo", data={
'access_token': token
}, headers={
'content-type': 'application/x-www-form-urlencoded'
})
data = resp.json()
assert 'email' in data
assert data['email'] is not None
Loading