From 486af2637cb80780105ed912d44f204a9d886b7f Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 29 Dec 2020 09:30:00 -0800 Subject: [PATCH] feat: add ListAccountSummaries (#20) --- packages/google-analytics-admin/.flake8 | 1 + .../.github/snippet-bot.yml | 0 packages/google-analytics-admin/.gitignore | 3 +- .../google-analytics-admin/.kokoro/build.sh | 8 +- .../.kokoro/docker/docs/Dockerfile | 98 + .../.kokoro/docker/docs/fetch_gpg_keys.sh | 45 + .../.kokoro/docs/common.cfg | 21 +- .../.kokoro/docs/docs-presubmit.cfg | 17 + .../.kokoro/populate-secrets.sh | 43 + .../.kokoro/publish-docs.sh | 39 +- .../.kokoro/release/common.cfg | 50 +- .../.kokoro/samples/python3.6/common.cfg | 6 + .../.kokoro/samples/python3.7/common.cfg | 6 + .../.kokoro/samples/python3.8/common.cfg | 6 + .../.kokoro/test-samples.sh | 8 +- .../.kokoro/trampoline.sh | 15 +- .../.kokoro/trampoline_v2.sh | 487 +++ .../.pre-commit-config.yaml | 17 + packages/google-analytics-admin/.trampolinerc | 51 + .../google-analytics-admin/CODE_OF_CONDUCT.md | 123 +- .../google-analytics-admin/CONTRIBUTING.rst | 40 +- .../docs/admin_v1alpha/types.rst | 1 + packages/google-analytics-admin/docs/conf.py | 21 +- .../google/analytics/admin/__init__.py | 12 + .../analytics/admin_v1alpha/__init__.py | 8 + .../analytics_admin_service/async_client.py | 441 ++- .../analytics_admin_service/client.py | 1429 ++++--- .../analytics_admin_service/pagers.py | 130 + .../transports/__init__.py | 1 - .../transports/base.py | 243 +- .../transports/grpc.py | 140 +- .../transports/grpc_asyncio.py | 127 +- .../analytics/admin_v1alpha/types/__init__.py | 13 +- .../admin_v1alpha/types/analytics_admin.py | 100 +- .../admin_v1alpha/types/resources.py | 92 +- packages/google-analytics-admin/noxfile.py | 50 +- .../scripts/decrypt-secrets.sh | 15 +- .../scripts/fixup_admin_v1alpha_keywords.py | 4 +- packages/google-analytics-admin/setup.py | 6 +- .../google-analytics-admin/synth.metadata | 104 +- .../unit/gapic/admin_v1alpha/__init__.py | 1 + .../test_analytics_admin_service.py | 3295 +++++++++++------ 42 files changed, 5268 insertions(+), 2049 deletions(-) create mode 100644 packages/google-analytics-admin/.github/snippet-bot.yml create mode 100644 packages/google-analytics-admin/.kokoro/docker/docs/Dockerfile create mode 100755 packages/google-analytics-admin/.kokoro/docker/docs/fetch_gpg_keys.sh create mode 100644 packages/google-analytics-admin/.kokoro/docs/docs-presubmit.cfg create mode 100755 packages/google-analytics-admin/.kokoro/populate-secrets.sh create mode 100755 packages/google-analytics-admin/.kokoro/trampoline_v2.sh create mode 100644 packages/google-analytics-admin/.pre-commit-config.yaml create mode 100644 packages/google-analytics-admin/.trampolinerc create mode 100644 packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/__init__.py diff --git a/packages/google-analytics-admin/.flake8 b/packages/google-analytics-admin/.flake8 index ed9316381c9c..29227d4cf419 100644 --- a/packages/google-analytics-admin/.flake8 +++ b/packages/google-analytics-admin/.flake8 @@ -26,6 +26,7 @@ exclude = *_pb2.py # Standard linting exemptions. + **/.nox/** __pycache__, .git, *.pyc, diff --git a/packages/google-analytics-admin/.github/snippet-bot.yml b/packages/google-analytics-admin/.github/snippet-bot.yml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/google-analytics-admin/.gitignore b/packages/google-analytics-admin/.gitignore index b87e1ed580d9..b9daa52f118d 100644 --- a/packages/google-analytics-admin/.gitignore +++ b/packages/google-analytics-admin/.gitignore @@ -46,6 +46,7 @@ pip-log.txt # Built documentation docs/_build bigquery/docs/generated +docs.metadata # Virtual environment env/ @@ -57,4 +58,4 @@ system_tests/local_test_setup # Make sure a generated file isn't accidentally committed. pylintrc -pylintrc.test \ No newline at end of file +pylintrc.test diff --git a/packages/google-analytics-admin/.kokoro/build.sh b/packages/google-analytics-admin/.kokoro/build.sh index 5943779976ef..831e0ab037a3 100755 --- a/packages/google-analytics-admin/.kokoro/build.sh +++ b/packages/google-analytics-admin/.kokoro/build.sh @@ -36,4 +36,10 @@ python3.6 -m pip uninstall --yes --quiet nox-automation python3.6 -m pip install --upgrade --quiet nox python3.6 -m nox --version -python3.6 -m nox +# If NOX_SESSION is set, it only runs the specified session, +# otherwise run all the sessions. +if [[ -n "${NOX_SESSION:-}" ]]; then + python3.6 -m nox -s "${NOX_SESSION:-}" +else + python3.6 -m nox +fi diff --git a/packages/google-analytics-admin/.kokoro/docker/docs/Dockerfile b/packages/google-analytics-admin/.kokoro/docker/docs/Dockerfile new file mode 100644 index 000000000000..412b0b56a921 --- /dev/null +++ b/packages/google-analytics-admin/.kokoro/docker/docs/Dockerfile @@ -0,0 +1,98 @@ +# Copyright 2020 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. + +from ubuntu:20.04 + +ENV DEBIAN_FRONTEND noninteractive + +# Ensure local Python is preferred over distribution Python. +ENV PATH /usr/local/bin:$PATH + +# Install dependencies. +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-transport-https \ + build-essential \ + ca-certificates \ + curl \ + dirmngr \ + git \ + gpg-agent \ + graphviz \ + libbz2-dev \ + libdb5.3-dev \ + libexpat1-dev \ + libffi-dev \ + liblzma-dev \ + libreadline-dev \ + libsnappy-dev \ + libssl-dev \ + libsqlite3-dev \ + portaudio19-dev \ + redis-server \ + software-properties-common \ + ssh \ + sudo \ + tcl \ + tcl-dev \ + tk \ + tk-dev \ + uuid-dev \ + wget \ + zlib1g-dev \ + && add-apt-repository universe \ + && apt-get update \ + && apt-get -y install jq \ + && apt-get clean autoclean \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && rm -f /var/cache/apt/archives/*.deb + + +COPY fetch_gpg_keys.sh /tmp +# Install the desired versions of Python. +RUN set -ex \ + && export GNUPGHOME="$(mktemp -d)" \ + && echo "disable-ipv6" >> "${GNUPGHOME}/dirmngr.conf" \ + && /tmp/fetch_gpg_keys.sh \ + && for PYTHON_VERSION in 3.7.8 3.8.5; do \ + wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ + && wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ + && gpg --batch --verify python-${PYTHON_VERSION}.tar.xz.asc python-${PYTHON_VERSION}.tar.xz \ + && rm -r python-${PYTHON_VERSION}.tar.xz.asc \ + && mkdir -p /usr/src/python-${PYTHON_VERSION} \ + && tar -xJC /usr/src/python-${PYTHON_VERSION} --strip-components=1 -f python-${PYTHON_VERSION}.tar.xz \ + && rm python-${PYTHON_VERSION}.tar.xz \ + && cd /usr/src/python-${PYTHON_VERSION} \ + && ./configure \ + --enable-shared \ + # This works only on Python 2.7 and throws a warning on every other + # version, but seems otherwise harmless. + --enable-unicode=ucs4 \ + --with-system-ffi \ + --without-ensurepip \ + && make -j$(nproc) \ + && make install \ + && ldconfig \ + ; done \ + && rm -rf "${GNUPGHOME}" \ + && rm -rf /usr/src/python* \ + && rm -rf ~/.cache/ + +RUN wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ + && python3.7 /tmp/get-pip.py \ + && python3.8 /tmp/get-pip.py \ + && rm /tmp/get-pip.py + +CMD ["python3.7"] diff --git a/packages/google-analytics-admin/.kokoro/docker/docs/fetch_gpg_keys.sh b/packages/google-analytics-admin/.kokoro/docker/docs/fetch_gpg_keys.sh new file mode 100755 index 000000000000..d653dd868e4b --- /dev/null +++ b/packages/google-analytics-admin/.kokoro/docker/docs/fetch_gpg_keys.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Copyright 2020 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. + +# A script to fetch gpg keys with retry. +# Avoid jinja parsing the file. +# + +function retry { + if [[ "${#}" -le 1 ]]; then + echo "Usage: ${0} retry_count commands.." + exit 1 + fi + local retries=${1} + local command="${@:2}" + until [[ "${retries}" -le 0 ]]; do + $command && return 0 + if [[ $? -ne 0 ]]; then + echo "command failed, retrying" + ((retries--)) + fi + done + return 1 +} + +# 3.6.9, 3.7.5 (Ned Deily) +retry 3 gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \ + 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D + +# 3.8.0 (Łukasz Langa) +retry 3 gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \ + E3FF2839C048B25C084DEBE9B26995E310250568 + +# diff --git a/packages/google-analytics-admin/.kokoro/docs/common.cfg b/packages/google-analytics-admin/.kokoro/docs/common.cfg index fa28871123ac..ce443c130ab8 100644 --- a/packages/google-analytics-admin/.kokoro/docs/common.cfg +++ b/packages/google-analytics-admin/.kokoro/docs/common.cfg @@ -11,12 +11,12 @@ action { gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "python-analytics-admin/.kokoro/trampoline.sh" +build_file: "python-analytics-admin/.kokoro/trampoline_v2.sh" # Configure the docker image for kokoro-trampoline. env_vars: { key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/python-multi" + value: "gcr.io/cloud-devrel-kokoro-resources/python-lib-docs" } env_vars: { key: "TRAMPOLINE_BUILD_FILE" @@ -28,6 +28,23 @@ env_vars: { value: "docs-staging" } +env_vars: { + key: "V2_STAGING_BUCKET" + value: "docs-staging-v2" +} + +# It will upload the docker image after successful builds. +env_vars: { + key: "TRAMPOLINE_IMAGE_UPLOAD" + value: "true" +} + +# It will always build the docker image. +env_vars: { + key: "TRAMPOLINE_DOCKERFILE" + value: ".kokoro/docker/docs/Dockerfile" +} + # Fetch the token needed for reporting release status to GitHub before_action { fetch_keystore { diff --git a/packages/google-analytics-admin/.kokoro/docs/docs-presubmit.cfg b/packages/google-analytics-admin/.kokoro/docs/docs-presubmit.cfg new file mode 100644 index 000000000000..1118107829b7 --- /dev/null +++ b/packages/google-analytics-admin/.kokoro/docs/docs-presubmit.cfg @@ -0,0 +1,17 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "STAGING_BUCKET" + value: "gcloud-python-test" +} + +env_vars: { + key: "V2_STAGING_BUCKET" + value: "gcloud-python-test" +} + +# We only upload the image in the main `docs` build. +env_vars: { + key: "TRAMPOLINE_IMAGE_UPLOAD" + value: "false" +} diff --git a/packages/google-analytics-admin/.kokoro/populate-secrets.sh b/packages/google-analytics-admin/.kokoro/populate-secrets.sh new file mode 100755 index 000000000000..f52514257ef0 --- /dev/null +++ b/packages/google-analytics-admin/.kokoro/populate-secrets.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Copyright 2020 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. + +set -eo pipefail + +function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;} +function msg { println "$*" >&2 ;} +function println { printf '%s\n' "$(now) $*" ;} + + +# Populates requested secrets set in SECRET_MANAGER_KEYS from service account: +# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com +SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager" +msg "Creating folder on disk for secrets: ${SECRET_LOCATION}" +mkdir -p ${SECRET_LOCATION} +for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g") +do + msg "Retrieving secret ${key}" + docker run --entrypoint=gcloud \ + --volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \ + gcr.io/google.com/cloudsdktool/cloud-sdk \ + secrets versions access latest \ + --project cloud-devrel-kokoro-resources \ + --secret ${key} > \ + "${SECRET_LOCATION}/${key}" + if [[ $? == 0 ]]; then + msg "Secret written to ${SECRET_LOCATION}/${key}" + else + msg "Error retrieving secret ${key}" + fi +done diff --git a/packages/google-analytics-admin/.kokoro/publish-docs.sh b/packages/google-analytics-admin/.kokoro/publish-docs.sh index f5a4968af6b8..8acb14e802b0 100755 --- a/packages/google-analytics-admin/.kokoro/publish-docs.sh +++ b/packages/google-analytics-admin/.kokoro/publish-docs.sh @@ -18,26 +18,16 @@ set -eo pipefail # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 -cd github/python-analytics-admin - -# Remove old nox -python3.6 -m pip uninstall --yes --quiet nox-automation +export PATH="${HOME}/.local/bin:${PATH}" # Install nox -python3.6 -m pip install --upgrade --quiet nox -python3.6 -m nox --version +python3 -m pip install --user --upgrade --quiet nox +python3 -m nox --version # build docs nox -s docs -python3 -m pip install gcp-docuploader - -# install a json parser -sudo apt-get update -sudo apt-get -y install software-properties-common -sudo add-apt-repository universe -sudo apt-get update -sudo apt-get -y install jq +python3 -m pip install --user gcp-docuploader # create metadata python3 -m docuploader create-metadata \ @@ -52,4 +42,23 @@ python3 -m docuploader create-metadata \ cat docs.metadata # upload docs -python3 -m docuploader upload docs/_build/html --metadata-file docs.metadata --staging-bucket docs-staging +python3 -m docuploader upload docs/_build/html --metadata-file docs.metadata --staging-bucket "${STAGING_BUCKET}" + + +# docfx yaml files +nox -s docfx + +# create metadata. +python3 -m docuploader create-metadata \ + --name=$(jq --raw-output '.name // empty' .repo-metadata.json) \ + --version=$(python3 setup.py --version) \ + --language=$(jq --raw-output '.language // empty' .repo-metadata.json) \ + --distribution-name=$(python3 setup.py --name) \ + --product-page=$(jq --raw-output '.product_documentation // empty' .repo-metadata.json) \ + --github-repository=$(jq --raw-output '.repo // empty' .repo-metadata.json) \ + --issue-tracker=$(jq --raw-output '.issue_tracker // empty' .repo-metadata.json) + +cat docs.metadata + +# upload docs +python3 -m docuploader upload docs/_build/html/docfx_yaml --metadata-file docs.metadata --destination-prefix docfx --staging-bucket "${V2_STAGING_BUCKET}" diff --git a/packages/google-analytics-admin/.kokoro/release/common.cfg b/packages/google-analytics-admin/.kokoro/release/common.cfg index bed189e2a4a5..0ed8b652195a 100644 --- a/packages/google-analytics-admin/.kokoro/release/common.cfg +++ b/packages/google-analytics-admin/.kokoro/release/common.cfg @@ -23,42 +23,18 @@ env_vars: { value: "github/python-analytics-admin/.kokoro/release.sh" } -# Fetch the token needed for reporting release status to GitHub -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "yoshi-automation-github-key" - } - } -} - -# Fetch PyPI password -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "google_cloud_pypi_password" - } - } -} - -# Fetch magictoken to use with Magic Github Proxy -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "releasetool-magictoken" - } - } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google_cloud_pypi_password" + } + } } -# Fetch api key to use with Magic Github Proxy -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "magic-github-proxy-api-key" - } - } -} +# Tokens needed to report release status back to GitHub +env_vars: { + key: "SECRET_MANAGER_KEYS" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" +} \ No newline at end of file diff --git a/packages/google-analytics-admin/.kokoro/samples/python3.6/common.cfg b/packages/google-analytics-admin/.kokoro/samples/python3.6/common.cfg index b79e165b062d..b7fccdac18de 100644 --- a/packages/google-analytics-admin/.kokoro/samples/python3.6/common.cfg +++ b/packages/google-analytics-admin/.kokoro/samples/python3.6/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.6" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py36" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-analytics-admin/.kokoro/test-samples.sh" diff --git a/packages/google-analytics-admin/.kokoro/samples/python3.7/common.cfg b/packages/google-analytics-admin/.kokoro/samples/python3.7/common.cfg index 46f8d81d806c..d91f9c3655a4 100644 --- a/packages/google-analytics-admin/.kokoro/samples/python3.7/common.cfg +++ b/packages/google-analytics-admin/.kokoro/samples/python3.7/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.7" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py37" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-analytics-admin/.kokoro/test-samples.sh" diff --git a/packages/google-analytics-admin/.kokoro/samples/python3.8/common.cfg b/packages/google-analytics-admin/.kokoro/samples/python3.8/common.cfg index 0668aa73a34f..9cb150e59803 100644 --- a/packages/google-analytics-admin/.kokoro/samples/python3.8/common.cfg +++ b/packages/google-analytics-admin/.kokoro/samples/python3.8/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.8" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py38" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-analytics-admin/.kokoro/test-samples.sh" diff --git a/packages/google-analytics-admin/.kokoro/test-samples.sh b/packages/google-analytics-admin/.kokoro/test-samples.sh index 68553d6ccbe4..897f35a7f7e3 100755 --- a/packages/google-analytics-admin/.kokoro/test-samples.sh +++ b/packages/google-analytics-admin/.kokoro/test-samples.sh @@ -28,6 +28,12 @@ if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then git checkout $LATEST_RELEASE fi +# Exit early if samples directory doesn't exist +if [ ! -d "./samples" ]; then + echo "No tests run. `./samples` not found" + exit 0 +fi + # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 @@ -101,4 +107,4 @@ cd "$ROOT" # Workaround for Kokoro permissions issue: delete secrets rm testing/{test-env.sh,client-secrets.json,service-account.json} -exit "$RTN" \ No newline at end of file +exit "$RTN" diff --git a/packages/google-analytics-admin/.kokoro/trampoline.sh b/packages/google-analytics-admin/.kokoro/trampoline.sh index e8c4251f3ed4..f39236e943a8 100755 --- a/packages/google-analytics-admin/.kokoro/trampoline.sh +++ b/packages/google-analytics-admin/.kokoro/trampoline.sh @@ -15,9 +15,14 @@ set -eo pipefail -python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" || ret_code=$? +# Always run the cleanup script, regardless of the success of bouncing into +# the container. +function cleanup() { + chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh + ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh + echo "cleanup"; +} +trap cleanup EXIT -chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh -${KOKORO_GFILE_DIR}/trampoline_cleanup.sh || true - -exit ${ret_code} +$(dirname $0)/populate-secrets.sh # Secret Manager secrets. +python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" \ No newline at end of file diff --git a/packages/google-analytics-admin/.kokoro/trampoline_v2.sh b/packages/google-analytics-admin/.kokoro/trampoline_v2.sh new file mode 100755 index 000000000000..719bcd5ba84d --- /dev/null +++ b/packages/google-analytics-admin/.kokoro/trampoline_v2.sh @@ -0,0 +1,487 @@ +#!/usr/bin/env bash +# Copyright 2020 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. + +# trampoline_v2.sh +# +# This script does 3 things. +# +# 1. Prepare the Docker image for the test +# 2. Run the Docker with appropriate flags to run the test +# 3. Upload the newly built Docker image +# +# in a way that is somewhat compatible with trampoline_v1. +# +# To run this script, first download few files from gcs to /dev/shm. +# (/dev/shm is passed into the container as KOKORO_GFILE_DIR). +# +# gsutil cp gs://cloud-devrel-kokoro-resources/python-docs-samples/secrets_viewer_service_account.json /dev/shm +# gsutil cp gs://cloud-devrel-kokoro-resources/python-docs-samples/automl_secrets.txt /dev/shm +# +# Then run the script. +# .kokoro/trampoline_v2.sh +# +# These environment variables are required: +# TRAMPOLINE_IMAGE: The docker image to use. +# TRAMPOLINE_DOCKERFILE: The location of the Dockerfile. +# +# You can optionally change these environment variables: +# TRAMPOLINE_IMAGE_UPLOAD: +# (true|false): Whether to upload the Docker image after the +# successful builds. +# TRAMPOLINE_BUILD_FILE: The script to run in the docker container. +# TRAMPOLINE_WORKSPACE: The workspace path in the docker container. +# Defaults to /workspace. +# Potentially there are some repo specific envvars in .trampolinerc in +# the project root. + + +set -euo pipefail + +TRAMPOLINE_VERSION="2.0.5" + +if command -v tput >/dev/null && [[ -n "${TERM:-}" ]]; then + readonly IO_COLOR_RED="$(tput setaf 1)" + readonly IO_COLOR_GREEN="$(tput setaf 2)" + readonly IO_COLOR_YELLOW="$(tput setaf 3)" + readonly IO_COLOR_RESET="$(tput sgr0)" +else + readonly IO_COLOR_RED="" + readonly IO_COLOR_GREEN="" + readonly IO_COLOR_YELLOW="" + readonly IO_COLOR_RESET="" +fi + +function function_exists { + [ $(LC_ALL=C type -t $1)"" == "function" ] +} + +# Logs a message using the given color. The first argument must be one +# of the IO_COLOR_* variables defined above, such as +# "${IO_COLOR_YELLOW}". The remaining arguments will be logged in the +# given color. The log message will also have an RFC-3339 timestamp +# prepended (in UTC). You can disable the color output by setting +# TERM=vt100. +function log_impl() { + local color="$1" + shift + local timestamp="$(date -u "+%Y-%m-%dT%H:%M:%SZ")" + echo "================================================================" + echo "${color}${timestamp}:" "$@" "${IO_COLOR_RESET}" + echo "================================================================" +} + +# Logs the given message with normal coloring and a timestamp. +function log() { + log_impl "${IO_COLOR_RESET}" "$@" +} + +# Logs the given message in green with a timestamp. +function log_green() { + log_impl "${IO_COLOR_GREEN}" "$@" +} + +# Logs the given message in yellow with a timestamp. +function log_yellow() { + log_impl "${IO_COLOR_YELLOW}" "$@" +} + +# Logs the given message in red with a timestamp. +function log_red() { + log_impl "${IO_COLOR_RED}" "$@" +} + +readonly tmpdir=$(mktemp -d -t ci-XXXXXXXX) +readonly tmphome="${tmpdir}/h" +mkdir -p "${tmphome}" + +function cleanup() { + rm -rf "${tmpdir}" +} +trap cleanup EXIT + +RUNNING_IN_CI="${RUNNING_IN_CI:-false}" + +# The workspace in the container, defaults to /workspace. +TRAMPOLINE_WORKSPACE="${TRAMPOLINE_WORKSPACE:-/workspace}" + +pass_down_envvars=( + # TRAMPOLINE_V2 variables. + # Tells scripts whether they are running as part of CI or not. + "RUNNING_IN_CI" + # Indicates which CI system we're in. + "TRAMPOLINE_CI" + # Indicates the version of the script. + "TRAMPOLINE_VERSION" +) + +log_yellow "Building with Trampoline ${TRAMPOLINE_VERSION}" + +# Detect which CI systems we're in. If we're in any of the CI systems +# we support, `RUNNING_IN_CI` will be true and `TRAMPOLINE_CI` will be +# the name of the CI system. Both envvars will be passing down to the +# container for telling which CI system we're in. +if [[ -n "${KOKORO_BUILD_ID:-}" ]]; then + # descriptive env var for indicating it's on CI. + RUNNING_IN_CI="true" + TRAMPOLINE_CI="kokoro" + if [[ "${TRAMPOLINE_USE_LEGACY_SERVICE_ACCOUNT:-}" == "true" ]]; then + if [[ ! -f "${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json" ]]; then + log_red "${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json does not exist. Did you forget to mount cloud-devrel-kokoro-resources/trampoline? Aborting." + exit 1 + fi + # This service account will be activated later. + TRAMPOLINE_SERVICE_ACCOUNT="${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json" + else + if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then + gcloud auth list + fi + log_yellow "Configuring Container Registry access" + gcloud auth configure-docker --quiet + fi + pass_down_envvars+=( + # KOKORO dynamic variables. + "KOKORO_BUILD_NUMBER" + "KOKORO_BUILD_ID" + "KOKORO_JOB_NAME" + "KOKORO_GIT_COMMIT" + "KOKORO_GITHUB_COMMIT" + "KOKORO_GITHUB_PULL_REQUEST_NUMBER" + "KOKORO_GITHUB_PULL_REQUEST_COMMIT" + # For Build Cop Bot + "KOKORO_GITHUB_COMMIT_URL" + "KOKORO_GITHUB_PULL_REQUEST_URL" + ) +elif [[ "${TRAVIS:-}" == "true" ]]; then + RUNNING_IN_CI="true" + TRAMPOLINE_CI="travis" + pass_down_envvars+=( + "TRAVIS_BRANCH" + "TRAVIS_BUILD_ID" + "TRAVIS_BUILD_NUMBER" + "TRAVIS_BUILD_WEB_URL" + "TRAVIS_COMMIT" + "TRAVIS_COMMIT_MESSAGE" + "TRAVIS_COMMIT_RANGE" + "TRAVIS_JOB_NAME" + "TRAVIS_JOB_NUMBER" + "TRAVIS_JOB_WEB_URL" + "TRAVIS_PULL_REQUEST" + "TRAVIS_PULL_REQUEST_BRANCH" + "TRAVIS_PULL_REQUEST_SHA" + "TRAVIS_PULL_REQUEST_SLUG" + "TRAVIS_REPO_SLUG" + "TRAVIS_SECURE_ENV_VARS" + "TRAVIS_TAG" + ) +elif [[ -n "${GITHUB_RUN_ID:-}" ]]; then + RUNNING_IN_CI="true" + TRAMPOLINE_CI="github-workflow" + pass_down_envvars+=( + "GITHUB_WORKFLOW" + "GITHUB_RUN_ID" + "GITHUB_RUN_NUMBER" + "GITHUB_ACTION" + "GITHUB_ACTIONS" + "GITHUB_ACTOR" + "GITHUB_REPOSITORY" + "GITHUB_EVENT_NAME" + "GITHUB_EVENT_PATH" + "GITHUB_SHA" + "GITHUB_REF" + "GITHUB_HEAD_REF" + "GITHUB_BASE_REF" + ) +elif [[ "${CIRCLECI:-}" == "true" ]]; then + RUNNING_IN_CI="true" + TRAMPOLINE_CI="circleci" + pass_down_envvars+=( + "CIRCLE_BRANCH" + "CIRCLE_BUILD_NUM" + "CIRCLE_BUILD_URL" + "CIRCLE_COMPARE_URL" + "CIRCLE_JOB" + "CIRCLE_NODE_INDEX" + "CIRCLE_NODE_TOTAL" + "CIRCLE_PREVIOUS_BUILD_NUM" + "CIRCLE_PROJECT_REPONAME" + "CIRCLE_PROJECT_USERNAME" + "CIRCLE_REPOSITORY_URL" + "CIRCLE_SHA1" + "CIRCLE_STAGE" + "CIRCLE_USERNAME" + "CIRCLE_WORKFLOW_ID" + "CIRCLE_WORKFLOW_JOB_ID" + "CIRCLE_WORKFLOW_UPSTREAM_JOB_IDS" + "CIRCLE_WORKFLOW_WORKSPACE_ID" + ) +fi + +# Configure the service account for pulling the docker image. +function repo_root() { + local dir="$1" + while [[ ! -d "${dir}/.git" ]]; do + dir="$(dirname "$dir")" + done + echo "${dir}" +} + +# Detect the project root. In CI builds, we assume the script is in +# the git tree and traverse from there, otherwise, traverse from `pwd` +# to find `.git` directory. +if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then + PROGRAM_PATH="$(realpath "$0")" + PROGRAM_DIR="$(dirname "${PROGRAM_PATH}")" + PROJECT_ROOT="$(repo_root "${PROGRAM_DIR}")" +else + PROJECT_ROOT="$(repo_root $(pwd))" +fi + +log_yellow "Changing to the project root: ${PROJECT_ROOT}." +cd "${PROJECT_ROOT}" + +# To support relative path for `TRAMPOLINE_SERVICE_ACCOUNT`, we need +# to use this environment variable in `PROJECT_ROOT`. +if [[ -n "${TRAMPOLINE_SERVICE_ACCOUNT:-}" ]]; then + + mkdir -p "${tmpdir}/gcloud" + gcloud_config_dir="${tmpdir}/gcloud" + + log_yellow "Using isolated gcloud config: ${gcloud_config_dir}." + export CLOUDSDK_CONFIG="${gcloud_config_dir}" + + log_yellow "Using ${TRAMPOLINE_SERVICE_ACCOUNT} for authentication." + gcloud auth activate-service-account \ + --key-file "${TRAMPOLINE_SERVICE_ACCOUNT}" + log_yellow "Configuring Container Registry access" + gcloud auth configure-docker --quiet +fi + +required_envvars=( + # The basic trampoline configurations. + "TRAMPOLINE_IMAGE" + "TRAMPOLINE_BUILD_FILE" +) + +if [[ -f "${PROJECT_ROOT}/.trampolinerc" ]]; then + source "${PROJECT_ROOT}/.trampolinerc" +fi + +log_yellow "Checking environment variables." +for e in "${required_envvars[@]}" +do + if [[ -z "${!e:-}" ]]; then + log "Missing ${e} env var. Aborting." + exit 1 + fi +done + +# We want to support legacy style TRAMPOLINE_BUILD_FILE used with V1 +# script: e.g. "github/repo-name/.kokoro/run_tests.sh" +TRAMPOLINE_BUILD_FILE="${TRAMPOLINE_BUILD_FILE#github/*/}" +log_yellow "Using TRAMPOLINE_BUILD_FILE: ${TRAMPOLINE_BUILD_FILE}" + +# ignore error on docker operations and test execution +set +e + +log_yellow "Preparing Docker image." +# We only download the docker image in CI builds. +if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then + # Download the docker image specified by `TRAMPOLINE_IMAGE` + + # We may want to add --max-concurrent-downloads flag. + + log_yellow "Start pulling the Docker image: ${TRAMPOLINE_IMAGE}." + if docker pull "${TRAMPOLINE_IMAGE}"; then + log_green "Finished pulling the Docker image: ${TRAMPOLINE_IMAGE}." + has_image="true" + else + log_red "Failed pulling the Docker image: ${TRAMPOLINE_IMAGE}." + has_image="false" + fi +else + # For local run, check if we have the image. + if docker images "${TRAMPOLINE_IMAGE}:latest" | grep "${TRAMPOLINE_IMAGE}"; then + has_image="true" + else + has_image="false" + fi +fi + + +# The default user for a Docker container has uid 0 (root). To avoid +# creating root-owned files in the build directory we tell docker to +# use the current user ID. +user_uid="$(id -u)" +user_gid="$(id -g)" +user_name="$(id -un)" + +# To allow docker in docker, we add the user to the docker group in +# the host os. +docker_gid=$(cut -d: -f3 < <(getent group docker)) + +update_cache="false" +if [[ "${TRAMPOLINE_DOCKERFILE:-none}" != "none" ]]; then + # Build the Docker image from the source. + context_dir=$(dirname "${TRAMPOLINE_DOCKERFILE}") + docker_build_flags=( + "-f" "${TRAMPOLINE_DOCKERFILE}" + "-t" "${TRAMPOLINE_IMAGE}" + "--build-arg" "UID=${user_uid}" + "--build-arg" "USERNAME=${user_name}" + ) + if [[ "${has_image}" == "true" ]]; then + docker_build_flags+=("--cache-from" "${TRAMPOLINE_IMAGE}") + fi + + log_yellow "Start building the docker image." + if [[ "${TRAMPOLINE_VERBOSE:-false}" == "true" ]]; then + echo "docker build" "${docker_build_flags[@]}" "${context_dir}" + fi + + # ON CI systems, we want to suppress docker build logs, only + # output the logs when it fails. + if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then + if docker build "${docker_build_flags[@]}" "${context_dir}" \ + > "${tmpdir}/docker_build.log" 2>&1; then + if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then + cat "${tmpdir}/docker_build.log" + fi + + log_green "Finished building the docker image." + update_cache="true" + else + log_red "Failed to build the Docker image, aborting." + log_yellow "Dumping the build logs:" + cat "${tmpdir}/docker_build.log" + exit 1 + fi + else + if docker build "${docker_build_flags[@]}" "${context_dir}"; then + log_green "Finished building the docker image." + update_cache="true" + else + log_red "Failed to build the Docker image, aborting." + exit 1 + fi + fi +else + if [[ "${has_image}" != "true" ]]; then + log_red "We do not have ${TRAMPOLINE_IMAGE} locally, aborting." + exit 1 + fi +fi + +# We use an array for the flags so they are easier to document. +docker_flags=( + # Remove the container after it exists. + "--rm" + + # Use the host network. + "--network=host" + + # Run in priviledged mode. We are not using docker for sandboxing or + # isolation, just for packaging our dev tools. + "--privileged" + + # Run the docker script with the user id. Because the docker image gets to + # write in ${PWD} you typically want this to be your user id. + # To allow docker in docker, we need to use docker gid on the host. + "--user" "${user_uid}:${docker_gid}" + + # Pass down the USER. + "--env" "USER=${user_name}" + + # Mount the project directory inside the Docker container. + "--volume" "${PROJECT_ROOT}:${TRAMPOLINE_WORKSPACE}" + "--workdir" "${TRAMPOLINE_WORKSPACE}" + "--env" "PROJECT_ROOT=${TRAMPOLINE_WORKSPACE}" + + # Mount the temporary home directory. + "--volume" "${tmphome}:/h" + "--env" "HOME=/h" + + # Allow docker in docker. + "--volume" "/var/run/docker.sock:/var/run/docker.sock" + + # Mount the /tmp so that docker in docker can mount the files + # there correctly. + "--volume" "/tmp:/tmp" + # Pass down the KOKORO_GFILE_DIR and KOKORO_KEYSTORE_DIR + # TODO(tmatsuo): This part is not portable. + "--env" "TRAMPOLINE_SECRET_DIR=/secrets" + "--volume" "${KOKORO_GFILE_DIR:-/dev/shm}:/secrets/gfile" + "--env" "KOKORO_GFILE_DIR=/secrets/gfile" + "--volume" "${KOKORO_KEYSTORE_DIR:-/dev/shm}:/secrets/keystore" + "--env" "KOKORO_KEYSTORE_DIR=/secrets/keystore" +) + +# Add an option for nicer output if the build gets a tty. +if [[ -t 0 ]]; then + docker_flags+=("-it") +fi + +# Passing down env vars +for e in "${pass_down_envvars[@]}" +do + if [[ -n "${!e:-}" ]]; then + docker_flags+=("--env" "${e}=${!e}") + fi +done + +# If arguments are given, all arguments will become the commands run +# in the container, otherwise run TRAMPOLINE_BUILD_FILE. +if [[ $# -ge 1 ]]; then + log_yellow "Running the given commands '" "${@:1}" "' in the container." + readonly commands=("${@:1}") + if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then + echo docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" "${commands[@]}" + fi + docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" "${commands[@]}" +else + log_yellow "Running the tests in a Docker container." + docker_flags+=("--entrypoint=${TRAMPOLINE_BUILD_FILE}") + if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then + echo docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" + fi + docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" +fi + + +test_retval=$? + +if [[ ${test_retval} -eq 0 ]]; then + log_green "Build finished with ${test_retval}" +else + log_red "Build finished with ${test_retval}" +fi + +# Only upload it when the test passes. +if [[ "${update_cache}" == "true" ]] && \ + [[ $test_retval == 0 ]] && \ + [[ "${TRAMPOLINE_IMAGE_UPLOAD:-false}" == "true" ]]; then + log_yellow "Uploading the Docker image." + if docker push "${TRAMPOLINE_IMAGE}"; then + log_green "Finished uploading the Docker image." + else + log_red "Failed uploading the Docker image." + fi + # Call trampoline_after_upload_hook if it's defined. + if function_exists trampoline_after_upload_hook; then + trampoline_after_upload_hook + fi + +fi + +exit "${test_retval}" diff --git a/packages/google-analytics-admin/.pre-commit-config.yaml b/packages/google-analytics-admin/.pre-commit-config.yaml new file mode 100644 index 000000000000..a9024b15d725 --- /dev/null +++ b/packages/google-analytics-admin/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml +- repo: https://github.com/psf/black + rev: 19.10b0 + hooks: + - id: black +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 diff --git a/packages/google-analytics-admin/.trampolinerc b/packages/google-analytics-admin/.trampolinerc new file mode 100644 index 000000000000..995ee29111e1 --- /dev/null +++ b/packages/google-analytics-admin/.trampolinerc @@ -0,0 +1,51 @@ +# Copyright 2020 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. + +# Template for .trampolinerc + +# Add required env vars here. +required_envvars+=( + "STAGING_BUCKET" + "V2_STAGING_BUCKET" +) + +# Add env vars which are passed down into the container here. +pass_down_envvars+=( + "STAGING_BUCKET" + "V2_STAGING_BUCKET" +) + +# Prevent unintentional override on the default image. +if [[ "${TRAMPOLINE_IMAGE_UPLOAD:-false}" == "true" ]] && \ + [[ -z "${TRAMPOLINE_IMAGE:-}" ]]; then + echo "Please set TRAMPOLINE_IMAGE if you want to upload the Docker image." + exit 1 +fi + +# Define the default value if it makes sense. +if [[ -z "${TRAMPOLINE_IMAGE_UPLOAD:-}" ]]; then + TRAMPOLINE_IMAGE_UPLOAD="" +fi + +if [[ -z "${TRAMPOLINE_IMAGE:-}" ]]; then + TRAMPOLINE_IMAGE="" +fi + +if [[ -z "${TRAMPOLINE_DOCKERFILE:-}" ]]; then + TRAMPOLINE_DOCKERFILE="" +fi + +if [[ -z "${TRAMPOLINE_BUILD_FILE:-}" ]]; then + TRAMPOLINE_BUILD_FILE="" +fi diff --git a/packages/google-analytics-admin/CODE_OF_CONDUCT.md b/packages/google-analytics-admin/CODE_OF_CONDUCT.md index b3d1f6029849..039f43681204 100644 --- a/packages/google-analytics-admin/CODE_OF_CONDUCT.md +++ b/packages/google-analytics-admin/CODE_OF_CONDUCT.md @@ -1,44 +1,95 @@ -# Contributor Code of Conduct +# Code of Conduct -As contributors and maintainers of this project, -and in the interest of fostering an open and welcoming community, -we pledge to respect all people who contribute through reporting issues, -posting feature requests, updating documentation, -submitting pull requests or patches, and other activities. +## Our Pledge -We are committed to making participation in this project -a harassment-free experience for everyone, -regardless of level of experience, gender, gender identity and expression, -sexual orientation, disability, personal appearance, -body size, race, ethnicity, age, religion, or nationality. +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery -* Personal attacks -* Trolling or insulting/derogatory comments -* Public or private harassment -* Publishing other's private information, -such as physical or electronic -addresses, without explicit permission -* Other unethical or unprofessional conduct. +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct. -By adopting this Code of Conduct, -project maintainers commit themselves to fairly and consistently -applying these principles to every aspect of managing this project. -Project maintainers who do not follow or enforce the Code of Conduct -may be permanently removed from the project team. - -This code of conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior -may be reported by opening an issue -or contacting one or more of the project maintainers. - -This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, -available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the project’s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + + +Reports should be directed to *googleapis-stewards@google.com*, the +Project Steward(s) for *Google Cloud Client Libraries*. It is the Project Steward’s duty to +receive and address reported violations of the code of conduct. They will then +work with a committee consisting of representatives from the Open Source +Programs Office and the Google Open Source Strategy team. If for any reason you +are uncomfortable reaching out to the Project Steward, please email +opensource@google.com. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file diff --git a/packages/google-analytics-admin/CONTRIBUTING.rst b/packages/google-analytics-admin/CONTRIBUTING.rst index 27b3872539af..62af07077fb3 100644 --- a/packages/google-analytics-admin/CONTRIBUTING.rst +++ b/packages/google-analytics-admin/CONTRIBUTING.rst @@ -21,8 +21,8 @@ In order to add a feature: - The feature must be documented in both the API and narrative documentation. -- The feature must work fully on the following CPython versions: 2.7, - 3.5, 3.6, 3.7 and 3.8 on both UNIX and Windows. +- The feature must work fully on the following CPython versions: + 3.6, 3.7, 3.8 and 3.9 on both UNIX and Windows. - The feature must not add unnecessary dependencies (where "unnecessary" is of course subjective, but new dependencies should @@ -80,25 +80,6 @@ We use `nox `__ to instrument our tests. .. nox: https://pypi.org/project/nox/ -Note on Editable Installs / Develop Mode -======================================== - -- As mentioned previously, using ``setuptools`` in `develop mode`_ - or a ``pip`` `editable install`_ is not possible with this - library. This is because this library uses `namespace packages`_. - For context see `Issue #2316`_ and the relevant `PyPA issue`_. - - Since ``editable`` / ``develop`` mode can't be used, packages - need to be installed directly. Hence your changes to the source - tree don't get incorporated into the **already installed** - package. - -.. _namespace packages: https://www.python.org/dev/peps/pep-0420/ -.. _Issue #2316: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2316 -.. _PyPA issue: https://github.com/pypa/packaging-problems/issues/12 -.. _develop mode: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode -.. _editable install: https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs - ***************************************** I'm getting weird errors... Can you help? ***************************************** @@ -130,6 +111,16 @@ Coding Style should point to the official ``googleapis`` checkout and the the branch should be the main branch on that remote (``master``). +- This repository contains configuration for the + `pre-commit `__ tool, which automates checking + our linters during a commit. If you have it installed on your ``$PATH``, + you can enable enforcing those checks via: + +.. code-block:: bash + + $ pre-commit install + pre-commit installed at .git/hooks/pre-commit + Exceptions to PEP8: - Many unit tests use a helper method, ``_call_fut`` ("FUT" is short for @@ -211,25 +202,24 @@ Supported Python Versions We support: -- `Python 3.5`_ - `Python 3.6`_ - `Python 3.7`_ - `Python 3.8`_ +- `Python 3.9`_ -.. _Python 3.5: https://docs.python.org/3.5/ .. _Python 3.6: https://docs.python.org/3.6/ .. _Python 3.7: https://docs.python.org/3.7/ .. _Python 3.8: https://docs.python.org/3.8/ +.. _Python 3.9: https://docs.python.org/3.9/ Supported versions can be found in our ``noxfile.py`` `config`_. .. _config: https://github.com/googleapis/python-analytics-admin/blob/master/noxfile.py -Python 2.7 support is deprecated. All code changes should maintain Python 2.7 compatibility until January 1, 2020. We also explicitly decided to support Python 3 beginning with version -3.5. Reasons for this include: +3.6. Reasons for this include: - Encouraging use of newest versions of Python 3 - Taking the lead of `prominent`_ open-source `projects`_ diff --git a/packages/google-analytics-admin/docs/admin_v1alpha/types.rst b/packages/google-analytics-admin/docs/admin_v1alpha/types.rst index b6a700a90b52..a9003712b4a9 100644 --- a/packages/google-analytics-admin/docs/admin_v1alpha/types.rst +++ b/packages/google-analytics-admin/docs/admin_v1alpha/types.rst @@ -3,3 +3,4 @@ Types for Google Analytics Admin v1alpha API .. automodule:: google.analytics.admin_v1alpha.types :members: + :show-inheritance: diff --git a/packages/google-analytics-admin/docs/conf.py b/packages/google-analytics-admin/docs/conf.py index c977cf8e1070..9054574e99ac 100644 --- a/packages/google-analytics-admin/docs/conf.py +++ b/packages/google-analytics-admin/docs/conf.py @@ -20,12 +20,16 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath("..")) +# For plugins that can not read conf.py. +# See also: https://github.com/docascode/sphinx-docfx-yaml/issues/85 +sys.path.insert(0, os.path.abspath(".")) + __version__ = "" # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "1.6.3" +needs_sphinx = "1.5.5" # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -35,6 +39,7 @@ "sphinx.ext.autosummary", "sphinx.ext.intersphinx", "sphinx.ext.coverage", + "sphinx.ext.doctest", "sphinx.ext.napoleon", "sphinx.ext.todo", "sphinx.ext.viewcode", @@ -90,7 +95,12 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ["_build"] +exclude_patterns = [ + "_build", + "samples/AUTHORING_GUIDE.md", + "samples/CONTRIBUTING.md", + "samples/snippets/README.rst", +] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -335,10 +345,11 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), + "python": ("https://python.readthedocs.org/en/latest/", None), + "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), - "grpc": ("https://grpc.io/grpc/python/", None), + "grpc": ("https://grpc.github.io/grpc/python/", None), + "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), } diff --git a/packages/google-analytics-admin/google/analytics/admin/__init__.py b/packages/google-analytics-admin/google/analytics/admin/__init__.py index ac7fa0cd4f47..2a25656a11c3 100644 --- a/packages/google-analytics-admin/google/analytics/admin/__init__.py +++ b/packages/google-analytics-admin/google/analytics/admin/__init__.py @@ -96,6 +96,12 @@ from google.analytics.admin_v1alpha.types.analytics_admin import GetPropertyRequest from google.analytics.admin_v1alpha.types.analytics_admin import GetUserLinkRequest from google.analytics.admin_v1alpha.types.analytics_admin import GetWebDataStreamRequest +from google.analytics.admin_v1alpha.types.analytics_admin import ( + ListAccountSummariesRequest, +) +from google.analytics.admin_v1alpha.types.analytics_admin import ( + ListAccountSummariesResponse, +) from google.analytics.admin_v1alpha.types.analytics_admin import ListAccountsRequest from google.analytics.admin_v1alpha.types.analytics_admin import ListAccountsResponse from google.analytics.admin_v1alpha.types.analytics_admin import ( @@ -160,6 +166,7 @@ UpdateWebDataStreamRequest, ) from google.analytics.admin_v1alpha.types.resources import Account +from google.analytics.admin_v1alpha.types.resources import AccountSummary from google.analytics.admin_v1alpha.types.resources import AndroidAppDataStream from google.analytics.admin_v1alpha.types.resources import AuditUserLink from google.analytics.admin_v1alpha.types.resources import DataSharingSettings @@ -171,11 +178,13 @@ from google.analytics.admin_v1alpha.types.resources import IosAppDataStream from google.analytics.admin_v1alpha.types.resources import MaximumUserAccess from google.analytics.admin_v1alpha.types.resources import Property +from google.analytics.admin_v1alpha.types.resources import PropertySummary from google.analytics.admin_v1alpha.types.resources import UserLink from google.analytics.admin_v1alpha.types.resources import WebDataStream __all__ = ( "Account", + "AccountSummary", "AnalyticsAdminServiceAsyncClient", "AnalyticsAdminServiceClient", "AndroidAppDataStream", @@ -220,6 +229,8 @@ "GoogleAdsLink", "IndustryCategory", "IosAppDataStream", + "ListAccountSummariesRequest", + "ListAccountSummariesResponse", "ListAccountsRequest", "ListAccountsResponse", "ListAndroidAppDataStreamsRequest", @@ -238,6 +249,7 @@ "ListWebDataStreamsResponse", "MaximumUserAccess", "Property", + "PropertySummary", "ProvisionAccountTicketRequest", "ProvisionAccountTicketResponse", "UpdateAccountRequest", diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/__init__.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/__init__.py index 50e22774b54a..9132398ec310 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/__init__.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/__init__.py @@ -49,6 +49,8 @@ from .types.analytics_admin import GetPropertyRequest from .types.analytics_admin import GetUserLinkRequest from .types.analytics_admin import GetWebDataStreamRequest +from .types.analytics_admin import ListAccountSummariesRequest +from .types.analytics_admin import ListAccountSummariesResponse from .types.analytics_admin import ListAccountsRequest from .types.analytics_admin import ListAccountsResponse from .types.analytics_admin import ListAndroidAppDataStreamsRequest @@ -77,6 +79,7 @@ from .types.analytics_admin import UpdateUserLinkRequest from .types.analytics_admin import UpdateWebDataStreamRequest from .types.resources import Account +from .types.resources import AccountSummary from .types.resources import AndroidAppDataStream from .types.resources import AuditUserLink from .types.resources import DataSharingSettings @@ -88,12 +91,14 @@ from .types.resources import IosAppDataStream from .types.resources import MaximumUserAccess from .types.resources import Property +from .types.resources import PropertySummary from .types.resources import UserLink from .types.resources import WebDataStream __all__ = ( "Account", + "AccountSummary", "AndroidAppDataStream", "AuditUserLink", "AuditUserLinksRequest", @@ -136,6 +141,8 @@ "GoogleAdsLink", "IndustryCategory", "IosAppDataStream", + "ListAccountSummariesRequest", + "ListAccountSummariesResponse", "ListAccountsRequest", "ListAccountsResponse", "ListAndroidAppDataStreamsRequest", @@ -154,6 +161,7 @@ "ListWebDataStreamsResponse", "MaximumUserAccess", "Property", + "PropertySummary", "ProvisionAccountTicketRequest", "ProvisionAccountTicketResponse", "UpdateAccountRequest", diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py index 5f5d624d69e4..de768c685540 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py @@ -35,50 +35,123 @@ from google.protobuf import timestamp_pb2 as timestamp # type: ignore from google.protobuf import wrappers_pb2 as wrappers # type: ignore -from .transports.base import AnalyticsAdminServiceTransport +from .transports.base import AnalyticsAdminServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import AnalyticsAdminServiceGrpcAsyncIOTransport from .client import AnalyticsAdminServiceClient class AnalyticsAdminServiceAsyncClient: - """Service Interface for the Analytics Admin API (App+Web).""" + """Service Interface for the Analytics Admin API (GA4).""" _client: AnalyticsAdminServiceClient DEFAULT_ENDPOINT = AnalyticsAdminServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AnalyticsAdminServiceClient.DEFAULT_MTLS_ENDPOINT + account_path = staticmethod(AnalyticsAdminServiceClient.account_path) + parse_account_path = staticmethod(AnalyticsAdminServiceClient.parse_account_path) + account_summary_path = staticmethod( + AnalyticsAdminServiceClient.account_summary_path + ) + parse_account_summary_path = staticmethod( + AnalyticsAdminServiceClient.parse_account_summary_path + ) android_app_data_stream_path = staticmethod( AnalyticsAdminServiceClient.android_app_data_stream_path ) - - property_path = staticmethod(AnalyticsAdminServiceClient.property_path) - - user_link_path = staticmethod(AnalyticsAdminServiceClient.user_link_path) - + parse_android_app_data_stream_path = staticmethod( + AnalyticsAdminServiceClient.parse_android_app_data_stream_path + ) + data_sharing_settings_path = staticmethod( + AnalyticsAdminServiceClient.data_sharing_settings_path + ) + parse_data_sharing_settings_path = staticmethod( + AnalyticsAdminServiceClient.parse_data_sharing_settings_path + ) enhanced_measurement_settings_path = staticmethod( AnalyticsAdminServiceClient.enhanced_measurement_settings_path ) - + parse_enhanced_measurement_settings_path = staticmethod( + AnalyticsAdminServiceClient.parse_enhanced_measurement_settings_path + ) + firebase_link_path = staticmethod(AnalyticsAdminServiceClient.firebase_link_path) + parse_firebase_link_path = staticmethod( + AnalyticsAdminServiceClient.parse_firebase_link_path + ) + global_site_tag_path = staticmethod( + AnalyticsAdminServiceClient.global_site_tag_path + ) + parse_global_site_tag_path = staticmethod( + AnalyticsAdminServiceClient.parse_global_site_tag_path + ) google_ads_link_path = staticmethod( AnalyticsAdminServiceClient.google_ads_link_path ) - - firebase_link_path = staticmethod(AnalyticsAdminServiceClient.firebase_link_path) - + parse_google_ads_link_path = staticmethod( + AnalyticsAdminServiceClient.parse_google_ads_link_path + ) + ios_app_data_stream_path = staticmethod( + AnalyticsAdminServiceClient.ios_app_data_stream_path + ) + parse_ios_app_data_stream_path = staticmethod( + AnalyticsAdminServiceClient.parse_ios_app_data_stream_path + ) + property_path = staticmethod(AnalyticsAdminServiceClient.property_path) + parse_property_path = staticmethod(AnalyticsAdminServiceClient.parse_property_path) + user_link_path = staticmethod(AnalyticsAdminServiceClient.user_link_path) + parse_user_link_path = staticmethod( + AnalyticsAdminServiceClient.parse_user_link_path + ) web_data_stream_path = staticmethod( AnalyticsAdminServiceClient.web_data_stream_path ) + parse_web_data_stream_path = staticmethod( + AnalyticsAdminServiceClient.parse_web_data_stream_path + ) - ios_app_data_stream_path = staticmethod( - AnalyticsAdminServiceClient.ios_app_data_stream_path + common_billing_account_path = staticmethod( + AnalyticsAdminServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + AnalyticsAdminServiceClient.parse_common_billing_account_path ) - account_path = staticmethod(AnalyticsAdminServiceClient.account_path) + common_folder_path = staticmethod(AnalyticsAdminServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + AnalyticsAdminServiceClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + AnalyticsAdminServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + AnalyticsAdminServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(AnalyticsAdminServiceClient.common_project_path) + parse_common_project_path = staticmethod( + AnalyticsAdminServiceClient.parse_common_project_path + ) + + common_location_path = staticmethod( + AnalyticsAdminServiceClient.common_location_path + ) + parse_common_location_path = staticmethod( + AnalyticsAdminServiceClient.parse_common_location_path + ) from_service_account_file = AnalyticsAdminServiceClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> AnalyticsAdminServiceTransport: + """Return the transport used by the client instance. + + Returns: + AnalyticsAdminServiceTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(AnalyticsAdminServiceClient).get_transport_class, type(AnalyticsAdminServiceClient), @@ -90,6 +163,7 @@ def __init__( credentials: credentials.Credentials = None, transport: Union[str, AnalyticsAdminServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the analytics admin service client. @@ -105,16 +179,19 @@ def __init__( client_options (ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint, this is the default value for - the environment variable) and "auto" (auto switch to the default - mTLS endpoint if client SSL credentials is present). However, - the ``api_endpoint`` property takes precedence if provided. - (2) The ``client_cert_source`` property is used to provide client - SSL credentials for mutual TLS transport. If not provided, the - default SSL credentials will be used if present. + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -122,7 +199,10 @@ def __init__( """ self._client = AnalyticsAdminServiceClient( - credentials=credentials, transport=transport, client_options=client_options, + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, ) async def get_account( @@ -164,7 +244,8 @@ async def get_account( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -183,7 +264,7 @@ async def get_account( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_account, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -207,10 +288,10 @@ async def list_accounts( metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAccountsAsyncPager: r"""Returns all accounts accessible by the caller. - Note that these accounts might not currently have - App+Web properties. Soft-deleted (ie: "trashed") - accounts are excluded by default. Returns an empty list - if no relevant accounts are found. + Note that these accounts might not currently have GA4 + properties. Soft-deleted (ie: "trashed") accounts are + excluded by default. Returns an empty list if no + relevant accounts are found. Args: request (:class:`~.analytics_admin.ListAccountsRequest`): @@ -240,7 +321,7 @@ async def list_accounts( rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_accounts, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Send the request. @@ -297,7 +378,8 @@ async def delete_account( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -316,7 +398,7 @@ async def delete_account( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_account, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -374,7 +456,8 @@ async def update_account( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([account, update_mask]): + has_flattened_params = any([account, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -395,7 +478,7 @@ async def update_account( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_account, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -448,7 +531,7 @@ async def provision_account_ticket( rpc = gapic_v1.method_async.wrap_method( self._client._transport.provision_account_ticket, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Send the request. @@ -457,6 +540,61 @@ async def provision_account_ticket( # Done; return the response. return response + async def list_account_summaries( + self, + request: analytics_admin.ListAccountSummariesRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListAccountSummariesAsyncPager: + r"""Returns summaries of all accounts accessible by the + caller. + + Args: + request (:class:`~.analytics_admin.ListAccountSummariesRequest`): + The request object. Request message for + ListAccountSummaries RPC. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.ListAccountSummariesAsyncPager: + Response message for + ListAccountSummaries RPC. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + + request = analytics_admin.ListAccountSummariesRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_account_summaries, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListAccountSummariesAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + async def get_property( self, request: analytics_admin.GetPropertyRequest = None, @@ -466,10 +604,10 @@ async def get_property( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resources.Property: - r"""Lookup for a single "App+Web" Property. + r"""Lookup for a single "GA4" Property. Throws "Target not found" if no such property found, if - property is not of the type "App+Web", or if caller does - not have permissions to access it. + property is not of the type "GA4", or if caller does not + have permissions to access it. Args: request (:class:`~.analytics_admin.GetPropertyRequest`): @@ -490,13 +628,14 @@ async def get_property( Returns: ~.resources.Property: A resource message representing a - Google Analytics App+Web property. + Google Analytics GA4 property. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -515,7 +654,7 @@ async def get_property( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_property, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -540,7 +679,7 @@ async def list_properties( ) -> pagers.ListPropertiesAsyncPager: r"""Returns child Properties under the specified parent Account. - Only "App+Web" properties will be returned. + Only "GA4" properties will be returned. Properties will be excluded if the caller does not have access. Soft-deleted (ie: "trashed") properties are excluded by default. Returns an empty list if no @@ -575,7 +714,7 @@ async def list_properties( rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_properties, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Send the request. @@ -599,8 +738,8 @@ async def create_property( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resources.Property: - r"""Creates an "App+Web" property with the specified - location and attributes. + r"""Creates an "GA4" property with the specified location + and attributes. Args: request (:class:`~.analytics_admin.CreatePropertyRequest`): @@ -623,13 +762,14 @@ async def create_property( Returns: ~.resources.Property: A resource message representing a - Google Analytics App+Web property. + Google Analytics GA4 property. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([property]): + has_flattened_params = any([property]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -648,7 +788,7 @@ async def create_property( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_property, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Send the request. @@ -677,7 +817,7 @@ async def delete_property( purged. https://support.google.com/analytics/answer/6154772 Returns an error if the target is not found, or is not - an App+Web Property. + an GA4 Property. Args: request (:class:`~.analytics_admin.DeletePropertyRequest`): @@ -700,7 +840,8 @@ async def delete_property( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -719,7 +860,7 @@ async def delete_property( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_property, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -772,13 +913,14 @@ async def update_property( Returns: ~.resources.Property: A resource message representing a - Google Analytics App+Web property. + Google Analytics GA4 property. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([property, update_mask]): + has_flattened_params = any([property, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -799,7 +941,7 @@ async def update_property( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_property, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -854,7 +996,8 @@ async def get_user_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -873,7 +1016,7 @@ async def get_user_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_user_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -925,7 +1068,7 @@ async def batch_get_user_links( rpc = gapic_v1.method_async.wrap_method( self._client._transport.batch_get_user_links, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -980,7 +1123,8 @@ async def list_user_links( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -999,7 +1143,7 @@ async def list_user_links( rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_user_links, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1069,7 +1213,7 @@ async def audit_user_links( rpc = gapic_v1.method_async.wrap_method( self._client._transport.audit_user_links, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1146,7 +1290,8 @@ async def create_user_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, user_link]): + has_flattened_params = any([parent, user_link]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1167,7 +1312,7 @@ async def create_user_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_user_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1221,7 +1366,7 @@ async def batch_create_user_links( rpc = gapic_v1.method_async.wrap_method( self._client._transport.batch_create_user_links, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1273,7 +1418,8 @@ async def update_user_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([user_link]): + has_flattened_params = any([user_link]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1292,7 +1438,7 @@ async def update_user_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_user_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1346,7 +1492,7 @@ async def batch_update_user_links( rpc = gapic_v1.method_async.wrap_method( self._client._transport.batch_update_user_links, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1392,7 +1538,8 @@ async def delete_user_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1411,7 +1558,7 @@ async def delete_user_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_user_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1456,7 +1603,7 @@ async def batch_delete_user_links( rpc = gapic_v1.method_async.wrap_method( self._client._transport.batch_delete_user_links, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1512,7 +1659,8 @@ async def get_web_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1531,7 +1679,7 @@ async def get_web_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_web_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1579,7 +1727,8 @@ async def delete_web_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1598,7 +1747,7 @@ async def delete_web_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_web_data_stream, default_timeout=None, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1656,7 +1805,8 @@ async def update_web_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([web_data_stream, update_mask]): + has_flattened_params = any([web_data_stream, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1677,7 +1827,7 @@ async def update_web_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_web_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1739,7 +1889,8 @@ async def create_web_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, web_data_stream]): + has_flattened_params = any([parent, web_data_stream]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1760,7 +1911,7 @@ async def create_web_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_web_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1821,7 +1972,8 @@ async def list_web_data_streams( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1840,7 +1992,7 @@ async def list_web_data_streams( rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_web_data_streams, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1903,7 +2055,8 @@ async def get_ios_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1922,7 +2075,7 @@ async def get_ios_app_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_ios_app_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -1970,7 +2123,8 @@ async def delete_ios_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1989,7 +2143,7 @@ async def delete_ios_app_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_ios_app_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2048,7 +2202,8 @@ async def update_ios_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([ios_app_data_stream, update_mask]): + has_flattened_params = any([ios_app_data_stream, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2069,7 +2224,7 @@ async def update_ios_app_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_ios_app_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2132,7 +2287,8 @@ async def create_ios_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, ios_app_data_stream]): + has_flattened_params = any([parent, ios_app_data_stream]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2153,7 +2309,7 @@ async def create_ios_app_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_ios_app_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2214,7 +2370,8 @@ async def list_ios_app_data_streams( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2233,7 +2390,7 @@ async def list_ios_app_data_streams( rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_ios_app_data_streams, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2296,7 +2453,8 @@ async def get_android_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2315,7 +2473,7 @@ async def get_android_app_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_android_app_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2363,7 +2521,8 @@ async def delete_android_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2382,7 +2541,7 @@ async def delete_android_app_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_android_app_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2441,7 +2600,8 @@ async def update_android_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([android_app_data_stream, update_mask]): + has_flattened_params = any([android_app_data_stream, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2462,7 +2622,7 @@ async def update_android_app_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_android_app_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2530,7 +2690,8 @@ async def create_android_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, android_app_data_stream]): + has_flattened_params = any([parent, android_app_data_stream]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2551,7 +2712,7 @@ async def create_android_app_data_stream( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_android_app_data_stream, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2612,7 +2773,8 @@ async def list_android_app_data_streams( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2631,7 +2793,7 @@ async def list_android_app_data_streams( rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_android_app_data_streams, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2671,6 +2833,7 @@ async def get_enhanced_measurement_settings( GetEnhancedMeasurementSettings RPC. name (:class:`str`): Required. The name of the settings to lookup. Format: + properties/{property_id}/webDataStreams/{stream_id}/enhancedMeasurementSettings Example: "properties/1000/webDataStreams/2000/enhancedMeasurementSettings". @@ -2695,7 +2858,8 @@ async def get_enhanced_measurement_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2714,7 +2878,7 @@ async def get_enhanced_measurement_settings( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_enhanced_measurement_settings, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2777,7 +2941,8 @@ async def update_enhanced_measurement_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([enhanced_measurement_settings, update_mask]): + has_flattened_params = any([enhanced_measurement_settings, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2798,7 +2963,7 @@ async def update_enhanced_measurement_settings( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_enhanced_measurement_settings, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2858,14 +3023,15 @@ async def create_firebase_link( Returns: ~.resources.FirebaseLink: - A link between an App+Web property - and a Firebase project. + A link between an GA4 property and a + Firebase project. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, firebase_link]): + has_flattened_params = any([parent, firebase_link]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2886,7 +3052,7 @@ async def create_firebase_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_firebase_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -2938,14 +3104,15 @@ async def update_firebase_link( Returns: ~.resources.FirebaseLink: - A link between an App+Web property - and a Firebase project. + A link between an GA4 property and a + Firebase project. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([firebase_link, update_mask]): + has_flattened_params = any([firebase_link, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -2966,7 +3133,7 @@ async def update_firebase_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_firebase_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3015,7 +3182,8 @@ async def delete_firebase_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3034,7 +3202,7 @@ async def delete_firebase_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_firebase_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3086,7 +3254,8 @@ async def list_firebase_links( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3105,7 +3274,7 @@ async def list_firebase_links( rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_firebase_links, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3163,7 +3332,8 @@ async def get_global_site_tag( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3182,7 +3352,7 @@ async def get_global_site_tag( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_global_site_tag, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3234,14 +3404,15 @@ async def create_google_ads_link( Returns: ~.resources.GoogleAdsLink: - A link between an App+Web property - and a Google Ads account. + A link between an GA4 property and a + Google Ads account. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, google_ads_link]): + has_flattened_params = any([parent, google_ads_link]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3262,7 +3433,7 @@ async def create_google_ads_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_google_ads_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3313,14 +3484,15 @@ async def update_google_ads_link( Returns: ~.resources.GoogleAdsLink: - A link between an App+Web property - and a Google Ads account. + A link between an GA4 property and a + Google Ads account. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([google_ads_link, update_mask]): + has_flattened_params = any([google_ads_link, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3341,7 +3513,7 @@ async def update_google_ads_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_google_ads_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3389,7 +3561,8 @@ async def delete_google_ads_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3408,7 +3581,7 @@ async def delete_google_ads_link( rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_google_ads_link, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3462,7 +3635,8 @@ async def list_google_ads_links( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3481,7 +3655,7 @@ async def list_google_ads_links( rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_google_ads_links, default_timeout=60.0, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3544,7 +3718,8 @@ async def get_data_sharing_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -3563,7 +3738,7 @@ async def get_data_sharing_settings( rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_data_sharing_settings, default_timeout=None, - client_info=_client_info, + client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; @@ -3580,11 +3755,11 @@ async def get_data_sharing_settings( try: - _client_info = gapic_v1.client_info.ClientInfo( + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution("google-analytics-admin",).version, ) except pkg_resources.DistributionNotFound: - _client_info = gapic_v1.client_info.ClientInfo() + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() __all__ = ("AnalyticsAdminServiceAsyncClient",) diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/client.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/client.py index 26e9fedf1c29..2ba795df2686 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/client.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/client.py @@ -16,17 +16,19 @@ # from collections import OrderedDict +from distutils import util import os import re -from typing import Callable, Dict, Sequence, Tuple, Type, Union +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import client_options as client_options_lib # type: ignore from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials # type: ignore from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore @@ -37,7 +39,7 @@ from google.protobuf import timestamp_pb2 as timestamp # type: ignore from google.protobuf import wrappers_pb2 as wrappers # type: ignore -from .transports.base import AnalyticsAdminServiceTransport +from .transports.base import AnalyticsAdminServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import AnalyticsAdminServiceGrpcTransport from .transports.grpc_asyncio import AnalyticsAdminServiceGrpcAsyncIOTransport @@ -78,7 +80,7 @@ def get_transport_class( class AnalyticsAdminServiceClient(metaclass=AnalyticsAdminServiceClientMeta): - """Service Interface for the Analytics Admin API (App+Web).""" + """Service Interface for the Analytics Admin API (GA4).""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): @@ -134,6 +136,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> AnalyticsAdminServiceTransport: + """Return the transport used by the client instance. + + Returns: + AnalyticsAdminServiceTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def account_path(account: str,) -> str: """Return a fully-qualified account string.""" @@ -145,6 +156,19 @@ def parse_account_path(path: str) -> Dict[str, str]: m = re.match(r"^accounts/(?P.+?)$", path) return m.groupdict() if m else {} + @staticmethod + def account_summary_path(account_summary: str,) -> str: + """Return a fully-qualified account_summary string.""" + return "accountSummaries/{account_summary}".format( + account_summary=account_summary, + ) + + @staticmethod + def parse_account_summary_path(path: str) -> Dict[str, str]: + """Parse a account_summary path into its component segments.""" + m = re.match(r"^accountSummaries/(?P.+?)$", path) + return m.groupdict() if m else {} + @staticmethod def android_app_data_stream_path( property: str, android_app_data_stream: str, @@ -163,6 +187,17 @@ def parse_android_app_data_stream_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def data_sharing_settings_path(account: str,) -> str: + """Return a fully-qualified data_sharing_settings string.""" + return "accounts/{account}/dataSharingSettings".format(account=account,) + + @staticmethod + def parse_data_sharing_settings_path(path: str) -> Dict[str, str]: + """Parse a data_sharing_settings path into its component segments.""" + m = re.match(r"^accounts/(?P.+?)/dataSharingSettings$", path) + return m.groupdict() if m else {} + @staticmethod def enhanced_measurement_settings_path(property: str, web_data_stream: str,) -> str: """Return a fully-qualified enhanced_measurement_settings string.""" @@ -194,6 +229,17 @@ def parse_firebase_link_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def global_site_tag_path(property: str,) -> str: + """Return a fully-qualified global_site_tag string.""" + return "properties/{property}/globalSiteTag".format(property=property,) + + @staticmethod + def parse_global_site_tag_path(path: str) -> Dict[str, str]: + """Parse a global_site_tag path into its component segments.""" + m = re.match(r"^properties/(?P.+?)/globalSiteTag$", path) + return m.groupdict() if m else {} + @staticmethod def google_ads_link_path(property: str, google_ads_link: str,) -> str: """Return a fully-qualified google_ads_link string.""" @@ -266,12 +312,72 @@ def parse_web_data_stream_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, - credentials: credentials.Credentials = None, - transport: Union[str, AnalyticsAdminServiceTransport] = None, - client_options: ClientOptions = None, + credentials: Optional[credentials.Credentials] = None, + transport: Union[str, AnalyticsAdminServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the analytics admin service client. @@ -284,48 +390,74 @@ def __init__( transport (Union[str, ~.AnalyticsAdminServiceTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. + client_options (client_options_lib.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint, this is the default value for - the environment variable) and "auto" (auto switch to the default - mTLS endpoint if client SSL credentials is present). However, - the ``api_endpoint`` property takes precedence if provided. - (2) The ``client_cert_source`` property is used to provide client - SSL credentials for mutual TLS transport. If not provided, the - default SSL credentials will be used if present. + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport creation failed for any reason. """ if isinstance(client_options, dict): - client_options = ClientOptions.from_dict(client_options) + client_options = client_options_lib.from_dict(client_options) if client_options is None: - client_options = ClientOptions.ClientOptions() + client_options = client_options_lib.ClientOptions() + + # Create SSL credentials for mutual TLS if needed. + use_client_cert = bool( + util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + ) + + ssl_credentials = None + is_mtls = False + if use_client_cert: + if client_options.client_cert_source: + import grpc # type: ignore - if client_options.api_endpoint is None: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never") + cert, key = client_options.client_cert_source() + ssl_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + is_mtls = True + else: + creds = SslCredentials() + is_mtls = creds.is_mtls + ssl_credentials = creds.ssl_credentials if is_mtls else None + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + else: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") if use_mtls_env == "never": - client_options.api_endpoint = self.DEFAULT_ENDPOINT + api_endpoint = self.DEFAULT_ENDPOINT elif use_mtls_env == "always": - client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT + api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - has_client_cert_source = ( - client_options.client_cert_source is not None - or mtls.has_default_client_cert_source() - ) - client_options.api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT - if has_client_cert_source - else self.DEFAULT_ENDPOINT + api_endpoint = ( + self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT ) else: raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS value. Accepted values: never, auto, always" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" ) # Save or instantiate the transport. @@ -349,11 +481,11 @@ def __init__( self._transport = Transport( credentials=credentials, credentials_file=client_options.credentials_file, - host=client_options.api_endpoint, + host=api_endpoint, scopes=client_options.scopes, - api_mtls_endpoint=client_options.api_endpoint, - client_cert_source=client_options.client_cert_source, + ssl_channel_credentials=ssl_credentials, quota_project_id=client_options.quota_project_id, + client_info=client_info, ) def get_account( @@ -395,25 +527,29 @@ def get_account( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetAccountRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetAccountRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.GetAccountRequest): + request = analytics_admin.GetAccountRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_account, default_timeout=60.0, client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.get_account] # Certain fields should be provided within the metadata header; # add these here. @@ -436,10 +572,10 @@ def list_accounts( metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAccountsPager: r"""Returns all accounts accessible by the caller. - Note that these accounts might not currently have - App+Web properties. Soft-deleted (ie: "trashed") - accounts are excluded by default. Returns an empty list - if no relevant accounts are found. + Note that these accounts might not currently have GA4 + properties. Soft-deleted (ie: "trashed") accounts are + excluded by default. Returns an empty list if no + relevant accounts are found. Args: request (:class:`~.analytics_admin.ListAccountsRequest`): @@ -462,15 +598,16 @@ def list_accounts( """ # Create or coerce a protobuf request object. - request = analytics_admin.ListAccountsRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListAccountsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListAccountsRequest): + request = analytics_admin.ListAccountsRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_accounts, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.list_accounts] # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) @@ -526,27 +663,29 @@ def delete_account( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.DeleteAccountRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.DeleteAccountRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.DeleteAccountRequest): + request = analytics_admin.DeleteAccountRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_account, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.delete_account] # Certain fields should be provided within the metadata header; # add these here. @@ -603,29 +742,31 @@ def update_account( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([account, update_mask]): + has_flattened_params = any([account, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdateAccountRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdateAccountRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.UpdateAccountRequest): + request = analytics_admin.UpdateAccountRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if account is not None: - request.account = account - if update_mask is not None: - request.update_mask = update_mask + if account is not None: + request.account = account + if update_mask is not None: + request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_account, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.update_account] # Certain fields should be provided within the metadata header; # add these here. @@ -670,19 +811,76 @@ def provision_account_ticket( """ # Create or coerce a protobuf request object. - request = analytics_admin.ProvisionAccountTicketRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ProvisionAccountTicketRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ProvisionAccountTicketRequest): + request = analytics_admin.ProvisionAccountTicketRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.provision_account_ticket, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.provision_account_ticket] + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def list_account_summaries( + self, + request: analytics_admin.ListAccountSummariesRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListAccountSummariesPager: + r"""Returns summaries of all accounts accessible by the + caller. + + Args: + request (:class:`~.analytics_admin.ListAccountSummariesRequest`): + The request object. Request message for + ListAccountSummaries RPC. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.ListAccountSummariesPager: + Response message for + ListAccountSummaries RPC. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListAccountSummariesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListAccountSummariesRequest): + request = analytics_admin.ListAccountSummariesRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_account_summaries] # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListAccountSummariesPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + # Done; return the response. return response @@ -695,10 +893,10 @@ def get_property( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resources.Property: - r"""Lookup for a single "App+Web" Property. + r"""Lookup for a single "GA4" Property. Throws "Target not found" if no such property found, if - property is not of the type "App+Web", or if caller does - not have permissions to access it. + property is not of the type "GA4", or if caller does not + have permissions to access it. Args: request (:class:`~.analytics_admin.GetPropertyRequest`): @@ -719,33 +917,35 @@ def get_property( Returns: ~.resources.Property: A resource message representing a - Google Analytics App+Web property. + Google Analytics GA4 property. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetPropertyRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetPropertyRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.GetPropertyRequest): + request = analytics_admin.GetPropertyRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_property, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.get_property] # Certain fields should be provided within the metadata header; # add these here. @@ -769,7 +969,7 @@ def list_properties( ) -> pagers.ListPropertiesPager: r"""Returns child Properties under the specified parent Account. - Only "App+Web" properties will be returned. + Only "GA4" properties will be returned. Properties will be excluded if the caller does not have access. Soft-deleted (ie: "trashed") properties are excluded by default. Returns an empty list if no @@ -797,15 +997,16 @@ def list_properties( """ # Create or coerce a protobuf request object. - request = analytics_admin.ListPropertiesRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListPropertiesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListPropertiesRequest): + request = analytics_admin.ListPropertiesRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_properties, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.list_properties] # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) @@ -828,8 +1029,8 @@ def create_property( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resources.Property: - r"""Creates an "App+Web" property with the specified - location and attributes. + r"""Creates an "GA4" property with the specified location + and attributes. Args: request (:class:`~.analytics_admin.CreatePropertyRequest`): @@ -852,33 +1053,35 @@ def create_property( Returns: ~.resources.Property: A resource message representing a - Google Analytics App+Web property. + Google Analytics GA4 property. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([property]): + has_flattened_params = any([property]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.CreatePropertyRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.CreatePropertyRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.CreatePropertyRequest): + request = analytics_admin.CreatePropertyRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if property is not None: - request.property = property + if property is not None: + request.property = property # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.create_property, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.create_property] # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) @@ -906,7 +1109,7 @@ def delete_property( purged. https://support.google.com/analytics/answer/6154772 Returns an error if the target is not found, or is not - an App+Web Property. + an GA4 Property. Args: request (:class:`~.analytics_admin.DeletePropertyRequest`): @@ -929,27 +1132,29 @@ def delete_property( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.DeletePropertyRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.DeletePropertyRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.DeletePropertyRequest): + request = analytics_admin.DeletePropertyRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_property, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.delete_property] # Certain fields should be provided within the metadata header; # add these here. @@ -1001,35 +1206,37 @@ def update_property( Returns: ~.resources.Property: A resource message representing a - Google Analytics App+Web property. + Google Analytics GA4 property. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([property, update_mask]): + has_flattened_params = any([property, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdatePropertyRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdatePropertyRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.UpdatePropertyRequest): + request = analytics_admin.UpdatePropertyRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if property is not None: - request.property = property - if update_mask is not None: - request.update_mask = update_mask + if property is not None: + request.property = property + if update_mask is not None: + request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_property, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.update_property] # Certain fields should be provided within the metadata header; # add these here. @@ -1083,27 +1290,29 @@ def get_user_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetUserLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetUserLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.GetUserLinkRequest): + request = analytics_admin.GetUserLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_user_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.get_user_link] # Certain fields should be provided within the metadata header; # add these here. @@ -1147,15 +1356,16 @@ def batch_get_user_links( """ # Create or coerce a protobuf request object. - request = analytics_admin.BatchGetUserLinksRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.BatchGetUserLinksRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.BatchGetUserLinksRequest): + request = analytics_admin.BatchGetUserLinksRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.batch_get_user_links, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.batch_get_user_links] # Certain fields should be provided within the metadata header; # add these here. @@ -1209,27 +1419,29 @@ def list_user_links( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.ListUserLinksRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListUserLinksRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListUserLinksRequest): + request = analytics_admin.ListUserLinksRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent + if parent is not None: + request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_user_links, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.list_user_links] # Certain fields should be provided within the metadata header; # add these here. @@ -1291,15 +1503,16 @@ def audit_user_links( """ # Create or coerce a protobuf request object. - request = analytics_admin.AuditUserLinksRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.AuditUserLinksRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.AuditUserLinksRequest): + request = analytics_admin.AuditUserLinksRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.audit_user_links, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.audit_user_links] # Certain fields should be provided within the metadata header; # add these here. @@ -1375,29 +1588,31 @@ def create_user_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, user_link]): + has_flattened_params = any([parent, user_link]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.CreateUserLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.CreateUserLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.CreateUserLinkRequest): + request = analytics_admin.CreateUserLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent - if user_link is not None: - request.user_link = user_link + if parent is not None: + request.parent = parent + if user_link is not None: + request.user_link = user_link # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.create_user_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.create_user_link] # Certain fields should be provided within the metadata header; # add these here. @@ -1443,15 +1658,16 @@ def batch_create_user_links( """ # Create or coerce a protobuf request object. - request = analytics_admin.BatchCreateUserLinksRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.BatchCreateUserLinksRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.BatchCreateUserLinksRequest): + request = analytics_admin.BatchCreateUserLinksRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.batch_create_user_links, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.batch_create_user_links] # Certain fields should be provided within the metadata header; # add these here. @@ -1502,27 +1718,29 @@ def update_user_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([user_link]): + has_flattened_params = any([user_link]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdateUserLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdateUserLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.UpdateUserLinkRequest): + request = analytics_admin.UpdateUserLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if user_link is not None: - request.user_link = user_link + if user_link is not None: + request.user_link = user_link # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_user_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.update_user_link] # Certain fields should be provided within the metadata header; # add these here. @@ -1568,15 +1786,16 @@ def batch_update_user_links( """ # Create or coerce a protobuf request object. - request = analytics_admin.BatchUpdateUserLinksRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.BatchUpdateUserLinksRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.BatchUpdateUserLinksRequest): + request = analytics_admin.BatchUpdateUserLinksRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.batch_update_user_links, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.batch_update_user_links] # Certain fields should be provided within the metadata header; # add these here. @@ -1621,27 +1840,29 @@ def delete_user_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.DeleteUserLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.DeleteUserLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.DeleteUserLinkRequest): + request = analytics_admin.DeleteUserLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_user_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.delete_user_link] # Certain fields should be provided within the metadata header; # add these here. @@ -1678,15 +1899,16 @@ def batch_delete_user_links( """ # Create or coerce a protobuf request object. - request = analytics_admin.BatchDeleteUserLinksRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.BatchDeleteUserLinksRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.BatchDeleteUserLinksRequest): + request = analytics_admin.BatchDeleteUserLinksRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.batch_delete_user_links, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.batch_delete_user_links] # Certain fields should be provided within the metadata header; # add these here. @@ -1741,27 +1963,29 @@ def get_web_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetWebDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetWebDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.GetWebDataStreamRequest): + request = analytics_admin.GetWebDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_web_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.get_web_data_stream] # Certain fields should be provided within the metadata header; # add these here. @@ -1808,27 +2032,29 @@ def delete_web_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.DeleteWebDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.DeleteWebDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.DeleteWebDataStreamRequest): + request = analytics_admin.DeleteWebDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_web_data_stream, - default_timeout=None, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.delete_web_data_stream] # Certain fields should be provided within the metadata header; # add these here. @@ -1885,29 +2111,31 @@ def update_web_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([web_data_stream, update_mask]): + has_flattened_params = any([web_data_stream, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdateWebDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdateWebDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.UpdateWebDataStreamRequest): + request = analytics_admin.UpdateWebDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if web_data_stream is not None: - request.web_data_stream = web_data_stream - if update_mask is not None: - request.update_mask = update_mask + if web_data_stream is not None: + request.web_data_stream = web_data_stream + if update_mask is not None: + request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_web_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.update_web_data_stream] # Certain fields should be provided within the metadata header; # add these here. @@ -1968,29 +2196,31 @@ def create_web_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, web_data_stream]): + has_flattened_params = any([parent, web_data_stream]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.CreateWebDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.CreateWebDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.CreateWebDataStreamRequest): + request = analytics_admin.CreateWebDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent - if web_data_stream is not None: - request.web_data_stream = web_data_stream + if parent is not None: + request.parent = parent + if web_data_stream is not None: + request.web_data_stream = web_data_stream # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.create_web_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.create_web_data_stream] # Certain fields should be provided within the metadata header; # add these here. @@ -2050,27 +2280,29 @@ def list_web_data_streams( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.ListWebDataStreamsRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListWebDataStreamsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListWebDataStreamsRequest): + request = analytics_admin.ListWebDataStreamsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent + if parent is not None: + request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_web_data_streams, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.list_web_data_streams] # Certain fields should be provided within the metadata header; # add these here. @@ -2132,27 +2364,29 @@ def get_ios_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetIosAppDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetIosAppDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.GetIosAppDataStreamRequest): + request = analytics_admin.GetIosAppDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_ios_app_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.get_ios_app_data_stream] # Certain fields should be provided within the metadata header; # add these here. @@ -2199,27 +2433,31 @@ def delete_ios_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.DeleteIosAppDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.DeleteIosAppDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.DeleteIosAppDataStreamRequest): + request = analytics_admin.DeleteIosAppDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_ios_app_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.delete_ios_app_data_stream + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2277,29 +2515,33 @@ def update_ios_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([ios_app_data_stream, update_mask]): + has_flattened_params = any([ios_app_data_stream, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdateIosAppDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdateIosAppDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.UpdateIosAppDataStreamRequest): + request = analytics_admin.UpdateIosAppDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if ios_app_data_stream is not None: - request.ios_app_data_stream = ios_app_data_stream - if update_mask is not None: - request.update_mask = update_mask + if ios_app_data_stream is not None: + request.ios_app_data_stream = ios_app_data_stream + if update_mask is not None: + request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_ios_app_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.update_ios_app_data_stream + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2361,29 +2603,33 @@ def create_ios_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, ios_app_data_stream]): + has_flattened_params = any([parent, ios_app_data_stream]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.CreateIosAppDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.CreateIosAppDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.CreateIosAppDataStreamRequest): + request = analytics_admin.CreateIosAppDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent - if ios_app_data_stream is not None: - request.ios_app_data_stream = ios_app_data_stream + if parent is not None: + request.parent = parent + if ios_app_data_stream is not None: + request.ios_app_data_stream = ios_app_data_stream # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.create_ios_app_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.create_ios_app_data_stream + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2443,27 +2689,31 @@ def list_ios_app_data_streams( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.ListIosAppDataStreamsRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListIosAppDataStreamsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListIosAppDataStreamsRequest): + request = analytics_admin.ListIosAppDataStreamsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent + if parent is not None: + request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_ios_app_data_streams, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.list_ios_app_data_streams + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2525,27 +2775,31 @@ def get_android_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetAndroidAppDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetAndroidAppDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.GetAndroidAppDataStreamRequest): + request = analytics_admin.GetAndroidAppDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_android_app_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.get_android_app_data_stream + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2592,27 +2846,31 @@ def delete_android_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.DeleteAndroidAppDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.DeleteAndroidAppDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.DeleteAndroidAppDataStreamRequest): + request = analytics_admin.DeleteAndroidAppDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_android_app_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.delete_android_app_data_stream + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2670,29 +2928,33 @@ def update_android_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([android_app_data_stream, update_mask]): + has_flattened_params = any([android_app_data_stream, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdateAndroidAppDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdateAndroidAppDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.UpdateAndroidAppDataStreamRequest): + request = analytics_admin.UpdateAndroidAppDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if android_app_data_stream is not None: - request.android_app_data_stream = android_app_data_stream - if update_mask is not None: - request.update_mask = update_mask + if android_app_data_stream is not None: + request.android_app_data_stream = android_app_data_stream + if update_mask is not None: + request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_android_app_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.update_android_app_data_stream + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2759,29 +3021,33 @@ def create_android_app_data_stream( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, android_app_data_stream]): + has_flattened_params = any([parent, android_app_data_stream]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.CreateAndroidAppDataStreamRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.CreateAndroidAppDataStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.CreateAndroidAppDataStreamRequest): + request = analytics_admin.CreateAndroidAppDataStreamRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent - if android_app_data_stream is not None: - request.android_app_data_stream = android_app_data_stream + if parent is not None: + request.parent = parent + if android_app_data_stream is not None: + request.android_app_data_stream = android_app_data_stream # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.create_android_app_data_stream, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.create_android_app_data_stream + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2841,27 +3107,31 @@ def list_android_app_data_streams( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.ListAndroidAppDataStreamsRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListAndroidAppDataStreamsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListAndroidAppDataStreamsRequest): + request = analytics_admin.ListAndroidAppDataStreamsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent + if parent is not None: + request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_android_app_data_streams, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.list_android_app_data_streams + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2900,6 +3170,7 @@ def get_enhanced_measurement_settings( GetEnhancedMeasurementSettings RPC. name (:class:`str`): Required. The name of the settings to lookup. Format: + properties/{property_id}/webDataStreams/{stream_id}/enhancedMeasurementSettings Example: "properties/1000/webDataStreams/2000/enhancedMeasurementSettings". @@ -2924,27 +3195,33 @@ def get_enhanced_measurement_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetEnhancedMeasurementSettingsRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetEnhancedMeasurementSettingsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, analytics_admin.GetEnhancedMeasurementSettingsRequest + ): + request = analytics_admin.GetEnhancedMeasurementSettingsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_enhanced_measurement_settings, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.get_enhanced_measurement_settings + ] # Certain fields should be provided within the metadata header; # add these here. @@ -3006,29 +3283,35 @@ def update_enhanced_measurement_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([enhanced_measurement_settings, update_mask]): + has_flattened_params = any([enhanced_measurement_settings, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdateEnhancedMeasurementSettingsRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdateEnhancedMeasurementSettingsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, analytics_admin.UpdateEnhancedMeasurementSettingsRequest + ): + request = analytics_admin.UpdateEnhancedMeasurementSettingsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if enhanced_measurement_settings is not None: - request.enhanced_measurement_settings = enhanced_measurement_settings - if update_mask is not None: - request.update_mask = update_mask + if enhanced_measurement_settings is not None: + request.enhanced_measurement_settings = enhanced_measurement_settings + if update_mask is not None: + request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_enhanced_measurement_settings, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.update_enhanced_measurement_settings + ] # Certain fields should be provided within the metadata header; # add these here. @@ -3087,36 +3370,38 @@ def create_firebase_link( Returns: ~.resources.FirebaseLink: - A link between an App+Web property - and a Firebase project. + A link between an GA4 property and a + Firebase project. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, firebase_link]): + has_flattened_params = any([parent, firebase_link]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.CreateFirebaseLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.CreateFirebaseLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.CreateFirebaseLinkRequest): + request = analytics_admin.CreateFirebaseLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent - if firebase_link is not None: - request.firebase_link = firebase_link + if parent is not None: + request.parent = parent + if firebase_link is not None: + request.firebase_link = firebase_link # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.create_firebase_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.create_firebase_link] # Certain fields should be provided within the metadata header; # add these here. @@ -3167,36 +3452,38 @@ def update_firebase_link( Returns: ~.resources.FirebaseLink: - A link between an App+Web property - and a Firebase project. + A link between an GA4 property and a + Firebase project. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([firebase_link, update_mask]): + has_flattened_params = any([firebase_link, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdateFirebaseLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdateFirebaseLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.UpdateFirebaseLinkRequest): + request = analytics_admin.UpdateFirebaseLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if firebase_link is not None: - request.firebase_link = firebase_link - if update_mask is not None: - request.update_mask = update_mask + if firebase_link is not None: + request.firebase_link = firebase_link + if update_mask is not None: + request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_firebase_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.update_firebase_link] # Certain fields should be provided within the metadata header; # add these here. @@ -3244,27 +3531,29 @@ def delete_firebase_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.DeleteFirebaseLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.DeleteFirebaseLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.DeleteFirebaseLinkRequest): + request = analytics_admin.DeleteFirebaseLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_firebase_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.delete_firebase_link] # Certain fields should be provided within the metadata header; # add these here. @@ -3315,27 +3604,29 @@ def list_firebase_links( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.ListFirebaseLinksRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListFirebaseLinksRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListFirebaseLinksRequest): + request = analytics_admin.ListFirebaseLinksRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent + if parent is not None: + request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_firebase_links, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.list_firebase_links] # Certain fields should be provided within the metadata header; # add these here. @@ -3392,27 +3683,29 @@ def get_global_site_tag( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetGlobalSiteTagRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetGlobalSiteTagRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.GetGlobalSiteTagRequest): + request = analytics_admin.GetGlobalSiteTagRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_global_site_tag, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.get_global_site_tag] # Certain fields should be provided within the metadata header; # add these here. @@ -3463,36 +3756,38 @@ def create_google_ads_link( Returns: ~.resources.GoogleAdsLink: - A link between an App+Web property - and a Google Ads account. + A link between an GA4 property and a + Google Ads account. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, google_ads_link]): + has_flattened_params = any([parent, google_ads_link]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.CreateGoogleAdsLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.CreateGoogleAdsLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.CreateGoogleAdsLinkRequest): + request = analytics_admin.CreateGoogleAdsLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent - if google_ads_link is not None: - request.google_ads_link = google_ads_link + if parent is not None: + request.parent = parent + if google_ads_link is not None: + request.google_ads_link = google_ads_link # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.create_google_ads_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.create_google_ads_link] # Certain fields should be provided within the metadata header; # add these here. @@ -3542,36 +3837,38 @@ def update_google_ads_link( Returns: ~.resources.GoogleAdsLink: - A link between an App+Web property - and a Google Ads account. + A link between an GA4 property and a + Google Ads account. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([google_ads_link, update_mask]): + has_flattened_params = any([google_ads_link, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.UpdateGoogleAdsLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.UpdateGoogleAdsLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.UpdateGoogleAdsLinkRequest): + request = analytics_admin.UpdateGoogleAdsLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if google_ads_link is not None: - request.google_ads_link = google_ads_link - if update_mask is not None: - request.update_mask = update_mask + if google_ads_link is not None: + request.google_ads_link = google_ads_link + if update_mask is not None: + request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.update_google_ads_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.update_google_ads_link] # Certain fields should be provided within the metadata header; # add these here. @@ -3618,27 +3915,29 @@ def delete_google_ads_link( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.DeleteGoogleAdsLinkRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.DeleteGoogleAdsLinkRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.DeleteGoogleAdsLinkRequest): + request = analytics_admin.DeleteGoogleAdsLinkRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_google_ads_link, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.delete_google_ads_link] # Certain fields should be provided within the metadata header; # add these here. @@ -3691,27 +3990,29 @@ def list_google_ads_links( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.ListGoogleAdsLinksRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.ListGoogleAdsLinksRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.ListGoogleAdsLinksRequest): + request = analytics_admin.ListGoogleAdsLinksRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if parent is not None: - request.parent = parent + if parent is not None: + request.parent = parent # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_google_ads_links, - default_timeout=60.0, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[self._transport.list_google_ads_links] # Certain fields should be provided within the metadata header; # add these here. @@ -3773,27 +4074,31 @@ def get_data_sharing_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." ) - request = analytics_admin.GetDataSharingSettingsRequest(request) + # Minor optimization to avoid making a copy if the user passes + # in a analytics_admin.GetDataSharingSettingsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_admin.GetDataSharingSettingsRequest): + request = analytics_admin.GetDataSharingSettingsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. + # If we have keyword arguments corresponding to fields on the + # request, apply these. - if name is not None: - request.name = name + if name is not None: + request.name = name # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_data_sharing_settings, - default_timeout=None, - client_info=_client_info, - ) + rpc = self._transport._wrapped_methods[ + self._transport.get_data_sharing_settings + ] # Certain fields should be provided within the metadata header; # add these here. @@ -3809,11 +4114,11 @@ def get_data_sharing_settings( try: - _client_info = gapic_v1.client_info.ClientInfo( + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=pkg_resources.get_distribution("google-analytics-admin",).version, ) except pkg_resources.DistributionNotFound: - _client_info = gapic_v1.client_info.ClientInfo() + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() __all__ = ("AnalyticsAdminServiceClient",) diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/pagers.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/pagers.py index db0b9f910c3e..8ea5aa484c43 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/pagers.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/pagers.py @@ -149,6 +149,136 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) +class ListAccountSummariesPager: + """A pager for iterating through ``list_account_summaries`` requests. + + This class thinly wraps an initial + :class:`~.analytics_admin.ListAccountSummariesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``account_summaries`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListAccountSummaries`` requests and continue to iterate + through the ``account_summaries`` field on the + corresponding responses. + + All the usual :class:`~.analytics_admin.ListAccountSummariesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., analytics_admin.ListAccountSummariesResponse], + request: analytics_admin.ListAccountSummariesRequest, + response: analytics_admin.ListAccountSummariesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (:class:`~.analytics_admin.ListAccountSummariesRequest`): + The initial request object. + response (:class:`~.analytics_admin.ListAccountSummariesResponse`): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = analytics_admin.ListAccountSummariesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterable[analytics_admin.ListAccountSummariesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterable[resources.AccountSummary]: + for page in self.pages: + yield from page.account_summaries + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListAccountSummariesAsyncPager: + """A pager for iterating through ``list_account_summaries`` requests. + + This class thinly wraps an initial + :class:`~.analytics_admin.ListAccountSummariesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``account_summaries`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListAccountSummaries`` requests and continue to iterate + through the ``account_summaries`` field on the + corresponding responses. + + All the usual :class:`~.analytics_admin.ListAccountSummariesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[analytics_admin.ListAccountSummariesResponse]], + request: analytics_admin.ListAccountSummariesRequest, + response: analytics_admin.ListAccountSummariesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (:class:`~.analytics_admin.ListAccountSummariesRequest`): + The initial request object. + response (:class:`~.analytics_admin.ListAccountSummariesResponse`): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = analytics_admin.ListAccountSummariesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterable[analytics_admin.ListAccountSummariesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterable[resources.AccountSummary]: + async def async_generator(): + async for page in self.pages: + for response in page.account_summaries: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + class ListPropertiesPager: """A pager for iterating through ``list_properties`` requests. diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/__init__.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/__init__.py index b4840aac46a1..e1e55440a92b 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/__init__.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/__init__.py @@ -30,7 +30,6 @@ _transport_registry["grpc"] = AnalyticsAdminServiceGrpcTransport _transport_registry["grpc_asyncio"] = AnalyticsAdminServiceGrpcAsyncIOTransport - __all__ = ( "AnalyticsAdminServiceTransport", "AnalyticsAdminServiceGrpcTransport", diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py index 4167ddd0a420..2521cf8bc5ed 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py @@ -17,9 +17,12 @@ import abc import typing +import pkg_resources -from google import auth +from google import auth # type: ignore from google.api_core import exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore from google.auth import credentials # type: ignore from google.analytics.admin_v1alpha.types import analytics_admin @@ -27,6 +30,14 @@ from google.protobuf import empty_pb2 as empty # type: ignore +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution("google-analytics-admin",).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + class AnalyticsAdminServiceTransport(abc.ABC): """Abstract transport class for AnalyticsAdminService.""" @@ -45,6 +56,7 @@ def __init__( credentials_file: typing.Optional[str] = None, scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, quota_project_id: typing.Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. @@ -62,6 +74,11 @@ def __init__( scope (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -88,6 +105,218 @@ def __init__( # Save the credentials. self._credentials = credentials + # Lifted into its own function so it can be stubbed out during tests. + self._prep_wrapped_messages(client_info) + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.get_account: gapic_v1.method.wrap_method( + self.get_account, default_timeout=60.0, client_info=client_info, + ), + self.list_accounts: gapic_v1.method.wrap_method( + self.list_accounts, default_timeout=60.0, client_info=client_info, + ), + self.delete_account: gapic_v1.method.wrap_method( + self.delete_account, default_timeout=60.0, client_info=client_info, + ), + self.update_account: gapic_v1.method.wrap_method( + self.update_account, default_timeout=60.0, client_info=client_info, + ), + self.provision_account_ticket: gapic_v1.method.wrap_method( + self.provision_account_ticket, + default_timeout=60.0, + client_info=client_info, + ), + self.list_account_summaries: gapic_v1.method.wrap_method( + self.list_account_summaries, + default_timeout=None, + client_info=client_info, + ), + self.get_property: gapic_v1.method.wrap_method( + self.get_property, default_timeout=60.0, client_info=client_info, + ), + self.list_properties: gapic_v1.method.wrap_method( + self.list_properties, default_timeout=60.0, client_info=client_info, + ), + self.create_property: gapic_v1.method.wrap_method( + self.create_property, default_timeout=60.0, client_info=client_info, + ), + self.delete_property: gapic_v1.method.wrap_method( + self.delete_property, default_timeout=60.0, client_info=client_info, + ), + self.update_property: gapic_v1.method.wrap_method( + self.update_property, default_timeout=60.0, client_info=client_info, + ), + self.get_user_link: gapic_v1.method.wrap_method( + self.get_user_link, default_timeout=60.0, client_info=client_info, + ), + self.batch_get_user_links: gapic_v1.method.wrap_method( + self.batch_get_user_links, + default_timeout=60.0, + client_info=client_info, + ), + self.list_user_links: gapic_v1.method.wrap_method( + self.list_user_links, default_timeout=60.0, client_info=client_info, + ), + self.audit_user_links: gapic_v1.method.wrap_method( + self.audit_user_links, default_timeout=60.0, client_info=client_info, + ), + self.create_user_link: gapic_v1.method.wrap_method( + self.create_user_link, default_timeout=60.0, client_info=client_info, + ), + self.batch_create_user_links: gapic_v1.method.wrap_method( + self.batch_create_user_links, + default_timeout=60.0, + client_info=client_info, + ), + self.update_user_link: gapic_v1.method.wrap_method( + self.update_user_link, default_timeout=60.0, client_info=client_info, + ), + self.batch_update_user_links: gapic_v1.method.wrap_method( + self.batch_update_user_links, + default_timeout=60.0, + client_info=client_info, + ), + self.delete_user_link: gapic_v1.method.wrap_method( + self.delete_user_link, default_timeout=60.0, client_info=client_info, + ), + self.batch_delete_user_links: gapic_v1.method.wrap_method( + self.batch_delete_user_links, + default_timeout=60.0, + client_info=client_info, + ), + self.get_web_data_stream: gapic_v1.method.wrap_method( + self.get_web_data_stream, default_timeout=60.0, client_info=client_info, + ), + self.delete_web_data_stream: gapic_v1.method.wrap_method( + self.delete_web_data_stream, + default_timeout=None, + client_info=client_info, + ), + self.update_web_data_stream: gapic_v1.method.wrap_method( + self.update_web_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.create_web_data_stream: gapic_v1.method.wrap_method( + self.create_web_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.list_web_data_streams: gapic_v1.method.wrap_method( + self.list_web_data_streams, + default_timeout=60.0, + client_info=client_info, + ), + self.get_ios_app_data_stream: gapic_v1.method.wrap_method( + self.get_ios_app_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.delete_ios_app_data_stream: gapic_v1.method.wrap_method( + self.delete_ios_app_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.update_ios_app_data_stream: gapic_v1.method.wrap_method( + self.update_ios_app_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.create_ios_app_data_stream: gapic_v1.method.wrap_method( + self.create_ios_app_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.list_ios_app_data_streams: gapic_v1.method.wrap_method( + self.list_ios_app_data_streams, + default_timeout=60.0, + client_info=client_info, + ), + self.get_android_app_data_stream: gapic_v1.method.wrap_method( + self.get_android_app_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.delete_android_app_data_stream: gapic_v1.method.wrap_method( + self.delete_android_app_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.update_android_app_data_stream: gapic_v1.method.wrap_method( + self.update_android_app_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.create_android_app_data_stream: gapic_v1.method.wrap_method( + self.create_android_app_data_stream, + default_timeout=60.0, + client_info=client_info, + ), + self.list_android_app_data_streams: gapic_v1.method.wrap_method( + self.list_android_app_data_streams, + default_timeout=60.0, + client_info=client_info, + ), + self.get_enhanced_measurement_settings: gapic_v1.method.wrap_method( + self.get_enhanced_measurement_settings, + default_timeout=60.0, + client_info=client_info, + ), + self.update_enhanced_measurement_settings: gapic_v1.method.wrap_method( + self.update_enhanced_measurement_settings, + default_timeout=60.0, + client_info=client_info, + ), + self.create_firebase_link: gapic_v1.method.wrap_method( + self.create_firebase_link, + default_timeout=60.0, + client_info=client_info, + ), + self.update_firebase_link: gapic_v1.method.wrap_method( + self.update_firebase_link, + default_timeout=60.0, + client_info=client_info, + ), + self.delete_firebase_link: gapic_v1.method.wrap_method( + self.delete_firebase_link, + default_timeout=60.0, + client_info=client_info, + ), + self.list_firebase_links: gapic_v1.method.wrap_method( + self.list_firebase_links, default_timeout=60.0, client_info=client_info, + ), + self.get_global_site_tag: gapic_v1.method.wrap_method( + self.get_global_site_tag, default_timeout=60.0, client_info=client_info, + ), + self.create_google_ads_link: gapic_v1.method.wrap_method( + self.create_google_ads_link, + default_timeout=60.0, + client_info=client_info, + ), + self.update_google_ads_link: gapic_v1.method.wrap_method( + self.update_google_ads_link, + default_timeout=60.0, + client_info=client_info, + ), + self.delete_google_ads_link: gapic_v1.method.wrap_method( + self.delete_google_ads_link, + default_timeout=60.0, + client_info=client_info, + ), + self.list_google_ads_links: gapic_v1.method.wrap_method( + self.list_google_ads_links, + default_timeout=60.0, + client_info=client_info, + ), + self.get_data_sharing_settings: gapic_v1.method.wrap_method( + self.get_data_sharing_settings, + default_timeout=None, + client_info=client_info, + ), + } + @property def get_account( self, @@ -139,6 +368,18 @@ def provision_account_ticket( ]: raise NotImplementedError() + @property + def list_account_summaries( + self, + ) -> typing.Callable[ + [analytics_admin.ListAccountSummariesRequest], + typing.Union[ + analytics_admin.ListAccountSummariesResponse, + typing.Awaitable[analytics_admin.ListAccountSummariesResponse], + ], + ]: + raise NotImplementedError() + @property def get_property( self, diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py index 1183afa05ec7..bb83bb8f669b 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py @@ -15,27 +15,28 @@ # limitations under the License. # +import warnings from typing import Callable, Dict, Optional, Sequence, Tuple from google.api_core import grpc_helpers # type: ignore +from google.api_core import gapic_v1 # type: ignore from google import auth # type: ignore from google.auth import credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore - import grpc # type: ignore from google.analytics.admin_v1alpha.types import analytics_admin from google.analytics.admin_v1alpha.types import resources from google.protobuf import empty_pb2 as empty # type: ignore -from .base import AnalyticsAdminServiceTransport +from .base import AnalyticsAdminServiceTransport, DEFAULT_CLIENT_INFO class AnalyticsAdminServiceGrpcTransport(AnalyticsAdminServiceTransport): """gRPC backend transport for AnalyticsAdminService. - Service Interface for the Analytics Admin API (App+Web). + Service Interface for the Analytics Admin API (GA4). This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -57,7 +58,9 @@ def __init__( channel: grpc.Channel = None, api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, - quota_project_id: Optional[str] = None + ssl_channel_credentials: grpc.ChannelCredentials = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the transport. @@ -76,16 +79,23 @@ def __init__( ignored if ``channel`` is provided. channel (Optional[grpc.Channel]): A ``Channel`` instance through which to make calls. - api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If - provided, it overrides the ``host`` argument and tries to create + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A - callback to provide client SSL certificate bytes and private key - bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` - is None. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -93,6 +103,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -100,7 +112,13 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: + warnings.warn( + "api_mtls_endpoint and client_cert_source are deprecated", + DeprecationWarning, + ) + host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -130,8 +148,36 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + self._ssl_channel_credentials = ssl_credentials + else: + host = host if ":" in host else host + ":443" + + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_channel_credentials, + scopes=scopes or self.AUTH_SCOPES, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._stubs = {} # type: Dict[str, Callable] + # Run the base constructor. super().__init__( host=host, @@ -139,10 +185,9 @@ def __init__( credentials_file=credentials_file, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + client_info=client_info, ) - self._stubs = {} # type: Dict[str, Callable] - @classmethod def create_channel( cls, @@ -151,11 +196,11 @@ def create_channel( credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, - **kwargs + **kwargs, ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -185,24 +230,13 @@ def create_channel( credentials_file=credentials_file, scopes=scopes, quota_project_id=quota_project_id, - **kwargs + **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Sanity check: Only create a new channel if we do not already - # have one. - if not hasattr(self, "_grpc_channel"): - self._grpc_channel = self.create_channel( - self._host, credentials=self._credentials, - ) - - # Return the channel from cache. return self._grpc_channel @property @@ -242,10 +276,10 @@ def list_accounts( r"""Return a callable for the list accounts method over gRPC. Returns all accounts accessible by the caller. - Note that these accounts might not currently have - App+Web properties. Soft-deleted (ie: "trashed") - accounts are excluded by default. Returns an empty list - if no relevant accounts are found. + Note that these accounts might not currently have GA4 + properties. Soft-deleted (ie: "trashed") accounts are + excluded by default. Returns an empty list if no + relevant accounts are found. Returns: Callable[[~.ListAccountsRequest], @@ -356,16 +390,46 @@ def provision_account_ticket( ) return self._stubs["provision_account_ticket"] + @property + def list_account_summaries( + self, + ) -> Callable[ + [analytics_admin.ListAccountSummariesRequest], + analytics_admin.ListAccountSummariesResponse, + ]: + r"""Return a callable for the list account summaries method over gRPC. + + Returns summaries of all accounts accessible by the + caller. + + Returns: + Callable[[~.ListAccountSummariesRequest], + ~.ListAccountSummariesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_account_summaries" not in self._stubs: + self._stubs["list_account_summaries"] = self.grpc_channel.unary_unary( + "/google.analytics.admin.v1alpha.AnalyticsAdminService/ListAccountSummaries", + request_serializer=analytics_admin.ListAccountSummariesRequest.serialize, + response_deserializer=analytics_admin.ListAccountSummariesResponse.deserialize, + ) + return self._stubs["list_account_summaries"] + @property def get_property( self, ) -> Callable[[analytics_admin.GetPropertyRequest], resources.Property]: r"""Return a callable for the get property method over gRPC. - Lookup for a single "App+Web" Property. + Lookup for a single "GA4" Property. Throws "Target not found" if no such property found, if - property is not of the type "App+Web", or if caller does - not have permissions to access it. + property is not of the type "GA4", or if caller does not + have permissions to access it. Returns: Callable[[~.GetPropertyRequest], @@ -395,7 +459,7 @@ def list_properties( Returns child Properties under the specified parent Account. - Only "App+Web" properties will be returned. + Only "GA4" properties will be returned. Properties will be excluded if the caller does not have access. Soft-deleted (ie: "trashed") properties are excluded by default. Returns an empty list if no @@ -425,8 +489,8 @@ def create_property( ) -> Callable[[analytics_admin.CreatePropertyRequest], resources.Property]: r"""Return a callable for the create property method over gRPC. - Creates an "App+Web" property with the specified - location and attributes. + Creates an "GA4" property with the specified location + and attributes. Returns: Callable[[~.CreatePropertyRequest], @@ -463,7 +527,7 @@ def delete_property( purged. https://support.google.com/analytics/answer/6154772 Returns an error if the target is not found, or is not - an App+Web Property. + an GA4 Property. Returns: Callable[[~.DeletePropertyRequest], diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py index 93309a259e72..26a431255a76 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py @@ -15,9 +15,12 @@ # limitations under the License. # +import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +from google.api_core import gapic_v1 # type: ignore from google.api_core import grpc_helpers_async # type: ignore +from google import auth # type: ignore from google.auth import credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -28,14 +31,14 @@ from google.analytics.admin_v1alpha.types import resources from google.protobuf import empty_pb2 as empty # type: ignore -from .base import AnalyticsAdminServiceTransport +from .base import AnalyticsAdminServiceTransport, DEFAULT_CLIENT_INFO from .grpc import AnalyticsAdminServiceGrpcTransport class AnalyticsAdminServiceGrpcAsyncIOTransport(AnalyticsAdminServiceTransport): """gRPC AsyncIO backend transport for AnalyticsAdminService. - Service Interface for the Analytics Admin API (App+Web). + Service Interface for the Analytics Admin API (GA4). This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -99,7 +102,9 @@ def __init__( channel: aio.Channel = None, api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the transport. @@ -119,16 +124,23 @@ def __init__( are passed to :func:`google.auth.default`. channel (Optional[aio.Channel]): A ``Channel`` instance through which to make calls. - api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If - provided, it overrides the ``host`` argument and tries to create + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from ``client_cert_source`` or applicatin default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A - callback to provide client SSL certificate bytes and private key - bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` - is None. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -136,6 +148,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -143,13 +157,24 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: + warnings.warn( + "api_mtls_endpoint and client_cert_source are deprecated", + DeprecationWarning, + ) + host = ( api_mtls_endpoint if ":" in api_mtls_endpoint else api_mtls_endpoint + ":443" ) + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + # Create SSL credentials with client_cert_source or application # default SSL credentials. if client_cert_source: @@ -168,6 +193,32 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + self._ssl_channel_credentials = ssl_credentials + else: + host = host if ":" in host else host + ":443" + + if credentials is None: + credentials, _ = auth.default( + scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id + ) + + # create a new channel. The provided one is ignored. + self._grpc_channel = type(self).create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + ssl_credentials=ssl_channel_credentials, + scopes=scopes or self.AUTH_SCOPES, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. @@ -177,6 +228,7 @@ def __init__( credentials_file=credentials_file, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + client_info=client_info, ) self._stubs = {} @@ -188,13 +240,6 @@ def grpc_channel(self) -> aio.Channel: This property caches on the instance; repeated calls return the same channel. """ - # Sanity check: Only create a new channel if we do not already - # have one. - if not hasattr(self, "_grpc_channel"): - self._grpc_channel = self.create_channel( - self._host, credentials=self._credentials, - ) - # Return the channel from cache. return self._grpc_channel @@ -236,10 +281,10 @@ def list_accounts( r"""Return a callable for the list accounts method over gRPC. Returns all accounts accessible by the caller. - Note that these accounts might not currently have - App+Web properties. Soft-deleted (ie: "trashed") - accounts are excluded by default. Returns an empty list - if no relevant accounts are found. + Note that these accounts might not currently have GA4 + properties. Soft-deleted (ie: "trashed") accounts are + excluded by default. Returns an empty list if no + relevant accounts are found. Returns: Callable[[~.ListAccountsRequest], @@ -350,16 +395,46 @@ def provision_account_ticket( ) return self._stubs["provision_account_ticket"] + @property + def list_account_summaries( + self, + ) -> Callable[ + [analytics_admin.ListAccountSummariesRequest], + Awaitable[analytics_admin.ListAccountSummariesResponse], + ]: + r"""Return a callable for the list account summaries method over gRPC. + + Returns summaries of all accounts accessible by the + caller. + + Returns: + Callable[[~.ListAccountSummariesRequest], + Awaitable[~.ListAccountSummariesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_account_summaries" not in self._stubs: + self._stubs["list_account_summaries"] = self.grpc_channel.unary_unary( + "/google.analytics.admin.v1alpha.AnalyticsAdminService/ListAccountSummaries", + request_serializer=analytics_admin.ListAccountSummariesRequest.serialize, + response_deserializer=analytics_admin.ListAccountSummariesResponse.deserialize, + ) + return self._stubs["list_account_summaries"] + @property def get_property( self, ) -> Callable[[analytics_admin.GetPropertyRequest], Awaitable[resources.Property]]: r"""Return a callable for the get property method over gRPC. - Lookup for a single "App+Web" Property. + Lookup for a single "GA4" Property. Throws "Target not found" if no such property found, if - property is not of the type "App+Web", or if caller does - not have permissions to access it. + property is not of the type "GA4", or if caller does not + have permissions to access it. Returns: Callable[[~.GetPropertyRequest], @@ -390,7 +465,7 @@ def list_properties( Returns child Properties under the specified parent Account. - Only "App+Web" properties will be returned. + Only "GA4" properties will be returned. Properties will be excluded if the caller does not have access. Soft-deleted (ie: "trashed") properties are excluded by default. Returns an empty list if no @@ -422,8 +497,8 @@ def create_property( ]: r"""Return a callable for the create property method over gRPC. - Creates an "App+Web" property with the specified - location and attributes. + Creates an "GA4" property with the specified location + and attributes. Returns: Callable[[~.CreatePropertyRequest], @@ -460,7 +535,7 @@ def delete_property( purged. https://support.google.com/analytics/answer/6154772 Returns an error if the target is not found, or is not - an App+Web Property. + an GA4 Property. Returns: Callable[[~.DeletePropertyRequest], diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/__init__.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/__init__.py index de1e42101cf2..4de0801057c1 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/__init__.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/__init__.py @@ -28,6 +28,10 @@ GlobalSiteTag, GoogleAdsLink, DataSharingSettings, + AccountSummary, + PropertySummary, + MaximumUserAccess, + IndustryCategory, ) from .analytics_admin import ( GetAccountRequest, @@ -90,9 +94,10 @@ ListGoogleAdsLinksRequest, ListGoogleAdsLinksResponse, GetDataSharingSettingsRequest, + ListAccountSummariesRequest, + ListAccountSummariesResponse, ) - __all__ = ( "Account", "Property", @@ -106,6 +111,10 @@ "GlobalSiteTag", "GoogleAdsLink", "DataSharingSettings", + "AccountSummary", + "PropertySummary", + "MaximumUserAccess", + "IndustryCategory", "GetAccountRequest", "ListAccountsRequest", "ListAccountsResponse", @@ -166,4 +175,6 @@ "ListGoogleAdsLinksRequest", "ListGoogleAdsLinksResponse", "GetDataSharingSettingsRequest", + "ListAccountSummariesRequest", + "ListAccountSummariesResponse", ) diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/analytics_admin.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/analytics_admin.py index f70d8292771a..5d89711722ec 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/analytics_admin.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/analytics_admin.py @@ -85,6 +85,8 @@ "ListGoogleAdsLinksRequest", "ListGoogleAdsLinksResponse", "GetDataSharingSettingsRequest", + "ListAccountSummariesRequest", + "ListAccountSummariesResponse", }, ) @@ -236,12 +238,13 @@ class ListPropertiesRequest(proto.Message): ``firebase_project:``\ (The id or number of the linked firebase project). Some examples of filters: - - ``parent:accounts/123`` : The account with account id: - 123. - - ``firebase_project:project-id`` : The firebase project - with id: project-id. - - ``firebase_project:123`` : The firebase project with - number: 123. + :: + + | Filter | Description | + |-----------------------------|-------------------------------------------| + | parent:accounts/123 | The account with account id: 123. | + | firebase_project:project-id | The firebase project with id: project-id. | + | firebase_project:123 | The firebase project with number: 123. | page_size (int): The maximum number of resources to return. The service may return fewer than this value, @@ -500,8 +503,9 @@ class CreateUserLinkRequest(proto.Message): parent (str): Required. Example format: accounts/1234 notify_new_user (bool): - Optional. If notify_new_user is set, then email new user - that they've been given permissions on the resource. + Optional. If set, then email the new user + notifying them that they've been granted + permissions to the resource. user_link (~.resources.UserLink): Required. The user link to create. """ @@ -525,12 +529,14 @@ class BatchCreateUserLinksRequest(proto.Message): empty or match this field. Example format: accounts/1234 notify_new_users (bool): - Optional. If notify_new_users is set, then email new users - that they've been given permissions on the resource. + Optional. If set, then email the new users notifying them + that they've been granted permissions to the resource. + Regardless of whether this is set or not, notify_new_user + field inside each individual request is ignored. requests (Sequence[~.analytics_admin.CreateUserLinkRequest]): - The requests specifying the user links to - create. A maximum of 1000 user links can be - created in a batch. + Required. The requests specifying the user + links to create. A maximum of 1000 user links + can be created in a batch. """ parent = proto.Field(proto.STRING, number=1) @@ -538,7 +544,7 @@ class BatchCreateUserLinksRequest(proto.Message): notify_new_users = proto.Field(proto.BOOL, number=2) requests = proto.RepeatedField( - proto.MESSAGE, number=3, message=CreateUserLinkRequest, + proto.MESSAGE, number=3, message="CreateUserLinkRequest", ) @@ -577,15 +583,15 @@ class BatchUpdateUserLinksRequest(proto.Message): either be empty or match this field. Example format: accounts/1234 requests (Sequence[~.analytics_admin.UpdateUserLinkRequest]): - The requests specifying the user links to - update. A maximum of 1000 user links can be - updated in a batch. + Required. The requests specifying the user + links to update. A maximum of 1000 user links + can be updated in a batch. """ parent = proto.Field(proto.STRING, number=1) requests = proto.RepeatedField( - proto.MESSAGE, number=2, message=UpdateUserLinkRequest, + proto.MESSAGE, number=2, message="UpdateUserLinkRequest", ) @@ -625,15 +631,15 @@ class BatchDeleteUserLinksRequest(proto.Message): match this field. Example format: accounts/1234 requests (Sequence[~.analytics_admin.DeleteUserLinkRequest]): - The requests specifying the user links to - update. A maximum of 1000 user links can be - updated in a batch. + Required. The requests specifying the user + links to update. A maximum of 1000 user links + can be updated in a batch. """ parent = proto.Field(proto.STRING, number=1) requests = proto.RepeatedField( - proto.MESSAGE, number=2, message=DeleteUserLinkRequest, + proto.MESSAGE, number=2, message="DeleteUserLinkRequest", ) @@ -995,6 +1001,7 @@ class GetEnhancedMeasurementSettingsRequest(proto.Message): Attributes: name (str): Required. The name of the settings to lookup. Format: + properties/{property_id}/webDataStreams/{stream_id}/enhancedMeasurementSettings Example: "properties/1000/webDataStreams/2000/enhancedMeasurementSettings". @@ -1222,4 +1229,53 @@ class GetDataSharingSettingsRequest(proto.Message): name = proto.Field(proto.STRING, number=1) +class ListAccountSummariesRequest(proto.Message): + r"""Request message for ListAccountSummaries RPC. + + Attributes: + page_size (int): + The maximum number of AccountSummary + resources to return. The service may return + fewer than this value, even if there are + additional pages. If unspecified, at most 50 + resources will be returned. The maximum value is + 200; (higher values will be coerced to the + maximum) + page_token (str): + A page token, received from a previous + ``ListAccountSummaries`` call. Provide this to retrieve the + subsequent page. When paginating, all other parameters + provided to ``ListAccountSummaries`` must match the call + that provided the page token. + """ + + page_size = proto.Field(proto.INT32, number=1) + + page_token = proto.Field(proto.STRING, number=2) + + +class ListAccountSummariesResponse(proto.Message): + r"""Response message for ListAccountSummaries RPC. + + Attributes: + account_summaries (Sequence[~.resources.AccountSummary]): + Account summaries of all accounts the caller + has access to. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + """ + + @property + def raw_page(self): + return self + + account_summaries = proto.RepeatedField( + proto.MESSAGE, number=1, message=resources.AccountSummary, + ) + + next_page_token = proto.Field(proto.STRING, number=2) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/resources.py b/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/resources.py index 4f8e1c4b4590..50a1800bbaa6 100644 --- a/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/resources.py +++ b/packages/google-analytics-admin/google/analytics/admin_v1alpha/types/resources.py @@ -25,8 +25,8 @@ __protobuf__ = proto.module( package="google.analytics.admin.v1alpha", manifest={ - "IndustryCategory", "MaximumUserAccess", + "IndustryCategory", "Account", "Property", "AndroidAppDataStream", @@ -39,10 +39,23 @@ "GlobalSiteTag", "GoogleAdsLink", "DataSharingSettings", + "AccountSummary", + "PropertySummary", }, ) +class MaximumUserAccess(proto.Enum): + r"""Maximum access settings that Firebase user receive on the + linked Analytics property. + """ + MAXIMUM_USER_ACCESS_UNSPECIFIED = 0 + NO_ACCESS = 1 + READ_AND_ANALYZE = 2 + EDITOR_WITHOUT_LINK_MANAGEMENT = 3 + EDITOR_INCLUDING_LINK_MANAGEMENT = 4 + + class IndustryCategory(proto.Enum): r"""The category selected for this property, used for industry benchmarking. @@ -76,17 +89,6 @@ class IndustryCategory(proto.Enum): SHOPPING = 26 -class MaximumUserAccess(proto.Enum): - r"""Maximum access settings that Firebase user receive on the - linked Analytics property. - """ - MAXIMUM_USER_ACCESS_UNSPECIFIED = 0 - NO_ACCESS = 1 - READ_AND_ANALYZE = 2 - EDITOR_WITHOUT_LINK_MANAGEMENT = 3 - EDITOR_INCLUDING_LINK_MANAGEMENT = 4 - - class Account(proto.Message): r"""A resource message representing a Google Analytics account. @@ -107,7 +109,9 @@ class Account(proto.Message): country_code (str): Country of business. Must be a non-deprecated code for a UN M.49 region. - https://unicode.org/cldr/charts/latest/supplemental/territory_containment_un_m_49.html + + https: //unicode.org/cldr/charts/latest/supplem // + ental/territory_containment_un_m_49.html deleted (bool): Output only. Indicates whether this Account is soft-deleted or not. Deleted accounts are @@ -129,7 +133,7 @@ class Account(proto.Message): class Property(proto.Message): - r"""A resource message representing a Google Analytics App+Web + r"""A resource message representing a Google Analytics GA4 property. Attributes: @@ -406,6 +410,7 @@ class EnhancedMeasurementSettings(proto.Message): Attributes: name (str): Output only. Resource name of this Data Stream. Format: + properties/{property_id}/webDataStreams/{stream_id}/enhancedMeasurementSettings Example: "properties/1000/webDataStreams/2000/enhancedMeasurementSettings". @@ -518,7 +523,7 @@ class EnhancedMeasurementSettings(proto.Message): class FirebaseLink(proto.Message): - r"""A link between an App+Web property and a Firebase project. + r"""A link between an GA4 property and a Firebase project. Attributes: name (str): @@ -536,7 +541,7 @@ class FirebaseLink(proto.Message): Output only. Time when this FirebaseLink was originally created. maximum_user_access (~.resources.MaximumUserAccess): - Maximum user access to the App + Web property + Maximum user access to the GA4 property allowed to admins of the linked Firebase project. """ @@ -559,13 +564,17 @@ class GlobalSiteTag(proto.Message): Immutable. JavaScript code snippet to be pasted as the first item into the head tag of every webpage to measure. + name (str): + The resource name of this tag. """ snippet = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=2) + class GoogleAdsLink(proto.Message): - r"""A link between an App+Web property and a Google Ads account. + r"""A link between an GA4 property and a Google Ads account. Attributes: name (str): @@ -663,4 +672,53 @@ class DataSharingSettings(proto.Message): sharing_with_others_enabled = proto.Field(proto.BOOL, number=6) +class AccountSummary(proto.Message): + r"""A virtual resource representing an overview of an account and + all its child GA4 properties. + + Attributes: + name (str): + Resource name for this account summary. Format: + accountSummaries/{account_id} Example: + "accountSummaries/1000". + account (str): + Resource name of account referred to by this account summary + Format: accounts/{account_id} Example: "accounts/1000". + display_name (str): + Display name for the account referred to in + this account summary. + property_summaries (Sequence[~.resources.PropertySummary]): + List of summaries for child accounts of this + account. + """ + + name = proto.Field(proto.STRING, number=1) + + account = proto.Field(proto.STRING, number=2) + + display_name = proto.Field(proto.STRING, number=3) + + property_summaries = proto.RepeatedField( + proto.MESSAGE, number=4, message="PropertySummary", + ) + + +class PropertySummary(proto.Message): + r"""A virtual resource representing metadata for an GA4 property. + + Attributes: + property (str): + Resource name of property referred to by this property + summary Format: properties/{property_id} Example: + "properties/1000". + display_name (str): + Display name for the property referred to in + this account summary. + """ + + property = proto.Field(proto.STRING, number=1) + + display_name = proto.Field(proto.STRING, number=2) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-analytics-admin/noxfile.py b/packages/google-analytics-admin/noxfile.py index 28579683cd2b..a57e24be11e3 100644 --- a/packages/google-analytics-admin/noxfile.py +++ b/packages/google-analytics-admin/noxfile.py @@ -28,7 +28,7 @@ DEFAULT_PYTHON_VERSION = "3.8" SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] -UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8"] +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] @nox.session(python=DEFAULT_PYTHON_VERSION) @@ -72,16 +72,17 @@ def default(session): # Install all test dependencies, then install this package in-place. session.install("asyncmock", "pytest-asyncio") - session.install("mock", "pytest", "pytest-cov") + session.install( + "mock", "pytest", "pytest-cov", + ) session.install("-e", ".") # Run py.test against the unit tests. session.run( "py.test", "--quiet", - "--cov=google.analytics.admin", - "--cov=google.analytics", - "--cov=tests.unit", + "--cov=google/cloud", + "--cov=tests/unit", "--cov-append", "--cov-config=.coveragerc", "--cov-report=", @@ -102,6 +103,10 @@ def system(session): """Run the system test suite.""" system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") + + # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. + if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": + session.skip("RUN_SYSTEM_TESTS is set to false, skipping") # Sanity check: Only run tests if the environment variable is set. if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): session.skip("Credentials must be set via environment variable") @@ -162,3 +167,38 @@ def docs(session): os.path.join("docs", ""), os.path.join("docs", "_build", "html", ""), ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def docfx(session): + """Build the docfx yaml files for this library.""" + + session.install("-e", ".") + # sphinx-docfx-yaml supports up to sphinx version 1.5.5. + # https://github.com/docascode/sphinx-docfx-yaml/issues/97 + session.install("sphinx==1.5.5", "alabaster", "recommonmark", "sphinx-docfx-yaml") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-T", # show full traceback on exception + "-N", # no colors + "-D", + ( + "extensions=sphinx.ext.autodoc," + "sphinx.ext.autosummary," + "docfx_yaml.extension," + "sphinx.ext.intersphinx," + "sphinx.ext.coverage," + "sphinx.ext.napoleon," + "sphinx.ext.todo," + "sphinx.ext.viewcode," + "recommonmark" + ), + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) diff --git a/packages/google-analytics-admin/scripts/decrypt-secrets.sh b/packages/google-analytics-admin/scripts/decrypt-secrets.sh index ff599eb2af25..21f6d2a26d90 100755 --- a/packages/google-analytics-admin/scripts/decrypt-secrets.sh +++ b/packages/google-analytics-admin/scripts/decrypt-secrets.sh @@ -20,14 +20,27 @@ ROOT=$( dirname "$DIR" ) # Work from the project root. cd $ROOT +# Prevent it from overriding files. +# We recommend that sample authors use their own service account files and cloud project. +# In that case, they are supposed to prepare these files by themselves. +if [[ -f "testing/test-env.sh" ]] || \ + [[ -f "testing/service-account.json" ]] || \ + [[ -f "testing/client-secrets.json" ]]; then + echo "One or more target files exist, aborting." + exit 1 +fi + # Use SECRET_MANAGER_PROJECT if set, fallback to cloud-devrel-kokoro-resources. PROJECT_ID="${SECRET_MANAGER_PROJECT:-cloud-devrel-kokoro-resources}" gcloud secrets versions access latest --secret="python-docs-samples-test-env" \ + --project="${PROJECT_ID}" \ > testing/test-env.sh gcloud secrets versions access latest \ --secret="python-docs-samples-service-account" \ + --project="${PROJECT_ID}" \ > testing/service-account.json gcloud secrets versions access latest \ --secret="python-docs-samples-client-secrets" \ - > testing/client-secrets.json \ No newline at end of file + --project="${PROJECT_ID}" \ + > testing/client-secrets.json diff --git a/packages/google-analytics-admin/scripts/fixup_admin_v1alpha_keywords.py b/packages/google-analytics-admin/scripts/fixup_admin_v1alpha_keywords.py index d3883208ef99..dbd7487e5e72 100644 --- a/packages/google-analytics-admin/scripts/fixup_admin_v1alpha_keywords.py +++ b/packages/google-analytics-admin/scripts/fixup_admin_v1alpha_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC @@ -41,7 +42,7 @@ class adminCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { 'audit_user_links': ('parent', 'page_size', 'page_token', ), - 'batch_create_user_links': ('parent', 'notify_new_users', 'requests', ), + 'batch_create_user_links': ('parent', 'requests', 'notify_new_users', ), 'batch_delete_user_links': ('parent', 'requests', ), 'batch_get_user_links': ('parent', 'names', ), 'batch_update_user_links': ('parent', 'requests', ), @@ -70,6 +71,7 @@ class adminCallTransformer(cst.CSTTransformer): 'get_user_link': ('name', ), 'get_web_data_stream': ('name', ), 'list_accounts': ('page_size', 'page_token', 'show_deleted', ), + 'list_account_summaries': ('page_size', 'page_token', ), 'list_android_app_data_streams': ('parent', 'page_size', 'page_token', ), 'list_firebase_links': ('parent', ), 'list_google_ads_links': ('parent', 'page_size', 'page_token', ), diff --git a/packages/google-analytics-admin/setup.py b/packages/google-analytics-admin/setup.py index 6c7cfd4c1add..29455cfb8ea8 100644 --- a/packages/google-analytics-admin/setup.py +++ b/packages/google-analytics-admin/setup.py @@ -41,12 +41,10 @@ platforms="Posix; MacOS X; Windows", include_package_data=True, install_requires=( - "google-api-core[grpc] >= 1.22.0, < 2.0.0dev", - "libcst >= 0.2.5", - "proto-plus >= 1.3.2", + "google-api-core[grpc] >= 1.22.2, < 2.0.0dev", + "proto-plus >= 1.4.0", ), python_requires=">=3.6", - scripts=["scripts/fixup_admin_v1alpha_keywords.py",], classifiers=[ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", diff --git a/packages/google-analytics-admin/synth.metadata b/packages/google-analytics-admin/synth.metadata index 51409445e324..cecd5f6e7efb 100644 --- a/packages/google-analytics-admin/synth.metadata +++ b/packages/google-analytics-admin/synth.metadata @@ -3,22 +3,30 @@ { "git": { "name": ".", - "remote": "git@github.com:googleapis/python-analytics-admin", - "sha": "37c5c6a341bd2df94953cd6dd7ac22033dd5dc7d" + "remote": "https://github.com/googleapis/python-analytics-admin.git", + "sha": "0f4e3821619fff948ae1173ce149c6beca22318d" + } + }, + { + "git": { + "name": "googleapis", + "remote": "https://github.com/googleapis/googleapis.git", + "sha": "69697504d9eba1d064820c3085b4750767be6d08", + "internalRef": "348952930" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "d07b7b7afa718686db7b095317f608a2f1b6b1cb" + "sha": "373861061648b5fe5e0ac4f8a38b32d639ee93e4" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "d07b7b7afa718686db7b095317f608a2f1b6b1cb" + "sha": "373861061648b5fe5e0ac4f8a38b32d639ee93e4" } } ], @@ -32,5 +40,93 @@ "generator": "bazel" } } + ], + "generatedFiles": [ + ".flake8", + ".github/CONTRIBUTING.md", + ".github/ISSUE_TEMPLATE/bug_report.md", + ".github/ISSUE_TEMPLATE/feature_request.md", + ".github/ISSUE_TEMPLATE/support_request.md", + ".github/PULL_REQUEST_TEMPLATE.md", + ".github/release-please.yml", + ".github/snippet-bot.yml", + ".gitignore", + ".kokoro/build.sh", + ".kokoro/continuous/common.cfg", + ".kokoro/continuous/continuous.cfg", + ".kokoro/docker/docs/Dockerfile", + ".kokoro/docker/docs/fetch_gpg_keys.sh", + ".kokoro/docs/common.cfg", + ".kokoro/docs/docs-presubmit.cfg", + ".kokoro/docs/docs.cfg", + ".kokoro/populate-secrets.sh", + ".kokoro/presubmit/common.cfg", + ".kokoro/presubmit/presubmit.cfg", + ".kokoro/publish-docs.sh", + ".kokoro/release.sh", + ".kokoro/release/common.cfg", + ".kokoro/release/release.cfg", + ".kokoro/samples/lint/common.cfg", + ".kokoro/samples/lint/continuous.cfg", + ".kokoro/samples/lint/periodic.cfg", + ".kokoro/samples/lint/presubmit.cfg", + ".kokoro/samples/python3.6/common.cfg", + ".kokoro/samples/python3.6/continuous.cfg", + ".kokoro/samples/python3.6/periodic.cfg", + ".kokoro/samples/python3.6/presubmit.cfg", + ".kokoro/samples/python3.7/common.cfg", + ".kokoro/samples/python3.7/continuous.cfg", + ".kokoro/samples/python3.7/periodic.cfg", + ".kokoro/samples/python3.7/presubmit.cfg", + ".kokoro/samples/python3.8/common.cfg", + ".kokoro/samples/python3.8/continuous.cfg", + ".kokoro/samples/python3.8/periodic.cfg", + ".kokoro/samples/python3.8/presubmit.cfg", + ".kokoro/test-samples.sh", + ".kokoro/trampoline.sh", + ".kokoro/trampoline_v2.sh", + ".pre-commit-config.yaml", + ".trampolinerc", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.rst", + "LICENSE", + "MANIFEST.in", + "docs/_static/custom.css", + "docs/_templates/layout.html", + "docs/admin_v1alpha/services.rst", + "docs/admin_v1alpha/types.rst", + "docs/conf.py", + "docs/multiprocessing.rst", + "google/analytics/admin/__init__.py", + "google/analytics/admin/py.typed", + "google/analytics/admin_v1alpha/__init__.py", + "google/analytics/admin_v1alpha/py.typed", + "google/analytics/admin_v1alpha/services/__init__.py", + "google/analytics/admin_v1alpha/services/analytics_admin_service/__init__.py", + "google/analytics/admin_v1alpha/services/analytics_admin_service/async_client.py", + "google/analytics/admin_v1alpha/services/analytics_admin_service/client.py", + "google/analytics/admin_v1alpha/services/analytics_admin_service/pagers.py", + "google/analytics/admin_v1alpha/services/analytics_admin_service/transports/__init__.py", + "google/analytics/admin_v1alpha/services/analytics_admin_service/transports/base.py", + "google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc.py", + "google/analytics/admin_v1alpha/services/analytics_admin_service/transports/grpc_asyncio.py", + "google/analytics/admin_v1alpha/types/__init__.py", + "google/analytics/admin_v1alpha/types/analytics_admin.py", + "google/analytics/admin_v1alpha/types/resources.py", + "mypy.ini", + "noxfile.py", + "renovate.json", + "scripts/decrypt-secrets.sh", + "scripts/fixup_admin_v1alpha_keywords.py", + "scripts/readme-gen/readme_gen.py", + "scripts/readme-gen/templates/README.tmpl.rst", + "scripts/readme-gen/templates/auth.tmpl.rst", + "scripts/readme-gen/templates/auth_api_key.tmpl.rst", + "scripts/readme-gen/templates/install_deps.tmpl.rst", + "scripts/readme-gen/templates/install_portaudio.tmpl.rst", + "setup.cfg", + "testing/.gitignore", + "tests/unit/gapic/admin_v1alpha/__init__.py", + "tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py" ] } \ No newline at end of file diff --git a/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/__init__.py b/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/__init__.py new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/__init__.py @@ -0,0 +1 @@ + diff --git a/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py b/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py index b4bca36d9cb5..c1572f538b63 100644 --- a/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py +++ b/packages/google-analytics-admin/tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py @@ -52,6 +52,17 @@ def client_cert_source_callback(): return b"cert bytes", b"key bytes" +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -92,12 +103,12 @@ def test_analytics_admin_service_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "analyticsadmin.googleapis.com:443" + assert client.transport._host == "analyticsadmin.googleapis.com:443" def test_analytics_admin_service_client_get_transport_class(): @@ -123,6 +134,16 @@ def test_analytics_admin_service_client_get_transport_class(): ), ], ) +@mock.patch.object( + AnalyticsAdminServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AnalyticsAdminServiceClient), +) +@mock.patch.object( + AnalyticsAdminServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AnalyticsAdminServiceAsyncClient), +) def test_analytics_admin_service_client_client_options( client_class, transport_class, transport_name ): @@ -147,14 +168,14 @@ def test_analytics_admin_service_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - api_mtls_endpoint="squid.clam.whelk", - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "never"}): + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class() @@ -163,14 +184,14 @@ def test_analytics_admin_service_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "always"}): + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class() @@ -179,90 +200,185 @@ def test_analytics_admin_service_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", and client_cert_source is provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class() + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class() + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + ssl_channel_credentials=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + AnalyticsAdminServiceClient, + transports.AnalyticsAdminServiceGrpcTransport, + "grpc", + "true", + ), + ( + AnalyticsAdminServiceAsyncClient, + transports.AnalyticsAdminServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + AnalyticsAdminServiceClient, + transports.AnalyticsAdminServiceGrpcTransport, + "grpc", + "false", + ), + ( + AnalyticsAdminServiceAsyncClient, + transports.AnalyticsAdminServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + AnalyticsAdminServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AnalyticsAdminServiceClient), +) +@mock.patch.object( + AnalyticsAdminServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(AnalyticsAdminServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_analytics_admin_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): options = client_options.ClientOptions( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=client_cert_source_callback, - quota_project_id=None, - ) - - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", and default_client_cert_source is provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): - with mock.patch.object(transport_class, "__init__") as patched: + ssl_channel_creds = mock.Mock() with mock.patch( - "google.auth.transport.mtls.has_default_client_cert_source", - return_value=True, + "grpc.ssl_channel_credentials", return_value=ssl_channel_creds ): patched.return_value = None - client = client_class() + client = client_class(client_options=options) + + if use_client_cert_env == "false": + expected_ssl_channel_creds = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_ssl_channel_creds = ssl_channel_creds + expected_host = client.DEFAULT_MTLS_ENDPOINT + patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, + host=expected_host, scopes=None, - api_mtls_endpoint=client.DEFAULT_MTLS_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=expected_ssl_channel_creds, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) - # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "auto", but client_cert_source and default_client_cert_source are None. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "auto"}): + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.mtls.has_default_client_cert_source", - return_value=False, + "google.auth.transport.grpc.SslCredentials.__init__", return_value=None ): - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, - quota_project_id=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class() - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, - quota_project_id="octopus", - ) + with mock.patch( + "google.auth.transport.grpc.SslCredentials.is_mtls", + new_callable=mock.PropertyMock, + ) as is_mtls_mock: + with mock.patch( + "google.auth.transport.grpc.SslCredentials.ssl_credentials", + new_callable=mock.PropertyMock, + ) as ssl_credentials_mock: + if use_client_cert_env == "false": + is_mtls_mock.return_value = False + ssl_credentials_mock.return_value = None + expected_host = client.DEFAULT_ENDPOINT + expected_ssl_channel_creds = None + else: + is_mtls_mock.return_value = True + ssl_credentials_mock.return_value = mock.Mock() + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_ssl_channel_creds = ( + ssl_credentials_mock.return_value + ) + + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + ssl_channel_credentials=expected_ssl_channel_creds, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + ): + with mock.patch( + "google.auth.transport.grpc.SslCredentials.is_mtls", + new_callable=mock.PropertyMock, + ) as is_mtls_mock: + is_mtls_mock.return_value = False + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + ssl_channel_credentials=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) @pytest.mark.parametrize( @@ -293,9 +409,9 @@ def test_analytics_admin_service_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -327,9 +443,9 @@ def test_analytics_admin_service_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - api_mtls_endpoint=client.DEFAULT_ENDPOINT, - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -346,23 +462,25 @@ def test_analytics_admin_service_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - api_mtls_endpoint="squid.clam.whelk", - client_cert_source=None, + ssl_channel_credentials=None, quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, ) -def test_get_account(transport: str = "grpc"): +def test_get_account( + transport: str = "grpc", request_type=analytics_admin.GetAccountRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetAccountRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_account), "__call__") as call: + with mock.patch.object(type(client.transport.get_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Account( name="name_value", @@ -377,9 +495,10 @@ def test_get_account(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetAccountRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Account) assert response.name == "name_value" @@ -391,20 +510,24 @@ def test_get_account(transport: str = "grpc"): assert response.deleted is True +def test_get_account_from_dict(): + test_get_account(request_type=dict) + + @pytest.mark.asyncio -async def test_get_account_async(transport: str = "grpc_asyncio"): +async def test_get_account_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.GetAccountRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetAccountRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Account( @@ -421,7 +544,7 @@ async def test_get_account_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetAccountRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Account) @@ -435,6 +558,11 @@ async def test_get_account_async(transport: str = "grpc_asyncio"): assert response.deleted is True +@pytest.mark.asyncio +async def test_get_account_async_from_dict(): + await test_get_account_async(request_type=dict) + + def test_get_account_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -446,7 +574,7 @@ def test_get_account_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_account), "__call__") as call: + with mock.patch.object(type(client.transport.get_account), "__call__") as call: call.return_value = resources.Account() client.get_account(request) @@ -473,9 +601,7 @@ async def test_get_account_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_account), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Account()) await client.get_account(request) @@ -496,7 +622,7 @@ def test_get_account_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_account), "__call__") as call: + with mock.patch.object(type(client.transport.get_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Account() @@ -532,9 +658,7 @@ async def test_get_account_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Account() @@ -565,17 +689,19 @@ async def test_get_account_flattened_error_async(): ) -def test_list_accounts(transport: str = "grpc"): +def test_list_accounts( + transport: str = "grpc", request_type=analytics_admin.ListAccountsRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListAccountsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_accounts), "__call__") as call: + with mock.patch.object(type(client.transport.list_accounts), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListAccountsResponse( next_page_token="next_page_token_value", @@ -587,28 +713,33 @@ def test_list_accounts(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListAccountsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAccountsPager) assert response.next_page_token == "next_page_token_value" +def test_list_accounts_from_dict(): + test_list_accounts(request_type=dict) + + @pytest.mark.asyncio -async def test_list_accounts_async(transport: str = "grpc_asyncio"): +async def test_list_accounts_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.ListAccountsRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListAccountsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_accounts), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_accounts), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListAccountsResponse( @@ -622,7 +753,7 @@ async def test_list_accounts_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListAccountsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAccountsAsyncPager) @@ -630,11 +761,16 @@ async def test_list_accounts_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_accounts_async_from_dict(): + await test_list_accounts_async(request_type=dict) + + def test_list_accounts_pager(): client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_accounts), "__call__") as call: + with mock.patch.object(type(client.transport.list_accounts), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( analytics_admin.ListAccountsResponse( @@ -669,7 +805,7 @@ def test_list_accounts_pages(): client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_accounts), "__call__") as call: + with mock.patch.object(type(client.transport.list_accounts), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( analytics_admin.ListAccountsResponse( @@ -690,8 +826,8 @@ def test_list_accounts_pages(): RuntimeError, ) pages = list(client.list_accounts(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -702,9 +838,7 @@ async def test_list_accounts_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_accounts), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_accounts), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -743,9 +877,7 @@ async def test_list_accounts_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_accounts), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_accounts), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -767,23 +899,25 @@ async def test_list_accounts_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_accounts(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_accounts(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_delete_account(transport: str = "grpc"): +def test_delete_account( + transport: str = "grpc", request_type=analytics_admin.DeleteAccountRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteAccountRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_account), "__call__") as call: + with mock.patch.object(type(client.transport.delete_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -793,26 +927,30 @@ def test_delete_account(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteAccountRequest() # Establish that the response is the type that we expect. assert response is None +def test_delete_account_from_dict(): + test_delete_account(request_type=dict) + + @pytest.mark.asyncio -async def test_delete_account_async(transport: str = "grpc_asyncio"): +async def test_delete_account_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.DeleteAccountRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteAccountRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -822,12 +960,17 @@ async def test_delete_account_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteAccountRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_account_async_from_dict(): + await test_delete_account_async(request_type=dict) + + def test_delete_account_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -839,7 +982,7 @@ def test_delete_account_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_account), "__call__") as call: + with mock.patch.object(type(client.transport.delete_account), "__call__") as call: call.return_value = None client.delete_account(request) @@ -866,9 +1009,7 @@ async def test_delete_account_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_account), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_account(request) @@ -889,7 +1030,7 @@ def test_delete_account_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_account), "__call__") as call: + with mock.patch.object(type(client.transport.delete_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -925,9 +1066,7 @@ async def test_delete_account_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -958,17 +1097,19 @@ async def test_delete_account_flattened_error_async(): ) -def test_update_account(transport: str = "grpc"): +def test_update_account( + transport: str = "grpc", request_type=analytics_admin.UpdateAccountRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateAccountRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_account), "__call__") as call: + with mock.patch.object(type(client.transport.update_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Account( name="name_value", @@ -983,9 +1124,10 @@ def test_update_account(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateAccountRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Account) assert response.name == "name_value" @@ -997,20 +1139,24 @@ def test_update_account(transport: str = "grpc"): assert response.deleted is True +def test_update_account_from_dict(): + test_update_account(request_type=dict) + + @pytest.mark.asyncio -async def test_update_account_async(transport: str = "grpc_asyncio"): +async def test_update_account_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.UpdateAccountRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateAccountRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Account( @@ -1027,7 +1173,7 @@ async def test_update_account_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateAccountRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Account) @@ -1041,6 +1187,11 @@ async def test_update_account_async(transport: str = "grpc_asyncio"): assert response.deleted is True +@pytest.mark.asyncio +async def test_update_account_async_from_dict(): + await test_update_account_async(request_type=dict) + + def test_update_account_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1052,7 +1203,7 @@ def test_update_account_field_headers(): request.account.name = "account.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_account), "__call__") as call: + with mock.patch.object(type(client.transport.update_account), "__call__") as call: call.return_value = resources.Account() client.update_account(request) @@ -1081,9 +1232,7 @@ async def test_update_account_field_headers_async(): request.account.name = "account.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_account), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Account()) await client.update_account(request) @@ -1106,7 +1255,7 @@ def test_update_account_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_account), "__call__") as call: + with mock.patch.object(type(client.transport.update_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Account() @@ -1149,9 +1298,7 @@ async def test_update_account_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_account), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_account), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Account() @@ -1189,18 +1336,20 @@ async def test_update_account_flattened_error_async(): ) -def test_provision_account_ticket(transport: str = "grpc"): +def test_provision_account_ticket( + transport: str = "grpc", request_type=analytics_admin.ProvisionAccountTicketRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ProvisionAccountTicketRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.provision_account_ticket), "__call__" + type(client.transport.provision_account_ticket), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ProvisionAccountTicketResponse( @@ -1213,27 +1362,35 @@ def test_provision_account_ticket(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ProvisionAccountTicketRequest() # Establish that the response is the type that we expect. + assert isinstance(response, analytics_admin.ProvisionAccountTicketResponse) assert response.account_ticket_id == "account_ticket_id_value" +def test_provision_account_ticket_from_dict(): + test_provision_account_ticket(request_type=dict) + + @pytest.mark.asyncio -async def test_provision_account_ticket_async(transport: str = "grpc_asyncio"): +async def test_provision_account_ticket_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.ProvisionAccountTicketRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ProvisionAccountTicketRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.provision_account_ticket), "__call__" + type(client.transport.provision_account_ticket), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1248,7 +1405,7 @@ async def test_provision_account_ticket_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ProvisionAccountTicketRequest() # Establish that the response is the type that we expect. assert isinstance(response, analytics_admin.ProvisionAccountTicketResponse) @@ -1256,111 +1413,377 @@ async def test_provision_account_ticket_async(transport: str = "grpc_asyncio"): assert response.account_ticket_id == "account_ticket_id_value" -def test_get_property(transport: str = "grpc"): +@pytest.mark.asyncio +async def test_provision_account_ticket_async_from_dict(): + await test_provision_account_ticket_async(request_type=dict) + + +def test_list_account_summaries( + transport: str = "grpc", request_type=analytics_admin.ListAccountSummariesRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetPropertyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_property), "__call__") as call: + with mock.patch.object( + type(client.transport.list_account_summaries), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = resources.Property( - name="name_value", - parent="parent_value", - display_name="display_name_value", - industry_category=resources.IndustryCategory.AUTOMOTIVE, - time_zone="time_zone_value", - currency_code="currency_code_value", - deleted=True, + call.return_value = analytics_admin.ListAccountSummariesResponse( + next_page_token="next_page_token_value", ) - response = client.get_property(request) + response = client.list_account_summaries(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListAccountSummariesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Property) - - assert response.name == "name_value" - assert response.parent == "parent_value" - - assert response.display_name == "display_name_value" - - assert response.industry_category == resources.IndustryCategory.AUTOMOTIVE + assert isinstance(response, pagers.ListAccountSummariesPager) - assert response.time_zone == "time_zone_value" + assert response.next_page_token == "next_page_token_value" - assert response.currency_code == "currency_code_value" - assert response.deleted is True +def test_list_account_summaries_from_dict(): + test_list_account_summaries(request_type=dict) @pytest.mark.asyncio -async def test_get_property_async(transport: str = "grpc_asyncio"): +async def test_list_account_summaries_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.ListAccountSummariesRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetPropertyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_property), "__call__" + type(client.transport.list_account_summaries), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.Property( - name="name_value", - parent="parent_value", - display_name="display_name_value", - industry_category=resources.IndustryCategory.AUTOMOTIVE, - time_zone="time_zone_value", - currency_code="currency_code_value", - deleted=True, + analytics_admin.ListAccountSummariesResponse( + next_page_token="next_page_token_value", ) ) - response = await client.get_property(request) + response = await client.list_account_summaries(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListAccountSummariesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Property) + assert isinstance(response, pagers.ListAccountSummariesAsyncPager) - assert response.name == "name_value" + assert response.next_page_token == "next_page_token_value" - assert response.parent == "parent_value" - assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_list_account_summaries_async_from_dict(): + await test_list_account_summaries_async(request_type=dict) - assert response.industry_category == resources.IndustryCategory.AUTOMOTIVE - assert response.time_zone == "time_zone_value" +def test_list_account_summaries_pager(): + client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) - assert response.currency_code == "currency_code_value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_account_summaries), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + analytics_admin.ListAccountSummariesResponse( + account_summaries=[ + resources.AccountSummary(), + resources.AccountSummary(), + resources.AccountSummary(), + ], + next_page_token="abc", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[], next_page_token="def", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[resources.AccountSummary(),], next_page_token="ghi", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[ + resources.AccountSummary(), + resources.AccountSummary(), + ], + ), + RuntimeError, + ) - assert response.deleted is True + metadata = () + pager = client.list_account_summaries(request={}) + assert pager._metadata == metadata -def test_get_property_field_headers(): - client = AnalyticsAdminServiceClient( - credentials=credentials.AnonymousCredentials(), - ) + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, resources.AccountSummary) for i in results) + + +def test_list_account_summaries_pages(): + client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_account_summaries), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + analytics_admin.ListAccountSummariesResponse( + account_summaries=[ + resources.AccountSummary(), + resources.AccountSummary(), + resources.AccountSummary(), + ], + next_page_token="abc", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[], next_page_token="def", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[resources.AccountSummary(),], next_page_token="ghi", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[ + resources.AccountSummary(), + resources.AccountSummary(), + ], + ), + RuntimeError, + ) + pages = list(client.list_account_summaries(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_account_summaries_async_pager(): + client = AnalyticsAdminServiceAsyncClient( + credentials=credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_account_summaries), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + analytics_admin.ListAccountSummariesResponse( + account_summaries=[ + resources.AccountSummary(), + resources.AccountSummary(), + resources.AccountSummary(), + ], + next_page_token="abc", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[], next_page_token="def", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[resources.AccountSummary(),], next_page_token="ghi", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[ + resources.AccountSummary(), + resources.AccountSummary(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_account_summaries(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, resources.AccountSummary) for i in responses) + + +@pytest.mark.asyncio +async def test_list_account_summaries_async_pages(): + client = AnalyticsAdminServiceAsyncClient( + credentials=credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_account_summaries), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + analytics_admin.ListAccountSummariesResponse( + account_summaries=[ + resources.AccountSummary(), + resources.AccountSummary(), + resources.AccountSummary(), + ], + next_page_token="abc", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[], next_page_token="def", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[resources.AccountSummary(),], next_page_token="ghi", + ), + analytics_admin.ListAccountSummariesResponse( + account_summaries=[ + resources.AccountSummary(), + resources.AccountSummary(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_account_summaries(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_property( + transport: str = "grpc", request_type=analytics_admin.GetPropertyRequest +): + client = AnalyticsAdminServiceClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_property), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = resources.Property( + name="name_value", + parent="parent_value", + display_name="display_name_value", + industry_category=resources.IndustryCategory.AUTOMOTIVE, + time_zone="time_zone_value", + currency_code="currency_code_value", + deleted=True, + ) + + response = client.get_property(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_admin.GetPropertyRequest() + + # Establish that the response is the type that we expect. + + assert isinstance(response, resources.Property) + + assert response.name == "name_value" + + assert response.parent == "parent_value" + + assert response.display_name == "display_name_value" + + assert response.industry_category == resources.IndustryCategory.AUTOMOTIVE + + assert response.time_zone == "time_zone_value" + + assert response.currency_code == "currency_code_value" + + assert response.deleted is True + + +def test_get_property_from_dict(): + test_get_property(request_type=dict) + + +@pytest.mark.asyncio +async def test_get_property_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.GetPropertyRequest +): + client = AnalyticsAdminServiceAsyncClient( + credentials=credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_property), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + resources.Property( + name="name_value", + parent="parent_value", + display_name="display_name_value", + industry_category=resources.IndustryCategory.AUTOMOTIVE, + time_zone="time_zone_value", + currency_code="currency_code_value", + deleted=True, + ) + ) + + response = await client.get_property(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_admin.GetPropertyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, resources.Property) + + assert response.name == "name_value" + + assert response.parent == "parent_value" + + assert response.display_name == "display_name_value" + + assert response.industry_category == resources.IndustryCategory.AUTOMOTIVE + + assert response.time_zone == "time_zone_value" + + assert response.currency_code == "currency_code_value" + + assert response.deleted is True + + +@pytest.mark.asyncio +async def test_get_property_async_from_dict(): + await test_get_property_async(request_type=dict) + + +def test_get_property_field_headers(): + client = AnalyticsAdminServiceClient( + credentials=credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -1368,7 +1791,7 @@ def test_get_property_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_property), "__call__") as call: + with mock.patch.object(type(client.transport.get_property), "__call__") as call: call.return_value = resources.Property() client.get_property(request) @@ -1395,9 +1818,7 @@ async def test_get_property_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_property), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Property()) await client.get_property(request) @@ -1418,7 +1839,7 @@ def test_get_property_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_property), "__call__") as call: + with mock.patch.object(type(client.transport.get_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Property() @@ -1454,9 +1875,7 @@ async def test_get_property_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Property() @@ -1487,17 +1906,19 @@ async def test_get_property_flattened_error_async(): ) -def test_list_properties(transport: str = "grpc"): +def test_list_properties( + transport: str = "grpc", request_type=analytics_admin.ListPropertiesRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListPropertiesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_properties), "__call__") as call: + with mock.patch.object(type(client.transport.list_properties), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListPropertiesResponse( next_page_token="next_page_token_value", @@ -1509,28 +1930,33 @@ def test_list_properties(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListPropertiesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListPropertiesPager) assert response.next_page_token == "next_page_token_value" +def test_list_properties_from_dict(): + test_list_properties(request_type=dict) + + @pytest.mark.asyncio -async def test_list_properties_async(transport: str = "grpc_asyncio"): +async def test_list_properties_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.ListPropertiesRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListPropertiesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_properties), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_properties), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListPropertiesResponse( @@ -1544,7 +1970,7 @@ async def test_list_properties_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListPropertiesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListPropertiesAsyncPager) @@ -1552,11 +1978,16 @@ async def test_list_properties_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_properties_async_from_dict(): + await test_list_properties_async(request_type=dict) + + def test_list_properties_pager(): client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_properties), "__call__") as call: + with mock.patch.object(type(client.transport.list_properties), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( analytics_admin.ListPropertiesResponse( @@ -1593,7 +2024,7 @@ def test_list_properties_pages(): client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_properties), "__call__") as call: + with mock.patch.object(type(client.transport.list_properties), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( analytics_admin.ListPropertiesResponse( @@ -1616,8 +2047,8 @@ def test_list_properties_pages(): RuntimeError, ) pages = list(client.list_properties(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -1628,9 +2059,7 @@ async def test_list_properties_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_properties), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_properties), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1671,9 +2100,7 @@ async def test_list_properties_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_properties), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_properties), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1697,23 +2124,25 @@ async def test_list_properties_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_properties(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_properties(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_create_property(transport: str = "grpc"): +def test_create_property( + transport: str = "grpc", request_type=analytics_admin.CreatePropertyRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreatePropertyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_property), "__call__") as call: + with mock.patch.object(type(client.transport.create_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Property( name="name_value", @@ -1731,9 +2160,10 @@ def test_create_property(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreatePropertyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Property) assert response.name == "name_value" @@ -1751,20 +2181,24 @@ def test_create_property(transport: str = "grpc"): assert response.deleted is True +def test_create_property_from_dict(): + test_create_property(request_type=dict) + + @pytest.mark.asyncio -async def test_create_property_async(transport: str = "grpc_asyncio"): +async def test_create_property_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.CreatePropertyRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreatePropertyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Property( @@ -1784,7 +2218,7 @@ async def test_create_property_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreatePropertyRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Property) @@ -1804,13 +2238,18 @@ async def test_create_property_async(transport: str = "grpc_asyncio"): assert response.deleted is True +@pytest.mark.asyncio +async def test_create_property_async_from_dict(): + await test_create_property_async(request_type=dict) + + def test_create_property_flattened(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_property), "__call__") as call: + with mock.patch.object(type(client.transport.create_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Property() @@ -1847,9 +2286,7 @@ async def test_create_property_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Property() @@ -1883,17 +2320,19 @@ async def test_create_property_flattened_error_async(): ) -def test_delete_property(transport: str = "grpc"): +def test_delete_property( + transport: str = "grpc", request_type=analytics_admin.DeletePropertyRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeletePropertyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_property), "__call__") as call: + with mock.patch.object(type(client.transport.delete_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1903,26 +2342,30 @@ def test_delete_property(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeletePropertyRequest() # Establish that the response is the type that we expect. assert response is None +def test_delete_property_from_dict(): + test_delete_property(request_type=dict) + + @pytest.mark.asyncio -async def test_delete_property_async(transport: str = "grpc_asyncio"): +async def test_delete_property_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.DeletePropertyRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeletePropertyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1932,12 +2375,17 @@ async def test_delete_property_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeletePropertyRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_property_async_from_dict(): + await test_delete_property_async(request_type=dict) + + def test_delete_property_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -1949,7 +2397,7 @@ def test_delete_property_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_property), "__call__") as call: + with mock.patch.object(type(client.transport.delete_property), "__call__") as call: call.return_value = None client.delete_property(request) @@ -1976,9 +2424,7 @@ async def test_delete_property_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_property), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_property(request) @@ -1999,7 +2445,7 @@ def test_delete_property_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_property), "__call__") as call: + with mock.patch.object(type(client.transport.delete_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2035,9 +2481,7 @@ async def test_delete_property_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -2068,17 +2512,19 @@ async def test_delete_property_flattened_error_async(): ) -def test_update_property(transport: str = "grpc"): +def test_update_property( + transport: str = "grpc", request_type=analytics_admin.UpdatePropertyRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdatePropertyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_property), "__call__") as call: + with mock.patch.object(type(client.transport.update_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Property( name="name_value", @@ -2096,9 +2542,10 @@ def test_update_property(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdatePropertyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.Property) assert response.name == "name_value" @@ -2116,20 +2563,24 @@ def test_update_property(transport: str = "grpc"): assert response.deleted is True +def test_update_property_from_dict(): + test_update_property(request_type=dict) + + @pytest.mark.asyncio -async def test_update_property_async(transport: str = "grpc_asyncio"): +async def test_update_property_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.UpdatePropertyRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdatePropertyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.Property( @@ -2149,7 +2600,7 @@ async def test_update_property_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdatePropertyRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Property) @@ -2169,6 +2620,11 @@ async def test_update_property_async(transport: str = "grpc_asyncio"): assert response.deleted is True +@pytest.mark.asyncio +async def test_update_property_async_from_dict(): + await test_update_property_async(request_type=dict) + + def test_update_property_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2180,7 +2636,7 @@ def test_update_property_field_headers(): request.property.name = "property.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_property), "__call__") as call: + with mock.patch.object(type(client.transport.update_property), "__call__") as call: call.return_value = resources.Property() client.update_property(request) @@ -2209,9 +2665,7 @@ async def test_update_property_field_headers_async(): request.property.name = "property.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_property), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.Property()) await client.update_property(request) @@ -2234,7 +2688,7 @@ def test_update_property_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_property), "__call__") as call: + with mock.patch.object(type(client.transport.update_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Property() @@ -2277,9 +2731,7 @@ async def test_update_property_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_property), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_property), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.Property() @@ -2317,17 +2769,19 @@ async def test_update_property_flattened_error_async(): ) -def test_get_user_link(transport: str = "grpc"): +def test_get_user_link( + transport: str = "grpc", request_type=analytics_admin.GetUserLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetUserLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_user_link), "__call__") as call: + with mock.patch.object(type(client.transport.get_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink( name="name_value", @@ -2341,9 +2795,10 @@ def test_get_user_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetUserLinkRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.UserLink) assert response.name == "name_value" @@ -2353,20 +2808,24 @@ def test_get_user_link(transport: str = "grpc"): assert response.direct_roles == ["direct_roles_value"] +def test_get_user_link_from_dict(): + test_get_user_link(request_type=dict) + + @pytest.mark.asyncio -async def test_get_user_link_async(transport: str = "grpc_asyncio"): +async def test_get_user_link_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.GetUserLinkRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetUserLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.UserLink( @@ -2382,7 +2841,7 @@ async def test_get_user_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetUserLinkRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.UserLink) @@ -2394,6 +2853,11 @@ async def test_get_user_link_async(transport: str = "grpc_asyncio"): assert response.direct_roles == ["direct_roles_value"] +@pytest.mark.asyncio +async def test_get_user_link_async_from_dict(): + await test_get_user_link_async(request_type=dict) + + def test_get_user_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2405,7 +2869,7 @@ def test_get_user_link_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_user_link), "__call__") as call: + with mock.patch.object(type(client.transport.get_user_link), "__call__") as call: call.return_value = resources.UserLink() client.get_user_link(request) @@ -2432,9 +2896,7 @@ async def test_get_user_link_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_user_link), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.UserLink()) await client.get_user_link(request) @@ -2455,7 +2917,7 @@ def test_get_user_link_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_user_link), "__call__") as call: + with mock.patch.object(type(client.transport.get_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink() @@ -2491,9 +2953,7 @@ async def test_get_user_link_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink() @@ -2524,18 +2984,20 @@ async def test_get_user_link_flattened_error_async(): ) -def test_batch_get_user_links(transport: str = "grpc"): +def test_batch_get_user_links( + transport: str = "grpc", request_type=analytics_admin.BatchGetUserLinksRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.BatchGetUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_get_user_links), "__call__" + type(client.transport.batch_get_user_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.BatchGetUserLinksResponse() @@ -2546,25 +3008,33 @@ def test_batch_get_user_links(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.BatchGetUserLinksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, analytics_admin.BatchGetUserLinksResponse) +def test_batch_get_user_links_from_dict(): + test_batch_get_user_links(request_type=dict) + + @pytest.mark.asyncio -async def test_batch_get_user_links_async(transport: str = "grpc_asyncio"): +async def test_batch_get_user_links_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.BatchGetUserLinksRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.BatchGetUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_get_user_links), "__call__" + type(client.transport.batch_get_user_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2577,12 +3047,17 @@ async def test_batch_get_user_links_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.BatchGetUserLinksRequest() # Establish that the response is the type that we expect. assert isinstance(response, analytics_admin.BatchGetUserLinksResponse) +@pytest.mark.asyncio +async def test_batch_get_user_links_async_from_dict(): + await test_batch_get_user_links_async(request_type=dict) + + def test_batch_get_user_links_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2595,7 +3070,7 @@ def test_batch_get_user_links_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_get_user_links), "__call__" + type(client.transport.batch_get_user_links), "__call__" ) as call: call.return_value = analytics_admin.BatchGetUserLinksResponse() @@ -2624,7 +3099,7 @@ async def test_batch_get_user_links_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_get_user_links), "__call__" + type(client.transport.batch_get_user_links), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.BatchGetUserLinksResponse() @@ -2642,17 +3117,19 @@ async def test_batch_get_user_links_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_user_links(transport: str = "grpc"): +def test_list_user_links( + transport: str = "grpc", request_type=analytics_admin.ListUserLinksRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_user_links), "__call__") as call: + with mock.patch.object(type(client.transport.list_user_links), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListUserLinksResponse( next_page_token="next_page_token_value", @@ -2664,28 +3141,33 @@ def test_list_user_links(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListUserLinksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListUserLinksPager) assert response.next_page_token == "next_page_token_value" +def test_list_user_links_from_dict(): + test_list_user_links(request_type=dict) + + @pytest.mark.asyncio -async def test_list_user_links_async(transport: str = "grpc_asyncio"): +async def test_list_user_links_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.ListUserLinksRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_user_links), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListUserLinksResponse( @@ -2699,7 +3181,7 @@ async def test_list_user_links_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListUserLinksRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListUserLinksAsyncPager) @@ -2707,6 +3189,11 @@ async def test_list_user_links_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_user_links_async_from_dict(): + await test_list_user_links_async(request_type=dict) + + def test_list_user_links_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -2718,7 +3205,7 @@ def test_list_user_links_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_user_links), "__call__") as call: + with mock.patch.object(type(client.transport.list_user_links), "__call__") as call: call.return_value = analytics_admin.ListUserLinksResponse() client.list_user_links(request) @@ -2745,9 +3232,7 @@ async def test_list_user_links_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_user_links), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListUserLinksResponse() ) @@ -2770,7 +3255,7 @@ def test_list_user_links_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_user_links), "__call__") as call: + with mock.patch.object(type(client.transport.list_user_links), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListUserLinksResponse() @@ -2806,9 +3291,7 @@ async def test_list_user_links_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_user_links), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListUserLinksResponse() @@ -2845,7 +3328,7 @@ def test_list_user_links_pager(): client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_user_links), "__call__") as call: + with mock.patch.object(type(client.transport.list_user_links), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( analytics_admin.ListUserLinksResponse( @@ -2885,7 +3368,7 @@ def test_list_user_links_pages(): client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_user_links), "__call__") as call: + with mock.patch.object(type(client.transport.list_user_links), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( analytics_admin.ListUserLinksResponse( @@ -2908,8 +3391,8 @@ def test_list_user_links_pages(): RuntimeError, ) pages = list(client.list_user_links(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -2920,9 +3403,7 @@ async def test_list_user_links_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_user_links), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_user_links), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2963,9 +3444,7 @@ async def test_list_user_links_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_user_links), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_user_links), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2989,25 +3468,25 @@ async def test_list_user_links_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_user_links(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_user_links(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_audit_user_links(transport: str = "grpc"): +def test_audit_user_links( + transport: str = "grpc", request_type=analytics_admin.AuditUserLinksRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.AuditUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.audit_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.audit_user_links), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.AuditUserLinksResponse( next_page_token="next_page_token_value", @@ -3019,28 +3498,33 @@ def test_audit_user_links(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.AuditUserLinksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.AuditUserLinksPager) assert response.next_page_token == "next_page_token_value" +def test_audit_user_links_from_dict(): + test_audit_user_links(request_type=dict) + + @pytest.mark.asyncio -async def test_audit_user_links_async(transport: str = "grpc_asyncio"): +async def test_audit_user_links_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.AuditUserLinksRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.AuditUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.audit_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.audit_user_links), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.AuditUserLinksResponse( @@ -3054,7 +3538,7 @@ async def test_audit_user_links_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.AuditUserLinksRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.AuditUserLinksAsyncPager) @@ -3062,6 +3546,11 @@ async def test_audit_user_links_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_audit_user_links_async_from_dict(): + await test_audit_user_links_async(request_type=dict) + + def test_audit_user_links_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -3073,9 +3562,7 @@ def test_audit_user_links_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.audit_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.audit_user_links), "__call__") as call: call.return_value = analytics_admin.AuditUserLinksResponse() client.audit_user_links(request) @@ -3102,9 +3589,7 @@ async def test_audit_user_links_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.audit_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.audit_user_links), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.AuditUserLinksResponse() ) @@ -3125,9 +3610,7 @@ def test_audit_user_links_pager(): client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.audit_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.audit_user_links), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( analytics_admin.AuditUserLinksResponse( @@ -3167,9 +3650,7 @@ def test_audit_user_links_pages(): client = AnalyticsAdminServiceClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.audit_user_links), "__call__" - ) as call: + with mock.patch.object(type(client.transport.audit_user_links), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( analytics_admin.AuditUserLinksResponse( @@ -3192,8 +3673,8 @@ def test_audit_user_links_pages(): RuntimeError, ) pages = list(client.audit_user_links(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -3204,9 +3685,7 @@ async def test_audit_user_links_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.audit_user_links), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.audit_user_links), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3247,9 +3726,7 @@ async def test_audit_user_links_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.audit_user_links), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.audit_user_links), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3273,25 +3750,25 @@ async def test_audit_user_links_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.audit_user_links(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.audit_user_links(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_create_user_link(transport: str = "grpc"): +def test_create_user_link( + transport: str = "grpc", request_type=analytics_admin.CreateUserLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateUserLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.create_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink( name="name_value", @@ -3305,9 +3782,10 @@ def test_create_user_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateUserLinkRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.UserLink) assert response.name == "name_value" @@ -3317,20 +3795,24 @@ def test_create_user_link(transport: str = "grpc"): assert response.direct_roles == ["direct_roles_value"] +def test_create_user_link_from_dict(): + test_create_user_link(request_type=dict) + + @pytest.mark.asyncio -async def test_create_user_link_async(transport: str = "grpc_asyncio"): +async def test_create_user_link_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.CreateUserLinkRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateUserLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.UserLink( @@ -3346,7 +3828,7 @@ async def test_create_user_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateUserLinkRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.UserLink) @@ -3358,6 +3840,11 @@ async def test_create_user_link_async(transport: str = "grpc_asyncio"): assert response.direct_roles == ["direct_roles_value"] +@pytest.mark.asyncio +async def test_create_user_link_async_from_dict(): + await test_create_user_link_async(request_type=dict) + + def test_create_user_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -3369,9 +3856,7 @@ def test_create_user_link_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.create_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_user_link), "__call__") as call: call.return_value = resources.UserLink() client.create_user_link(request) @@ -3398,9 +3883,7 @@ async def test_create_user_link_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_user_link), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.UserLink()) await client.create_user_link(request) @@ -3421,9 +3904,7 @@ def test_create_user_link_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.create_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink() @@ -3465,9 +3946,7 @@ async def test_create_user_link_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink() @@ -3504,18 +3983,20 @@ async def test_create_user_link_flattened_error_async(): ) -def test_batch_create_user_links(transport: str = "grpc"): +def test_batch_create_user_links( + transport: str = "grpc", request_type=analytics_admin.BatchCreateUserLinksRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.BatchCreateUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_create_user_links), "__call__" + type(client.transport.batch_create_user_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.BatchCreateUserLinksResponse() @@ -3526,25 +4007,33 @@ def test_batch_create_user_links(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.BatchCreateUserLinksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, analytics_admin.BatchCreateUserLinksResponse) +def test_batch_create_user_links_from_dict(): + test_batch_create_user_links(request_type=dict) + + @pytest.mark.asyncio -async def test_batch_create_user_links_async(transport: str = "grpc_asyncio"): +async def test_batch_create_user_links_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.BatchCreateUserLinksRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.BatchCreateUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_create_user_links), "__call__" + type(client.transport.batch_create_user_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3557,12 +4046,17 @@ async def test_batch_create_user_links_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.BatchCreateUserLinksRequest() # Establish that the response is the type that we expect. assert isinstance(response, analytics_admin.BatchCreateUserLinksResponse) +@pytest.mark.asyncio +async def test_batch_create_user_links_async_from_dict(): + await test_batch_create_user_links_async(request_type=dict) + + def test_batch_create_user_links_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -3575,7 +4069,7 @@ def test_batch_create_user_links_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_create_user_links), "__call__" + type(client.transport.batch_create_user_links), "__call__" ) as call: call.return_value = analytics_admin.BatchCreateUserLinksResponse() @@ -3604,7 +4098,7 @@ async def test_batch_create_user_links_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_create_user_links), "__call__" + type(client.transport.batch_create_user_links), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.BatchCreateUserLinksResponse() @@ -3622,19 +4116,19 @@ async def test_batch_create_user_links_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_update_user_link(transport: str = "grpc"): +def test_update_user_link( + transport: str = "grpc", request_type=analytics_admin.UpdateUserLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateUserLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.update_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink( name="name_value", @@ -3648,9 +4142,10 @@ def test_update_user_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateUserLinkRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.UserLink) assert response.name == "name_value" @@ -3660,20 +4155,24 @@ def test_update_user_link(transport: str = "grpc"): assert response.direct_roles == ["direct_roles_value"] +def test_update_user_link_from_dict(): + test_update_user_link(request_type=dict) + + @pytest.mark.asyncio -async def test_update_user_link_async(transport: str = "grpc_asyncio"): +async def test_update_user_link_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.UpdateUserLinkRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateUserLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.UserLink( @@ -3689,7 +4188,7 @@ async def test_update_user_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateUserLinkRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.UserLink) @@ -3701,6 +4200,11 @@ async def test_update_user_link_async(transport: str = "grpc_asyncio"): assert response.direct_roles == ["direct_roles_value"] +@pytest.mark.asyncio +async def test_update_user_link_async_from_dict(): + await test_update_user_link_async(request_type=dict) + + def test_update_user_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -3712,9 +4216,7 @@ def test_update_user_link_field_headers(): request.user_link.name = "user_link.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.update_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_user_link), "__call__") as call: call.return_value = resources.UserLink() client.update_user_link(request) @@ -3743,9 +4245,7 @@ async def test_update_user_link_field_headers_async(): request.user_link.name = "user_link.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_user_link), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(resources.UserLink()) await client.update_user_link(request) @@ -3768,9 +4268,7 @@ def test_update_user_link_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.update_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink() @@ -3807,9 +4305,7 @@ async def test_update_user_link_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.UserLink() @@ -3843,18 +4339,20 @@ async def test_update_user_link_flattened_error_async(): ) -def test_batch_update_user_links(transport: str = "grpc"): +def test_batch_update_user_links( + transport: str = "grpc", request_type=analytics_admin.BatchUpdateUserLinksRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.BatchUpdateUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_update_user_links), "__call__" + type(client.transport.batch_update_user_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.BatchUpdateUserLinksResponse() @@ -3865,25 +4363,33 @@ def test_batch_update_user_links(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.BatchUpdateUserLinksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, analytics_admin.BatchUpdateUserLinksResponse) +def test_batch_update_user_links_from_dict(): + test_batch_update_user_links(request_type=dict) + + @pytest.mark.asyncio -async def test_batch_update_user_links_async(transport: str = "grpc_asyncio"): +async def test_batch_update_user_links_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.BatchUpdateUserLinksRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.BatchUpdateUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_update_user_links), "__call__" + type(client.transport.batch_update_user_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3896,12 +4402,17 @@ async def test_batch_update_user_links_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.BatchUpdateUserLinksRequest() # Establish that the response is the type that we expect. assert isinstance(response, analytics_admin.BatchUpdateUserLinksResponse) +@pytest.mark.asyncio +async def test_batch_update_user_links_async_from_dict(): + await test_batch_update_user_links_async(request_type=dict) + + def test_batch_update_user_links_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -3914,7 +4425,7 @@ def test_batch_update_user_links_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_update_user_links), "__call__" + type(client.transport.batch_update_user_links), "__call__" ) as call: call.return_value = analytics_admin.BatchUpdateUserLinksResponse() @@ -3943,7 +4454,7 @@ async def test_batch_update_user_links_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_update_user_links), "__call__" + type(client.transport.batch_update_user_links), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.BatchUpdateUserLinksResponse() @@ -3961,19 +4472,19 @@ async def test_batch_update_user_links_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_delete_user_link(transport: str = "grpc"): +def test_delete_user_link( + transport: str = "grpc", request_type=analytics_admin.DeleteUserLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteUserLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.delete_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -3983,26 +4494,30 @@ def test_delete_user_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteUserLinkRequest() # Establish that the response is the type that we expect. assert response is None +def test_delete_user_link_from_dict(): + test_delete_user_link(request_type=dict) + + @pytest.mark.asyncio -async def test_delete_user_link_async(transport: str = "grpc_asyncio"): +async def test_delete_user_link_async( + transport: str = "grpc_asyncio", request_type=analytics_admin.DeleteUserLinkRequest +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteUserLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -4012,12 +4527,17 @@ async def test_delete_user_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteUserLinkRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_user_link_async_from_dict(): + await test_delete_user_link_async(request_type=dict) + + def test_delete_user_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -4029,9 +4549,7 @@ def test_delete_user_link_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.delete_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_user_link), "__call__") as call: call.return_value = None client.delete_user_link(request) @@ -4058,9 +4576,7 @@ async def test_delete_user_link_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_user_link), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_user_link(request) @@ -4081,9 +4597,7 @@ def test_delete_user_link_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.delete_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -4119,9 +4633,7 @@ async def test_delete_user_link_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_user_link), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_user_link), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -4152,18 +4664,20 @@ async def test_delete_user_link_flattened_error_async(): ) -def test_batch_delete_user_links(transport: str = "grpc"): +def test_batch_delete_user_links( + transport: str = "grpc", request_type=analytics_admin.BatchDeleteUserLinksRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.BatchDeleteUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_delete_user_links), "__call__" + type(client.transport.batch_delete_user_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -4174,25 +4688,32 @@ def test_batch_delete_user_links(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.BatchDeleteUserLinksRequest() # Establish that the response is the type that we expect. assert response is None +def test_batch_delete_user_links_from_dict(): + test_batch_delete_user_links(request_type=dict) + + @pytest.mark.asyncio -async def test_batch_delete_user_links_async(transport: str = "grpc_asyncio"): +async def test_batch_delete_user_links_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.BatchDeleteUserLinksRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.BatchDeleteUserLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_delete_user_links), "__call__" + type(client.transport.batch_delete_user_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -4203,12 +4724,17 @@ async def test_batch_delete_user_links_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.BatchDeleteUserLinksRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_batch_delete_user_links_async_from_dict(): + await test_batch_delete_user_links_async(request_type=dict) + + def test_batch_delete_user_links_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -4221,7 +4747,7 @@ def test_batch_delete_user_links_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_delete_user_links), "__call__" + type(client.transport.batch_delete_user_links), "__call__" ) as call: call.return_value = None @@ -4250,7 +4776,7 @@ async def test_batch_delete_user_links_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_delete_user_links), "__call__" + type(client.transport.batch_delete_user_links), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -4266,18 +4792,20 @@ async def test_batch_delete_user_links_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_get_web_data_stream(transport: str = "grpc"): +def test_get_web_data_stream( + transport: str = "grpc", request_type=analytics_admin.GetWebDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetWebDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_web_data_stream), "__call__" + type(client.transport.get_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream( @@ -4294,9 +4822,10 @@ def test_get_web_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetWebDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.WebDataStream) assert response.name == "name_value" @@ -4310,19 +4839,26 @@ def test_get_web_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_get_web_data_stream_from_dict(): + test_get_web_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_get_web_data_stream_async(transport: str = "grpc_asyncio"): +async def test_get_web_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.GetWebDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetWebDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_web_data_stream), "__call__" + type(client.transport.get_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4341,7 +4877,7 @@ async def test_get_web_data_stream_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetWebDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.WebDataStream) @@ -4357,6 +4893,11 @@ async def test_get_web_data_stream_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_get_web_data_stream_async_from_dict(): + await test_get_web_data_stream_async(request_type=dict) + + def test_get_web_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -4369,7 +4910,7 @@ def test_get_web_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_web_data_stream), "__call__" + type(client.transport.get_web_data_stream), "__call__" ) as call: call.return_value = resources.WebDataStream() @@ -4398,7 +4939,7 @@ async def test_get_web_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_web_data_stream), "__call__" + type(client.transport.get_web_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.WebDataStream() @@ -4423,7 +4964,7 @@ def test_get_web_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_web_data_stream), "__call__" + type(client.transport.get_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream() @@ -4461,7 +5002,7 @@ async def test_get_web_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_web_data_stream), "__call__" + type(client.transport.get_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream() @@ -4495,18 +5036,20 @@ async def test_get_web_data_stream_flattened_error_async(): ) -def test_delete_web_data_stream(transport: str = "grpc"): +def test_delete_web_data_stream( + transport: str = "grpc", request_type=analytics_admin.DeleteWebDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteWebDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_web_data_stream), "__call__" + type(client.transport.delete_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -4517,25 +5060,32 @@ def test_delete_web_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteWebDataStreamRequest() # Establish that the response is the type that we expect. assert response is None +def test_delete_web_data_stream_from_dict(): + test_delete_web_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_delete_web_data_stream_async(transport: str = "grpc_asyncio"): +async def test_delete_web_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.DeleteWebDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteWebDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_web_data_stream), "__call__" + type(client.transport.delete_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -4546,12 +5096,17 @@ async def test_delete_web_data_stream_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteWebDataStreamRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_web_data_stream_async_from_dict(): + await test_delete_web_data_stream_async(request_type=dict) + + def test_delete_web_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -4564,7 +5119,7 @@ def test_delete_web_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_web_data_stream), "__call__" + type(client.transport.delete_web_data_stream), "__call__" ) as call: call.return_value = None @@ -4593,7 +5148,7 @@ async def test_delete_web_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_web_data_stream), "__call__" + type(client.transport.delete_web_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -4616,7 +5171,7 @@ def test_delete_web_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_web_data_stream), "__call__" + type(client.transport.delete_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -4654,7 +5209,7 @@ async def test_delete_web_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_web_data_stream), "__call__" + type(client.transport.delete_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -4686,18 +5241,20 @@ async def test_delete_web_data_stream_flattened_error_async(): ) -def test_update_web_data_stream(transport: str = "grpc"): +def test_update_web_data_stream( + transport: str = "grpc", request_type=analytics_admin.UpdateWebDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateWebDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_web_data_stream), "__call__" + type(client.transport.update_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream( @@ -4714,9 +5271,10 @@ def test_update_web_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateWebDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.WebDataStream) assert response.name == "name_value" @@ -4730,19 +5288,26 @@ def test_update_web_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_update_web_data_stream_from_dict(): + test_update_web_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_update_web_data_stream_async(transport: str = "grpc_asyncio"): +async def test_update_web_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.UpdateWebDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateWebDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_web_data_stream), "__call__" + type(client.transport.update_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4761,7 +5326,7 @@ async def test_update_web_data_stream_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateWebDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.WebDataStream) @@ -4777,6 +5342,11 @@ async def test_update_web_data_stream_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_update_web_data_stream_async_from_dict(): + await test_update_web_data_stream_async(request_type=dict) + + def test_update_web_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -4789,7 +5359,7 @@ def test_update_web_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_web_data_stream), "__call__" + type(client.transport.update_web_data_stream), "__call__" ) as call: call.return_value = resources.WebDataStream() @@ -4821,7 +5391,7 @@ async def test_update_web_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_web_data_stream), "__call__" + type(client.transport.update_web_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.WebDataStream() @@ -4849,7 +5419,7 @@ def test_update_web_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_web_data_stream), "__call__" + type(client.transport.update_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream() @@ -4894,7 +5464,7 @@ async def test_update_web_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_web_data_stream), "__call__" + type(client.transport.update_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream() @@ -4935,18 +5505,20 @@ async def test_update_web_data_stream_flattened_error_async(): ) -def test_create_web_data_stream(transport: str = "grpc"): +def test_create_web_data_stream( + transport: str = "grpc", request_type=analytics_admin.CreateWebDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateWebDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_web_data_stream), "__call__" + type(client.transport.create_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream( @@ -4963,9 +5535,10 @@ def test_create_web_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateWebDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.WebDataStream) assert response.name == "name_value" @@ -4979,19 +5552,26 @@ def test_create_web_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_create_web_data_stream_from_dict(): + test_create_web_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_create_web_data_stream_async(transport: str = "grpc_asyncio"): +async def test_create_web_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.CreateWebDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateWebDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_web_data_stream), "__call__" + type(client.transport.create_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5010,7 +5590,7 @@ async def test_create_web_data_stream_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateWebDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.WebDataStream) @@ -5026,6 +5606,11 @@ async def test_create_web_data_stream_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_create_web_data_stream_async_from_dict(): + await test_create_web_data_stream_async(request_type=dict) + + def test_create_web_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -5038,7 +5623,7 @@ def test_create_web_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_web_data_stream), "__call__" + type(client.transport.create_web_data_stream), "__call__" ) as call: call.return_value = resources.WebDataStream() @@ -5067,7 +5652,7 @@ async def test_create_web_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_web_data_stream), "__call__" + type(client.transport.create_web_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.WebDataStream() @@ -5092,7 +5677,7 @@ def test_create_web_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_web_data_stream), "__call__" + type(client.transport.create_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream() @@ -5137,7 +5722,7 @@ async def test_create_web_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_web_data_stream), "__call__" + type(client.transport.create_web_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.WebDataStream() @@ -5178,18 +5763,20 @@ async def test_create_web_data_stream_flattened_error_async(): ) -def test_list_web_data_streams(transport: str = "grpc"): +def test_list_web_data_streams( + transport: str = "grpc", request_type=analytics_admin.ListWebDataStreamsRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListWebDataStreamsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_web_data_streams), "__call__" + type(client.transport.list_web_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListWebDataStreamsResponse( @@ -5202,27 +5789,35 @@ def test_list_web_data_streams(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListWebDataStreamsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListWebDataStreamsPager) assert response.next_page_token == "next_page_token_value" +def test_list_web_data_streams_from_dict(): + test_list_web_data_streams(request_type=dict) + + @pytest.mark.asyncio -async def test_list_web_data_streams_async(transport: str = "grpc_asyncio"): +async def test_list_web_data_streams_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.ListWebDataStreamsRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListWebDataStreamsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_web_data_streams), "__call__" + type(client.transport.list_web_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5237,7 +5832,7 @@ async def test_list_web_data_streams_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListWebDataStreamsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListWebDataStreamsAsyncPager) @@ -5245,6 +5840,11 @@ async def test_list_web_data_streams_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_web_data_streams_async_from_dict(): + await test_list_web_data_streams_async(request_type=dict) + + def test_list_web_data_streams_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -5257,7 +5857,7 @@ def test_list_web_data_streams_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_web_data_streams), "__call__" + type(client.transport.list_web_data_streams), "__call__" ) as call: call.return_value = analytics_admin.ListWebDataStreamsResponse() @@ -5286,7 +5886,7 @@ async def test_list_web_data_streams_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_web_data_streams), "__call__" + type(client.transport.list_web_data_streams), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListWebDataStreamsResponse() @@ -5311,7 +5911,7 @@ def test_list_web_data_streams_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_web_data_streams), "__call__" + type(client.transport.list_web_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListWebDataStreamsResponse() @@ -5349,7 +5949,7 @@ async def test_list_web_data_streams_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_web_data_streams), "__call__" + type(client.transport.list_web_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListWebDataStreamsResponse() @@ -5388,7 +5988,7 @@ def test_list_web_data_streams_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_web_data_streams), "__call__" + type(client.transport.list_web_data_streams), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -5433,7 +6033,7 @@ def test_list_web_data_streams_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_web_data_streams), "__call__" + type(client.transport.list_web_data_streams), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -5460,8 +6060,8 @@ def test_list_web_data_streams_pages(): RuntimeError, ) pages = list(client.list_web_data_streams(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -5472,7 +6072,7 @@ async def test_list_web_data_streams_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_web_data_streams), + type(client.transport.list_web_data_streams), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -5518,7 +6118,7 @@ async def test_list_web_data_streams_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_web_data_streams), + type(client.transport.list_web_data_streams), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -5547,24 +6147,26 @@ async def test_list_web_data_streams_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_web_data_streams(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_web_data_streams(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_get_ios_app_data_stream(transport: str = "grpc"): +def test_get_ios_app_data_stream( + transport: str = "grpc", request_type=analytics_admin.GetIosAppDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetIosAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_ios_app_data_stream), "__call__" + type(client.transport.get_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream( @@ -5580,9 +6182,10 @@ def test_get_ios_app_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetIosAppDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.IosAppDataStream) assert response.name == "name_value" @@ -5594,19 +6197,26 @@ def test_get_ios_app_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_get_ios_app_data_stream_from_dict(): + test_get_ios_app_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_get_ios_app_data_stream_async(transport: str = "grpc_asyncio"): +async def test_get_ios_app_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.GetIosAppDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetIosAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_ios_app_data_stream), "__call__" + type(client.transport.get_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5624,7 +6234,7 @@ async def test_get_ios_app_data_stream_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetIosAppDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.IosAppDataStream) @@ -5638,6 +6248,11 @@ async def test_get_ios_app_data_stream_async(transport: str = "grpc_asyncio"): assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_get_ios_app_data_stream_async_from_dict(): + await test_get_ios_app_data_stream_async(request_type=dict) + + def test_get_ios_app_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -5650,7 +6265,7 @@ def test_get_ios_app_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_ios_app_data_stream), "__call__" + type(client.transport.get_ios_app_data_stream), "__call__" ) as call: call.return_value = resources.IosAppDataStream() @@ -5679,7 +6294,7 @@ async def test_get_ios_app_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_ios_app_data_stream), "__call__" + type(client.transport.get_ios_app_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.IosAppDataStream() @@ -5704,7 +6319,7 @@ def test_get_ios_app_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_ios_app_data_stream), "__call__" + type(client.transport.get_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream() @@ -5742,7 +6357,7 @@ async def test_get_ios_app_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_ios_app_data_stream), "__call__" + type(client.transport.get_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream() @@ -5776,18 +6391,20 @@ async def test_get_ios_app_data_stream_flattened_error_async(): ) -def test_delete_ios_app_data_stream(transport: str = "grpc"): +def test_delete_ios_app_data_stream( + transport: str = "grpc", request_type=analytics_admin.DeleteIosAppDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteIosAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_ios_app_data_stream), "__call__" + type(client.transport.delete_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5798,25 +6415,32 @@ def test_delete_ios_app_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteIosAppDataStreamRequest() # Establish that the response is the type that we expect. assert response is None +def test_delete_ios_app_data_stream_from_dict(): + test_delete_ios_app_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_delete_ios_app_data_stream_async(transport: str = "grpc_asyncio"): +async def test_delete_ios_app_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.DeleteIosAppDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteIosAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_ios_app_data_stream), "__call__" + type(client.transport.delete_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -5827,12 +6451,17 @@ async def test_delete_ios_app_data_stream_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteIosAppDataStreamRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_ios_app_data_stream_async_from_dict(): + await test_delete_ios_app_data_stream_async(request_type=dict) + + def test_delete_ios_app_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -5845,7 +6474,7 @@ def test_delete_ios_app_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_ios_app_data_stream), "__call__" + type(client.transport.delete_ios_app_data_stream), "__call__" ) as call: call.return_value = None @@ -5874,7 +6503,7 @@ async def test_delete_ios_app_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_ios_app_data_stream), "__call__" + type(client.transport.delete_ios_app_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -5897,7 +6526,7 @@ def test_delete_ios_app_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_ios_app_data_stream), "__call__" + type(client.transport.delete_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5935,7 +6564,7 @@ async def test_delete_ios_app_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_ios_app_data_stream), "__call__" + type(client.transport.delete_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -5967,18 +6596,20 @@ async def test_delete_ios_app_data_stream_flattened_error_async(): ) -def test_update_ios_app_data_stream(transport: str = "grpc"): +def test_update_ios_app_data_stream( + transport: str = "grpc", request_type=analytics_admin.UpdateIosAppDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateIosAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_ios_app_data_stream), "__call__" + type(client.transport.update_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream( @@ -5994,9 +6625,10 @@ def test_update_ios_app_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateIosAppDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.IosAppDataStream) assert response.name == "name_value" @@ -6008,19 +6640,26 @@ def test_update_ios_app_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_update_ios_app_data_stream_from_dict(): + test_update_ios_app_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_update_ios_app_data_stream_async(transport: str = "grpc_asyncio"): +async def test_update_ios_app_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.UpdateIosAppDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateIosAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_ios_app_data_stream), "__call__" + type(client.transport.update_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -6038,7 +6677,7 @@ async def test_update_ios_app_data_stream_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateIosAppDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.IosAppDataStream) @@ -6052,6 +6691,11 @@ async def test_update_ios_app_data_stream_async(transport: str = "grpc_asyncio") assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_update_ios_app_data_stream_async_from_dict(): + await test_update_ios_app_data_stream_async(request_type=dict) + + def test_update_ios_app_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -6064,7 +6708,7 @@ def test_update_ios_app_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_ios_app_data_stream), "__call__" + type(client.transport.update_ios_app_data_stream), "__call__" ) as call: call.return_value = resources.IosAppDataStream() @@ -6096,7 +6740,7 @@ async def test_update_ios_app_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_ios_app_data_stream), "__call__" + type(client.transport.update_ios_app_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.IosAppDataStream() @@ -6124,7 +6768,7 @@ def test_update_ios_app_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_ios_app_data_stream), "__call__" + type(client.transport.update_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream() @@ -6171,7 +6815,7 @@ async def test_update_ios_app_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_ios_app_data_stream), "__call__" + type(client.transport.update_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream() @@ -6214,18 +6858,20 @@ async def test_update_ios_app_data_stream_flattened_error_async(): ) -def test_create_ios_app_data_stream(transport: str = "grpc"): +def test_create_ios_app_data_stream( + transport: str = "grpc", request_type=analytics_admin.CreateIosAppDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateIosAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_ios_app_data_stream), "__call__" + type(client.transport.create_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream( @@ -6241,9 +6887,10 @@ def test_create_ios_app_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateIosAppDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.IosAppDataStream) assert response.name == "name_value" @@ -6255,19 +6902,26 @@ def test_create_ios_app_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_create_ios_app_data_stream_from_dict(): + test_create_ios_app_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_create_ios_app_data_stream_async(transport: str = "grpc_asyncio"): +async def test_create_ios_app_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.CreateIosAppDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateIosAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_ios_app_data_stream), "__call__" + type(client.transport.create_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -6285,7 +6939,7 @@ async def test_create_ios_app_data_stream_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateIosAppDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.IosAppDataStream) @@ -6299,6 +6953,11 @@ async def test_create_ios_app_data_stream_async(transport: str = "grpc_asyncio") assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_create_ios_app_data_stream_async_from_dict(): + await test_create_ios_app_data_stream_async(request_type=dict) + + def test_create_ios_app_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -6311,7 +6970,7 @@ def test_create_ios_app_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_ios_app_data_stream), "__call__" + type(client.transport.create_ios_app_data_stream), "__call__" ) as call: call.return_value = resources.IosAppDataStream() @@ -6340,7 +6999,7 @@ async def test_create_ios_app_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_ios_app_data_stream), "__call__" + type(client.transport.create_ios_app_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.IosAppDataStream() @@ -6365,7 +7024,7 @@ def test_create_ios_app_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_ios_app_data_stream), "__call__" + type(client.transport.create_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream() @@ -6412,7 +7071,7 @@ async def test_create_ios_app_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_ios_app_data_stream), "__call__" + type(client.transport.create_ios_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.IosAppDataStream() @@ -6455,18 +7114,20 @@ async def test_create_ios_app_data_stream_flattened_error_async(): ) -def test_list_ios_app_data_streams(transport: str = "grpc"): +def test_list_ios_app_data_streams( + transport: str = "grpc", request_type=analytics_admin.ListIosAppDataStreamsRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListIosAppDataStreamsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_ios_app_data_streams), "__call__" + type(client.transport.list_ios_app_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListIosAppDataStreamsResponse( @@ -6479,27 +7140,35 @@ def test_list_ios_app_data_streams(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListIosAppDataStreamsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListIosAppDataStreamsPager) assert response.next_page_token == "next_page_token_value" +def test_list_ios_app_data_streams_from_dict(): + test_list_ios_app_data_streams(request_type=dict) + + @pytest.mark.asyncio -async def test_list_ios_app_data_streams_async(transport: str = "grpc_asyncio"): +async def test_list_ios_app_data_streams_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.ListIosAppDataStreamsRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListIosAppDataStreamsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_ios_app_data_streams), "__call__" + type(client.transport.list_ios_app_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -6514,7 +7183,7 @@ async def test_list_ios_app_data_streams_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListIosAppDataStreamsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListIosAppDataStreamsAsyncPager) @@ -6522,6 +7191,11 @@ async def test_list_ios_app_data_streams_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_ios_app_data_streams_async_from_dict(): + await test_list_ios_app_data_streams_async(request_type=dict) + + def test_list_ios_app_data_streams_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -6534,7 +7208,7 @@ def test_list_ios_app_data_streams_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_ios_app_data_streams), "__call__" + type(client.transport.list_ios_app_data_streams), "__call__" ) as call: call.return_value = analytics_admin.ListIosAppDataStreamsResponse() @@ -6563,7 +7237,7 @@ async def test_list_ios_app_data_streams_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_ios_app_data_streams), "__call__" + type(client.transport.list_ios_app_data_streams), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListIosAppDataStreamsResponse() @@ -6588,7 +7262,7 @@ def test_list_ios_app_data_streams_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_ios_app_data_streams), "__call__" + type(client.transport.list_ios_app_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListIosAppDataStreamsResponse() @@ -6626,7 +7300,7 @@ async def test_list_ios_app_data_streams_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_ios_app_data_streams), "__call__" + type(client.transport.list_ios_app_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListIosAppDataStreamsResponse() @@ -6665,7 +7339,7 @@ def test_list_ios_app_data_streams_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_ios_app_data_streams), "__call__" + type(client.transport.list_ios_app_data_streams), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6711,7 +7385,7 @@ def test_list_ios_app_data_streams_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_ios_app_data_streams), "__call__" + type(client.transport.list_ios_app_data_streams), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -6739,8 +7413,8 @@ def test_list_ios_app_data_streams_pages(): RuntimeError, ) pages = list(client.list_ios_app_data_streams(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -6751,7 +7425,7 @@ async def test_list_ios_app_data_streams_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_ios_app_data_streams), + type(client.transport.list_ios_app_data_streams), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -6798,7 +7472,7 @@ async def test_list_ios_app_data_streams_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_ios_app_data_streams), + type(client.transport.list_ios_app_data_streams), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -6828,24 +7502,26 @@ async def test_list_ios_app_data_streams_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_ios_app_data_streams(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_ios_app_data_streams(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_get_android_app_data_stream(transport: str = "grpc"): +def test_get_android_app_data_stream( + transport: str = "grpc", request_type=analytics_admin.GetAndroidAppDataStreamRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetAndroidAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_android_app_data_stream), "__call__" + type(client.transport.get_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream( @@ -6861,9 +7537,10 @@ def test_get_android_app_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetAndroidAppDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.AndroidAppDataStream) assert response.name == "name_value" @@ -6875,19 +7552,26 @@ def test_get_android_app_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_get_android_app_data_stream_from_dict(): + test_get_android_app_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_get_android_app_data_stream_async(transport: str = "grpc_asyncio"): +async def test_get_android_app_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.GetAndroidAppDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetAndroidAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_android_app_data_stream), "__call__" + type(client.transport.get_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -6905,7 +7589,7 @@ async def test_get_android_app_data_stream_async(transport: str = "grpc_asyncio" assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetAndroidAppDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.AndroidAppDataStream) @@ -6919,6 +7603,11 @@ async def test_get_android_app_data_stream_async(transport: str = "grpc_asyncio" assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_get_android_app_data_stream_async_from_dict(): + await test_get_android_app_data_stream_async(request_type=dict) + + def test_get_android_app_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -6931,7 +7620,7 @@ def test_get_android_app_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_android_app_data_stream), "__call__" + type(client.transport.get_android_app_data_stream), "__call__" ) as call: call.return_value = resources.AndroidAppDataStream() @@ -6960,7 +7649,7 @@ async def test_get_android_app_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_android_app_data_stream), "__call__" + type(client.transport.get_android_app_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.AndroidAppDataStream() @@ -6985,7 +7674,7 @@ def test_get_android_app_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_android_app_data_stream), "__call__" + type(client.transport.get_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream() @@ -7023,7 +7712,7 @@ async def test_get_android_app_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_android_app_data_stream), "__call__" + type(client.transport.get_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream() @@ -7057,18 +7746,21 @@ async def test_get_android_app_data_stream_flattened_error_async(): ) -def test_delete_android_app_data_stream(transport: str = "grpc"): +def test_delete_android_app_data_stream( + transport: str = "grpc", + request_type=analytics_admin.DeleteAndroidAppDataStreamRequest, +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteAndroidAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_android_app_data_stream), "__call__" + type(client.transport.delete_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -7079,25 +7771,32 @@ def test_delete_android_app_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteAndroidAppDataStreamRequest() # Establish that the response is the type that we expect. assert response is None +def test_delete_android_app_data_stream_from_dict(): + test_delete_android_app_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_delete_android_app_data_stream_async(transport: str = "grpc_asyncio"): +async def test_delete_android_app_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.DeleteAndroidAppDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteAndroidAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_android_app_data_stream), "__call__" + type(client.transport.delete_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -7108,12 +7807,17 @@ async def test_delete_android_app_data_stream_async(transport: str = "grpc_async assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteAndroidAppDataStreamRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_android_app_data_stream_async_from_dict(): + await test_delete_android_app_data_stream_async(request_type=dict) + + def test_delete_android_app_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -7126,7 +7830,7 @@ def test_delete_android_app_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_android_app_data_stream), "__call__" + type(client.transport.delete_android_app_data_stream), "__call__" ) as call: call.return_value = None @@ -7155,7 +7859,7 @@ async def test_delete_android_app_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_android_app_data_stream), "__call__" + type(client.transport.delete_android_app_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -7178,7 +7882,7 @@ def test_delete_android_app_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_android_app_data_stream), "__call__" + type(client.transport.delete_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -7216,7 +7920,7 @@ async def test_delete_android_app_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_android_app_data_stream), "__call__" + type(client.transport.delete_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -7248,18 +7952,21 @@ async def test_delete_android_app_data_stream_flattened_error_async(): ) -def test_update_android_app_data_stream(transport: str = "grpc"): +def test_update_android_app_data_stream( + transport: str = "grpc", + request_type=analytics_admin.UpdateAndroidAppDataStreamRequest, +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateAndroidAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_android_app_data_stream), "__call__" + type(client.transport.update_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream( @@ -7275,9 +7982,10 @@ def test_update_android_app_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateAndroidAppDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.AndroidAppDataStream) assert response.name == "name_value" @@ -7289,19 +7997,26 @@ def test_update_android_app_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_update_android_app_data_stream_from_dict(): + test_update_android_app_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_update_android_app_data_stream_async(transport: str = "grpc_asyncio"): +async def test_update_android_app_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.UpdateAndroidAppDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateAndroidAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_android_app_data_stream), "__call__" + type(client.transport.update_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7319,7 +8034,7 @@ async def test_update_android_app_data_stream_async(transport: str = "grpc_async assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateAndroidAppDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.AndroidAppDataStream) @@ -7333,6 +8048,11 @@ async def test_update_android_app_data_stream_async(transport: str = "grpc_async assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_update_android_app_data_stream_async_from_dict(): + await test_update_android_app_data_stream_async(request_type=dict) + + def test_update_android_app_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -7345,7 +8065,7 @@ def test_update_android_app_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_android_app_data_stream), "__call__" + type(client.transport.update_android_app_data_stream), "__call__" ) as call: call.return_value = resources.AndroidAppDataStream() @@ -7377,7 +8097,7 @@ async def test_update_android_app_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_android_app_data_stream), "__call__" + type(client.transport.update_android_app_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.AndroidAppDataStream() @@ -7405,7 +8125,7 @@ def test_update_android_app_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_android_app_data_stream), "__call__" + type(client.transport.update_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream() @@ -7452,7 +8172,7 @@ async def test_update_android_app_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_android_app_data_stream), "__call__" + type(client.transport.update_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream() @@ -7495,18 +8215,21 @@ async def test_update_android_app_data_stream_flattened_error_async(): ) -def test_create_android_app_data_stream(transport: str = "grpc"): +def test_create_android_app_data_stream( + transport: str = "grpc", + request_type=analytics_admin.CreateAndroidAppDataStreamRequest, +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateAndroidAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_android_app_data_stream), "__call__" + type(client.transport.create_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream( @@ -7522,9 +8245,10 @@ def test_create_android_app_data_stream(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateAndroidAppDataStreamRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.AndroidAppDataStream) assert response.name == "name_value" @@ -7536,19 +8260,26 @@ def test_create_android_app_data_stream(transport: str = "grpc"): assert response.display_name == "display_name_value" +def test_create_android_app_data_stream_from_dict(): + test_create_android_app_data_stream(request_type=dict) + + @pytest.mark.asyncio -async def test_create_android_app_data_stream_async(transport: str = "grpc_asyncio"): +async def test_create_android_app_data_stream_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.CreateAndroidAppDataStreamRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateAndroidAppDataStreamRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_android_app_data_stream), "__call__" + type(client.transport.create_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7566,7 +8297,7 @@ async def test_create_android_app_data_stream_async(transport: str = "grpc_async assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateAndroidAppDataStreamRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.AndroidAppDataStream) @@ -7580,6 +8311,11 @@ async def test_create_android_app_data_stream_async(transport: str = "grpc_async assert response.display_name == "display_name_value" +@pytest.mark.asyncio +async def test_create_android_app_data_stream_async_from_dict(): + await test_create_android_app_data_stream_async(request_type=dict) + + def test_create_android_app_data_stream_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -7592,7 +8328,7 @@ def test_create_android_app_data_stream_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_android_app_data_stream), "__call__" + type(client.transport.create_android_app_data_stream), "__call__" ) as call: call.return_value = resources.AndroidAppDataStream() @@ -7621,7 +8357,7 @@ async def test_create_android_app_data_stream_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_android_app_data_stream), "__call__" + type(client.transport.create_android_app_data_stream), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.AndroidAppDataStream() @@ -7646,7 +8382,7 @@ def test_create_android_app_data_stream_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_android_app_data_stream), "__call__" + type(client.transport.create_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream() @@ -7693,7 +8429,7 @@ async def test_create_android_app_data_stream_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_android_app_data_stream), "__call__" + type(client.transport.create_android_app_data_stream), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.AndroidAppDataStream() @@ -7736,18 +8472,21 @@ async def test_create_android_app_data_stream_flattened_error_async(): ) -def test_list_android_app_data_streams(transport: str = "grpc"): +def test_list_android_app_data_streams( + transport: str = "grpc", + request_type=analytics_admin.ListAndroidAppDataStreamsRequest, +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListAndroidAppDataStreamsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_android_app_data_streams), "__call__" + type(client.transport.list_android_app_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListAndroidAppDataStreamsResponse( @@ -7760,27 +8499,35 @@ def test_list_android_app_data_streams(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListAndroidAppDataStreamsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAndroidAppDataStreamsPager) assert response.next_page_token == "next_page_token_value" +def test_list_android_app_data_streams_from_dict(): + test_list_android_app_data_streams(request_type=dict) + + @pytest.mark.asyncio -async def test_list_android_app_data_streams_async(transport: str = "grpc_asyncio"): +async def test_list_android_app_data_streams_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.ListAndroidAppDataStreamsRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListAndroidAppDataStreamsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_android_app_data_streams), "__call__" + type(client.transport.list_android_app_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -7795,7 +8542,7 @@ async def test_list_android_app_data_streams_async(transport: str = "grpc_asynci assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListAndroidAppDataStreamsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAndroidAppDataStreamsAsyncPager) @@ -7803,6 +8550,11 @@ async def test_list_android_app_data_streams_async(transport: str = "grpc_asynci assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_android_app_data_streams_async_from_dict(): + await test_list_android_app_data_streams_async(request_type=dict) + + def test_list_android_app_data_streams_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -7815,7 +8567,7 @@ def test_list_android_app_data_streams_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_android_app_data_streams), "__call__" + type(client.transport.list_android_app_data_streams), "__call__" ) as call: call.return_value = analytics_admin.ListAndroidAppDataStreamsResponse() @@ -7844,7 +8596,7 @@ async def test_list_android_app_data_streams_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_android_app_data_streams), "__call__" + type(client.transport.list_android_app_data_streams), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListAndroidAppDataStreamsResponse() @@ -7869,7 +8621,7 @@ def test_list_android_app_data_streams_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_android_app_data_streams), "__call__" + type(client.transport.list_android_app_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListAndroidAppDataStreamsResponse() @@ -7907,7 +8659,7 @@ async def test_list_android_app_data_streams_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_android_app_data_streams), "__call__" + type(client.transport.list_android_app_data_streams), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListAndroidAppDataStreamsResponse() @@ -7946,7 +8698,7 @@ def test_list_android_app_data_streams_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_android_app_data_streams), "__call__" + type(client.transport.list_android_app_data_streams), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -7992,7 +8744,7 @@ def test_list_android_app_data_streams_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_android_app_data_streams), "__call__" + type(client.transport.list_android_app_data_streams), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -8020,8 +8772,8 @@ def test_list_android_app_data_streams_pages(): RuntimeError, ) pages = list(client.list_android_app_data_streams(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -8032,7 +8784,7 @@ async def test_list_android_app_data_streams_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_android_app_data_streams), + type(client.transport.list_android_app_data_streams), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -8079,7 +8831,7 @@ async def test_list_android_app_data_streams_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_android_app_data_streams), + type(client.transport.list_android_app_data_streams), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -8109,26 +8861,29 @@ async def test_list_android_app_data_streams_async_pages(): RuntimeError, ) pages = [] - async for page in ( + async for page_ in ( await client.list_android_app_data_streams(request={}) ).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_get_enhanced_measurement_settings(transport: str = "grpc"): +def test_get_enhanced_measurement_settings( + transport: str = "grpc", + request_type=analytics_admin.GetEnhancedMeasurementSettingsRequest, +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetEnhancedMeasurementSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_enhanced_measurement_settings), "__call__" + type(client.transport.get_enhanced_measurement_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.EnhancedMeasurementSettings( @@ -8158,9 +8913,10 @@ def test_get_enhanced_measurement_settings(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetEnhancedMeasurementSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.EnhancedMeasurementSettings) assert response.name == "name_value" @@ -8200,19 +8956,26 @@ def test_get_enhanced_measurement_settings(transport: str = "grpc"): assert response.excluded_domains == "excluded_domains_value" +def test_get_enhanced_measurement_settings_from_dict(): + test_get_enhanced_measurement_settings(request_type=dict) + + @pytest.mark.asyncio -async def test_get_enhanced_measurement_settings_async(transport: str = "grpc_asyncio"): +async def test_get_enhanced_measurement_settings_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.GetEnhancedMeasurementSettingsRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetEnhancedMeasurementSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_enhanced_measurement_settings), "__call__" + type(client.transport.get_enhanced_measurement_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -8244,7 +9007,7 @@ async def test_get_enhanced_measurement_settings_async(transport: str = "grpc_as assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetEnhancedMeasurementSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.EnhancedMeasurementSettings) @@ -8286,6 +9049,11 @@ async def test_get_enhanced_measurement_settings_async(transport: str = "grpc_as assert response.excluded_domains == "excluded_domains_value" +@pytest.mark.asyncio +async def test_get_enhanced_measurement_settings_async_from_dict(): + await test_get_enhanced_measurement_settings_async(request_type=dict) + + def test_get_enhanced_measurement_settings_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -8298,7 +9066,7 @@ def test_get_enhanced_measurement_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_enhanced_measurement_settings), "__call__" + type(client.transport.get_enhanced_measurement_settings), "__call__" ) as call: call.return_value = resources.EnhancedMeasurementSettings() @@ -8327,7 +9095,7 @@ async def test_get_enhanced_measurement_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_enhanced_measurement_settings), "__call__" + type(client.transport.get_enhanced_measurement_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.EnhancedMeasurementSettings() @@ -8352,7 +9120,7 @@ def test_get_enhanced_measurement_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_enhanced_measurement_settings), "__call__" + type(client.transport.get_enhanced_measurement_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.EnhancedMeasurementSettings() @@ -8390,7 +9158,7 @@ async def test_get_enhanced_measurement_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_enhanced_measurement_settings), "__call__" + type(client.transport.get_enhanced_measurement_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.EnhancedMeasurementSettings() @@ -8424,18 +9192,21 @@ async def test_get_enhanced_measurement_settings_flattened_error_async(): ) -def test_update_enhanced_measurement_settings(transport: str = "grpc"): +def test_update_enhanced_measurement_settings( + transport: str = "grpc", + request_type=analytics_admin.UpdateEnhancedMeasurementSettingsRequest, +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateEnhancedMeasurementSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_enhanced_measurement_settings), "__call__" + type(client.transport.update_enhanced_measurement_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.EnhancedMeasurementSettings( @@ -8465,9 +9236,10 @@ def test_update_enhanced_measurement_settings(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateEnhancedMeasurementSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.EnhancedMeasurementSettings) assert response.name == "name_value" @@ -8507,9 +9279,14 @@ def test_update_enhanced_measurement_settings(transport: str = "grpc"): assert response.excluded_domains == "excluded_domains_value" +def test_update_enhanced_measurement_settings_from_dict(): + test_update_enhanced_measurement_settings(request_type=dict) + + @pytest.mark.asyncio async def test_update_enhanced_measurement_settings_async( transport: str = "grpc_asyncio", + request_type=analytics_admin.UpdateEnhancedMeasurementSettingsRequest, ): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -8517,11 +9294,11 @@ async def test_update_enhanced_measurement_settings_async( # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateEnhancedMeasurementSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_enhanced_measurement_settings), "__call__" + type(client.transport.update_enhanced_measurement_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -8553,7 +9330,7 @@ async def test_update_enhanced_measurement_settings_async( assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateEnhancedMeasurementSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.EnhancedMeasurementSettings) @@ -8595,6 +9372,11 @@ async def test_update_enhanced_measurement_settings_async( assert response.excluded_domains == "excluded_domains_value" +@pytest.mark.asyncio +async def test_update_enhanced_measurement_settings_async_from_dict(): + await test_update_enhanced_measurement_settings_async(request_type=dict) + + def test_update_enhanced_measurement_settings_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -8609,7 +9391,7 @@ def test_update_enhanced_measurement_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_enhanced_measurement_settings), "__call__" + type(client.transport.update_enhanced_measurement_settings), "__call__" ) as call: call.return_value = resources.EnhancedMeasurementSettings() @@ -8643,7 +9425,7 @@ async def test_update_enhanced_measurement_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_enhanced_measurement_settings), "__call__" + type(client.transport.update_enhanced_measurement_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.EnhancedMeasurementSettings() @@ -8671,7 +9453,7 @@ def test_update_enhanced_measurement_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_enhanced_measurement_settings), "__call__" + type(client.transport.update_enhanced_measurement_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.EnhancedMeasurementSettings() @@ -8724,7 +9506,7 @@ async def test_update_enhanced_measurement_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_enhanced_measurement_settings), "__call__" + type(client.transport.update_enhanced_measurement_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.EnhancedMeasurementSettings() @@ -8773,18 +9555,20 @@ async def test_update_enhanced_measurement_settings_flattened_error_async(): ) -def test_create_firebase_link(transport: str = "grpc"): +def test_create_firebase_link( + transport: str = "grpc", request_type=analytics_admin.CreateFirebaseLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateFirebaseLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_firebase_link), "__call__" + type(client.transport.create_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.FirebaseLink( @@ -8799,9 +9583,10 @@ def test_create_firebase_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateFirebaseLinkRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.FirebaseLink) assert response.name == "name_value" @@ -8811,19 +9596,26 @@ def test_create_firebase_link(transport: str = "grpc"): assert response.maximum_user_access == resources.MaximumUserAccess.NO_ACCESS +def test_create_firebase_link_from_dict(): + test_create_firebase_link(request_type=dict) + + @pytest.mark.asyncio -async def test_create_firebase_link_async(transport: str = "grpc_asyncio"): +async def test_create_firebase_link_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.CreateFirebaseLinkRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateFirebaseLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_firebase_link), "__call__" + type(client.transport.create_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -8840,7 +9632,7 @@ async def test_create_firebase_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateFirebaseLinkRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.FirebaseLink) @@ -8852,6 +9644,11 @@ async def test_create_firebase_link_async(transport: str = "grpc_asyncio"): assert response.maximum_user_access == resources.MaximumUserAccess.NO_ACCESS +@pytest.mark.asyncio +async def test_create_firebase_link_async_from_dict(): + await test_create_firebase_link_async(request_type=dict) + + def test_create_firebase_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -8864,7 +9661,7 @@ def test_create_firebase_link_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_firebase_link), "__call__" + type(client.transport.create_firebase_link), "__call__" ) as call: call.return_value = resources.FirebaseLink() @@ -8893,7 +9690,7 @@ async def test_create_firebase_link_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_firebase_link), "__call__" + type(client.transport.create_firebase_link), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.FirebaseLink() @@ -8918,7 +9715,7 @@ def test_create_firebase_link_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_firebase_link), "__call__" + type(client.transport.create_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.FirebaseLink() @@ -8963,7 +9760,7 @@ async def test_create_firebase_link_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_firebase_link), "__call__" + type(client.transport.create_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.FirebaseLink() @@ -9004,18 +9801,20 @@ async def test_create_firebase_link_flattened_error_async(): ) -def test_update_firebase_link(transport: str = "grpc"): +def test_update_firebase_link( + transport: str = "grpc", request_type=analytics_admin.UpdateFirebaseLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateFirebaseLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_firebase_link), "__call__" + type(client.transport.update_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.FirebaseLink( @@ -9030,9 +9829,10 @@ def test_update_firebase_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateFirebaseLinkRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.FirebaseLink) assert response.name == "name_value" @@ -9042,19 +9842,26 @@ def test_update_firebase_link(transport: str = "grpc"): assert response.maximum_user_access == resources.MaximumUserAccess.NO_ACCESS +def test_update_firebase_link_from_dict(): + test_update_firebase_link(request_type=dict) + + @pytest.mark.asyncio -async def test_update_firebase_link_async(transport: str = "grpc_asyncio"): +async def test_update_firebase_link_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.UpdateFirebaseLinkRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateFirebaseLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_firebase_link), "__call__" + type(client.transport.update_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -9071,7 +9878,7 @@ async def test_update_firebase_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateFirebaseLinkRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.FirebaseLink) @@ -9083,6 +9890,11 @@ async def test_update_firebase_link_async(transport: str = "grpc_asyncio"): assert response.maximum_user_access == resources.MaximumUserAccess.NO_ACCESS +@pytest.mark.asyncio +async def test_update_firebase_link_async_from_dict(): + await test_update_firebase_link_async(request_type=dict) + + def test_update_firebase_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -9095,7 +9907,7 @@ def test_update_firebase_link_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_firebase_link), "__call__" + type(client.transport.update_firebase_link), "__call__" ) as call: call.return_value = resources.FirebaseLink() @@ -9127,7 +9939,7 @@ async def test_update_firebase_link_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_firebase_link), "__call__" + type(client.transport.update_firebase_link), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.FirebaseLink() @@ -9155,7 +9967,7 @@ def test_update_firebase_link_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_firebase_link), "__call__" + type(client.transport.update_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.FirebaseLink() @@ -9200,7 +10012,7 @@ async def test_update_firebase_link_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_firebase_link), "__call__" + type(client.transport.update_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.FirebaseLink() @@ -9241,18 +10053,20 @@ async def test_update_firebase_link_flattened_error_async(): ) -def test_delete_firebase_link(transport: str = "grpc"): +def test_delete_firebase_link( + transport: str = "grpc", request_type=analytics_admin.DeleteFirebaseLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteFirebaseLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_firebase_link), "__call__" + type(client.transport.delete_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -9263,25 +10077,32 @@ def test_delete_firebase_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteFirebaseLinkRequest() # Establish that the response is the type that we expect. assert response is None +def test_delete_firebase_link_from_dict(): + test_delete_firebase_link(request_type=dict) + + @pytest.mark.asyncio -async def test_delete_firebase_link_async(transport: str = "grpc_asyncio"): +async def test_delete_firebase_link_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.DeleteFirebaseLinkRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteFirebaseLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_firebase_link), "__call__" + type(client.transport.delete_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -9292,12 +10113,17 @@ async def test_delete_firebase_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteFirebaseLinkRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_firebase_link_async_from_dict(): + await test_delete_firebase_link_async(request_type=dict) + + def test_delete_firebase_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -9310,7 +10136,7 @@ def test_delete_firebase_link_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_firebase_link), "__call__" + type(client.transport.delete_firebase_link), "__call__" ) as call: call.return_value = None @@ -9339,7 +10165,7 @@ async def test_delete_firebase_link_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_firebase_link), "__call__" + type(client.transport.delete_firebase_link), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -9362,7 +10188,7 @@ def test_delete_firebase_link_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_firebase_link), "__call__" + type(client.transport.delete_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -9400,7 +10226,7 @@ async def test_delete_firebase_link_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_firebase_link), "__call__" + type(client.transport.delete_firebase_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -9432,18 +10258,20 @@ async def test_delete_firebase_link_flattened_error_async(): ) -def test_list_firebase_links(transport: str = "grpc"): +def test_list_firebase_links( + transport: str = "grpc", request_type=analytics_admin.ListFirebaseLinksRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListFirebaseLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_firebase_links), "__call__" + type(client.transport.list_firebase_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListFirebaseLinksResponse() @@ -9454,25 +10282,33 @@ def test_list_firebase_links(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListFirebaseLinksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, analytics_admin.ListFirebaseLinksResponse) +def test_list_firebase_links_from_dict(): + test_list_firebase_links(request_type=dict) + + @pytest.mark.asyncio -async def test_list_firebase_links_async(transport: str = "grpc_asyncio"): +async def test_list_firebase_links_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.ListFirebaseLinksRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListFirebaseLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_firebase_links), "__call__" + type(client.transport.list_firebase_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -9485,12 +10321,17 @@ async def test_list_firebase_links_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListFirebaseLinksRequest() # Establish that the response is the type that we expect. assert isinstance(response, analytics_admin.ListFirebaseLinksResponse) +@pytest.mark.asyncio +async def test_list_firebase_links_async_from_dict(): + await test_list_firebase_links_async(request_type=dict) + + def test_list_firebase_links_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -9503,7 +10344,7 @@ def test_list_firebase_links_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_firebase_links), "__call__" + type(client.transport.list_firebase_links), "__call__" ) as call: call.return_value = analytics_admin.ListFirebaseLinksResponse() @@ -9532,7 +10373,7 @@ async def test_list_firebase_links_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_firebase_links), "__call__" + type(client.transport.list_firebase_links), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListFirebaseLinksResponse() @@ -9557,7 +10398,7 @@ def test_list_firebase_links_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_firebase_links), "__call__" + type(client.transport.list_firebase_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListFirebaseLinksResponse() @@ -9595,7 +10436,7 @@ async def test_list_firebase_links_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_firebase_links), "__call__" + type(client.transport.list_firebase_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListFirebaseLinksResponse() @@ -9629,21 +10470,25 @@ async def test_list_firebase_links_flattened_error_async(): ) -def test_get_global_site_tag(transport: str = "grpc"): +def test_get_global_site_tag( + transport: str = "grpc", request_type=analytics_admin.GetGlobalSiteTagRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetGlobalSiteTagRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_global_site_tag), "__call__" + type(client.transport.get_global_site_tag), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = resources.GlobalSiteTag(snippet="snippet_value",) + call.return_value = resources.GlobalSiteTag( + snippet="snippet_value", name="name_value", + ) response = client.get_global_site_tag(request) @@ -9651,31 +10496,41 @@ def test_get_global_site_tag(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetGlobalSiteTagRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.GlobalSiteTag) assert response.snippet == "snippet_value" + assert response.name == "name_value" + + +def test_get_global_site_tag_from_dict(): + test_get_global_site_tag(request_type=dict) + @pytest.mark.asyncio -async def test_get_global_site_tag_async(transport: str = "grpc_asyncio"): +async def test_get_global_site_tag_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.GetGlobalSiteTagRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetGlobalSiteTagRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_global_site_tag), "__call__" + type(client.transport.get_global_site_tag), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - resources.GlobalSiteTag(snippet="snippet_value",) + resources.GlobalSiteTag(snippet="snippet_value", name="name_value",) ) response = await client.get_global_site_tag(request) @@ -9684,13 +10539,20 @@ async def test_get_global_site_tag_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetGlobalSiteTagRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.GlobalSiteTag) assert response.snippet == "snippet_value" + assert response.name == "name_value" + + +@pytest.mark.asyncio +async def test_get_global_site_tag_async_from_dict(): + await test_get_global_site_tag_async(request_type=dict) + def test_get_global_site_tag_field_headers(): client = AnalyticsAdminServiceClient( @@ -9704,7 +10566,7 @@ def test_get_global_site_tag_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_global_site_tag), "__call__" + type(client.transport.get_global_site_tag), "__call__" ) as call: call.return_value = resources.GlobalSiteTag() @@ -9733,7 +10595,7 @@ async def test_get_global_site_tag_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_global_site_tag), "__call__" + type(client.transport.get_global_site_tag), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.GlobalSiteTag() @@ -9758,7 +10620,7 @@ def test_get_global_site_tag_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_global_site_tag), "__call__" + type(client.transport.get_global_site_tag), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.GlobalSiteTag() @@ -9796,7 +10658,7 @@ async def test_get_global_site_tag_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_global_site_tag), "__call__" + type(client.transport.get_global_site_tag), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.GlobalSiteTag() @@ -9830,18 +10692,20 @@ async def test_get_global_site_tag_flattened_error_async(): ) -def test_create_google_ads_link(transport: str = "grpc"): +def test_create_google_ads_link( + transport: str = "grpc", request_type=analytics_admin.CreateGoogleAdsLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateGoogleAdsLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_google_ads_link), "__call__" + type(client.transport.create_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.GoogleAdsLink( @@ -9858,9 +10722,10 @@ def test_create_google_ads_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateGoogleAdsLinkRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.GoogleAdsLink) assert response.name == "name_value" @@ -9874,19 +10739,26 @@ def test_create_google_ads_link(transport: str = "grpc"): assert response.email_address == "email_address_value" +def test_create_google_ads_link_from_dict(): + test_create_google_ads_link(request_type=dict) + + @pytest.mark.asyncio -async def test_create_google_ads_link_async(transport: str = "grpc_asyncio"): +async def test_create_google_ads_link_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.CreateGoogleAdsLinkRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.CreateGoogleAdsLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_google_ads_link), "__call__" + type(client.transport.create_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -9905,7 +10777,7 @@ async def test_create_google_ads_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.CreateGoogleAdsLinkRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.GoogleAdsLink) @@ -9921,6 +10793,11 @@ async def test_create_google_ads_link_async(transport: str = "grpc_asyncio"): assert response.email_address == "email_address_value" +@pytest.mark.asyncio +async def test_create_google_ads_link_async_from_dict(): + await test_create_google_ads_link_async(request_type=dict) + + def test_create_google_ads_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -9933,7 +10810,7 @@ def test_create_google_ads_link_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_google_ads_link), "__call__" + type(client.transport.create_google_ads_link), "__call__" ) as call: call.return_value = resources.GoogleAdsLink() @@ -9962,7 +10839,7 @@ async def test_create_google_ads_link_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_google_ads_link), "__call__" + type(client.transport.create_google_ads_link), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.GoogleAdsLink() @@ -9987,7 +10864,7 @@ def test_create_google_ads_link_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_google_ads_link), "__call__" + type(client.transport.create_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.GoogleAdsLink() @@ -10032,7 +10909,7 @@ async def test_create_google_ads_link_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_google_ads_link), "__call__" + type(client.transport.create_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.GoogleAdsLink() @@ -10073,18 +10950,20 @@ async def test_create_google_ads_link_flattened_error_async(): ) -def test_update_google_ads_link(transport: str = "grpc"): +def test_update_google_ads_link( + transport: str = "grpc", request_type=analytics_admin.UpdateGoogleAdsLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateGoogleAdsLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_google_ads_link), "__call__" + type(client.transport.update_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.GoogleAdsLink( @@ -10101,9 +10980,10 @@ def test_update_google_ads_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateGoogleAdsLinkRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.GoogleAdsLink) assert response.name == "name_value" @@ -10117,19 +10997,26 @@ def test_update_google_ads_link(transport: str = "grpc"): assert response.email_address == "email_address_value" +def test_update_google_ads_link_from_dict(): + test_update_google_ads_link(request_type=dict) + + @pytest.mark.asyncio -async def test_update_google_ads_link_async(transport: str = "grpc_asyncio"): +async def test_update_google_ads_link_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.UpdateGoogleAdsLinkRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.UpdateGoogleAdsLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_google_ads_link), "__call__" + type(client.transport.update_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -10148,7 +11035,7 @@ async def test_update_google_ads_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.UpdateGoogleAdsLinkRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.GoogleAdsLink) @@ -10164,6 +11051,11 @@ async def test_update_google_ads_link_async(transport: str = "grpc_asyncio"): assert response.email_address == "email_address_value" +@pytest.mark.asyncio +async def test_update_google_ads_link_async_from_dict(): + await test_update_google_ads_link_async(request_type=dict) + + def test_update_google_ads_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -10176,7 +11068,7 @@ def test_update_google_ads_link_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_google_ads_link), "__call__" + type(client.transport.update_google_ads_link), "__call__" ) as call: call.return_value = resources.GoogleAdsLink() @@ -10208,7 +11100,7 @@ async def test_update_google_ads_link_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_google_ads_link), "__call__" + type(client.transport.update_google_ads_link), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.GoogleAdsLink() @@ -10236,7 +11128,7 @@ def test_update_google_ads_link_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_google_ads_link), "__call__" + type(client.transport.update_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.GoogleAdsLink() @@ -10281,7 +11173,7 @@ async def test_update_google_ads_link_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_google_ads_link), "__call__" + type(client.transport.update_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.GoogleAdsLink() @@ -10322,18 +11214,20 @@ async def test_update_google_ads_link_flattened_error_async(): ) -def test_delete_google_ads_link(transport: str = "grpc"): +def test_delete_google_ads_link( + transport: str = "grpc", request_type=analytics_admin.DeleteGoogleAdsLinkRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteGoogleAdsLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_google_ads_link), "__call__" + type(client.transport.delete_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -10344,25 +11238,32 @@ def test_delete_google_ads_link(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteGoogleAdsLinkRequest() # Establish that the response is the type that we expect. assert response is None +def test_delete_google_ads_link_from_dict(): + test_delete_google_ads_link(request_type=dict) + + @pytest.mark.asyncio -async def test_delete_google_ads_link_async(transport: str = "grpc_asyncio"): +async def test_delete_google_ads_link_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.DeleteGoogleAdsLinkRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.DeleteGoogleAdsLinkRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_google_ads_link), "__call__" + type(client.transport.delete_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -10373,12 +11274,17 @@ async def test_delete_google_ads_link_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.DeleteGoogleAdsLinkRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_google_ads_link_async_from_dict(): + await test_delete_google_ads_link_async(request_type=dict) + + def test_delete_google_ads_link_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -10391,7 +11297,7 @@ def test_delete_google_ads_link_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_google_ads_link), "__call__" + type(client.transport.delete_google_ads_link), "__call__" ) as call: call.return_value = None @@ -10420,7 +11326,7 @@ async def test_delete_google_ads_link_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_google_ads_link), "__call__" + type(client.transport.delete_google_ads_link), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -10443,7 +11349,7 @@ def test_delete_google_ads_link_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_google_ads_link), "__call__" + type(client.transport.delete_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -10481,7 +11387,7 @@ async def test_delete_google_ads_link_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_google_ads_link), "__call__" + type(client.transport.delete_google_ads_link), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -10513,18 +11419,20 @@ async def test_delete_google_ads_link_flattened_error_async(): ) -def test_list_google_ads_links(transport: str = "grpc"): +def test_list_google_ads_links( + transport: str = "grpc", request_type=analytics_admin.ListGoogleAdsLinksRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListGoogleAdsLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_google_ads_links), "__call__" + type(client.transport.list_google_ads_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListGoogleAdsLinksResponse( @@ -10537,27 +11445,35 @@ def test_list_google_ads_links(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListGoogleAdsLinksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListGoogleAdsLinksPager) assert response.next_page_token == "next_page_token_value" +def test_list_google_ads_links_from_dict(): + test_list_google_ads_links(request_type=dict) + + @pytest.mark.asyncio -async def test_list_google_ads_links_async(transport: str = "grpc_asyncio"): +async def test_list_google_ads_links_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.ListGoogleAdsLinksRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.ListGoogleAdsLinksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_google_ads_links), "__call__" + type(client.transport.list_google_ads_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -10572,7 +11488,7 @@ async def test_list_google_ads_links_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.ListGoogleAdsLinksRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListGoogleAdsLinksAsyncPager) @@ -10580,6 +11496,11 @@ async def test_list_google_ads_links_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_google_ads_links_async_from_dict(): + await test_list_google_ads_links_async(request_type=dict) + + def test_list_google_ads_links_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -10592,7 +11513,7 @@ def test_list_google_ads_links_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_google_ads_links), "__call__" + type(client.transport.list_google_ads_links), "__call__" ) as call: call.return_value = analytics_admin.ListGoogleAdsLinksResponse() @@ -10621,7 +11542,7 @@ async def test_list_google_ads_links_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_google_ads_links), "__call__" + type(client.transport.list_google_ads_links), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( analytics_admin.ListGoogleAdsLinksResponse() @@ -10646,7 +11567,7 @@ def test_list_google_ads_links_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_google_ads_links), "__call__" + type(client.transport.list_google_ads_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListGoogleAdsLinksResponse() @@ -10684,7 +11605,7 @@ async def test_list_google_ads_links_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_google_ads_links), "__call__" + type(client.transport.list_google_ads_links), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = analytics_admin.ListGoogleAdsLinksResponse() @@ -10723,7 +11644,7 @@ def test_list_google_ads_links_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_google_ads_links), "__call__" + type(client.transport.list_google_ads_links), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -10768,7 +11689,7 @@ def test_list_google_ads_links_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_google_ads_links), "__call__" + type(client.transport.list_google_ads_links), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -10795,8 +11716,8 @@ def test_list_google_ads_links_pages(): RuntimeError, ) pages = list(client.list_google_ads_links(request={}).pages) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio @@ -10807,7 +11728,7 @@ async def test_list_google_ads_links_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_google_ads_links), + type(client.transport.list_google_ads_links), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -10853,7 +11774,7 @@ async def test_list_google_ads_links_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_google_ads_links), + type(client.transport.list_google_ads_links), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -10882,24 +11803,26 @@ async def test_list_google_ads_links_async_pages(): RuntimeError, ) pages = [] - async for page in (await client.list_google_ads_links(request={})).pages: - pages.append(page) - for page, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page.raw_page.next_page_token == token + async for page_ in (await client.list_google_ads_links(request={})).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_get_data_sharing_settings(transport: str = "grpc"): +def test_get_data_sharing_settings( + transport: str = "grpc", request_type=analytics_admin.GetDataSharingSettingsRequest +): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetDataSharingSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_data_sharing_settings), "__call__" + type(client.transport.get_data_sharing_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.DataSharingSettings( @@ -10917,9 +11840,10 @@ def test_get_data_sharing_settings(transport: str = "grpc"): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetDataSharingSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, resources.DataSharingSettings) assert response.name == "name_value" @@ -10935,19 +11859,26 @@ def test_get_data_sharing_settings(transport: str = "grpc"): assert response.sharing_with_others_enabled is True +def test_get_data_sharing_settings_from_dict(): + test_get_data_sharing_settings(request_type=dict) + + @pytest.mark.asyncio -async def test_get_data_sharing_settings_async(transport: str = "grpc_asyncio"): +async def test_get_data_sharing_settings_async( + transport: str = "grpc_asyncio", + request_type=analytics_admin.GetDataSharingSettingsRequest, +): client = AnalyticsAdminServiceAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = analytics_admin.GetDataSharingSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_data_sharing_settings), "__call__" + type(client.transport.get_data_sharing_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -10967,7 +11898,7 @@ async def test_get_data_sharing_settings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == analytics_admin.GetDataSharingSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.DataSharingSettings) @@ -10985,6 +11916,11 @@ async def test_get_data_sharing_settings_async(transport: str = "grpc_asyncio"): assert response.sharing_with_others_enabled is True +@pytest.mark.asyncio +async def test_get_data_sharing_settings_async_from_dict(): + await test_get_data_sharing_settings_async(request_type=dict) + + def test_get_data_sharing_settings_field_headers(): client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), @@ -10997,7 +11933,7 @@ def test_get_data_sharing_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_data_sharing_settings), "__call__" + type(client.transport.get_data_sharing_settings), "__call__" ) as call: call.return_value = resources.DataSharingSettings() @@ -11026,7 +11962,7 @@ async def test_get_data_sharing_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_data_sharing_settings), "__call__" + type(client.transport.get_data_sharing_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( resources.DataSharingSettings() @@ -11051,7 +11987,7 @@ def test_get_data_sharing_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_data_sharing_settings), "__call__" + type(client.transport.get_data_sharing_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.DataSharingSettings() @@ -11089,7 +12025,7 @@ async def test_get_data_sharing_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_data_sharing_settings), "__call__" + type(client.transport.get_data_sharing_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = resources.DataSharingSettings() @@ -11159,7 +12095,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = AnalyticsAdminServiceClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -11177,12 +12113,27 @@ def test_transport_get_channel(): assert channel +@pytest.mark.parametrize( + "transport_class", + [ + transports.AnalyticsAdminServiceGrpcTransport, + transports.AnalyticsAdminServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(auth, "default") as adc: + adc.return_value = (credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AnalyticsAdminServiceClient( credentials=credentials.AnonymousCredentials(), ) - assert isinstance(client._transport, transports.AnalyticsAdminServiceGrpcTransport,) + assert isinstance(client.transport, transports.AnalyticsAdminServiceGrpcTransport,) def test_analytics_admin_service_base_transport_error(): @@ -11196,9 +12147,13 @@ def test_analytics_admin_service_base_transport_error(): def test_analytics_admin_service_base_transport(): # Instantiate the base transport. - transport = transports.AnalyticsAdminServiceTransport( - credentials=credentials.AnonymousCredentials(), - ) + with mock.patch( + "google.analytics.admin_v1alpha.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.AnalyticsAdminServiceTransport( + credentials=credentials.AnonymousCredentials(), + ) # Every method on the transport should just blindly # raise NotImplementedError. @@ -11208,6 +12163,7 @@ def test_analytics_admin_service_base_transport(): "delete_account", "update_account", "provision_account_ticket", + "list_account_summaries", "get_property", "list_properties", "create_property", @@ -11258,7 +12214,12 @@ def test_analytics_admin_service_base_transport(): def test_analytics_admin_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object(auth, "load_credentials_from_file") as load_creds: + with mock.patch.object( + auth, "load_credentials_from_file" + ) as load_creds, mock.patch( + "google.analytics.admin_v1alpha.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None load_creds.return_value = (credentials.AnonymousCredentials(), None) transport = transports.AnalyticsAdminServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -11275,6 +12236,17 @@ def test_analytics_admin_service_base_transport_with_credentials_file(): ) +def test_analytics_admin_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(auth, "default") as adc, mock.patch( + "google.analytics.admin_v1alpha.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (credentials.AnonymousCredentials(), None) + transport = transports.AnalyticsAdminServiceTransport() + adc.assert_called_once() + + def test_analytics_admin_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(auth, "default") as adc: @@ -11317,7 +12289,7 @@ def test_analytics_admin_service_host_no_port(): api_endpoint="analyticsadmin.googleapis.com" ), ) - assert client._transport._host == "analyticsadmin.googleapis.com:443" + assert client.transport._host == "analyticsadmin.googleapis.com:443" def test_analytics_admin_service_host_with_port(): @@ -11327,210 +12299,182 @@ def test_analytics_admin_service_host_with_port(): api_endpoint="analyticsadmin.googleapis.com:8000" ), ) - assert client._transport._host == "analyticsadmin.googleapis.com:8000" + assert client.transport._host == "analyticsadmin.googleapis.com:8000" def test_analytics_admin_service_grpc_transport_channel(): channel = grpc.insecure_channel("http://localhost/") - # Check that if channel is provided, mtls endpoint and client_cert_source - # won't be used. - callback = mock.MagicMock() + # Check that channel is used if provided. transport = transports.AnalyticsAdminServiceGrpcTransport( - host="squid.clam.whelk", - channel=channel, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=callback, + host="squid.clam.whelk", channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" - assert not callback.called + assert transport._ssl_channel_credentials == None def test_analytics_admin_service_grpc_asyncio_transport_channel(): channel = aio.insecure_channel("http://localhost/") - # Check that if channel is provided, mtls endpoint and client_cert_source - # won't be used. - callback = mock.MagicMock() + # Check that channel is used if provided. transport = transports.AnalyticsAdminServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=callback, + host="squid.clam.whelk", channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" - assert not callback.called + assert transport._ssl_channel_credentials == None -@mock.patch("grpc.ssl_channel_credentials", autospec=True) -@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) -def test_analytics_admin_service_grpc_transport_channel_mtls_with_client_cert_source( - grpc_create_channel, grpc_ssl_channel_cred +@pytest.mark.parametrize( + "transport_class", + [ + transports.AnalyticsAdminServiceGrpcTransport, + transports.AnalyticsAdminServiceGrpcAsyncIOTransport, + ], +) +def test_analytics_admin_service_transport_channel_mtls_with_client_cert_source( + transport_class, ): - # Check that if channel is None, but api_mtls_endpoint and client_cert_source - # are provided, then a mTLS channel will be created. - mock_cred = mock.Mock() + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel", autospec=True + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/analytics.edit", + "https://www.googleapis.com/auth/analytics.manage.users", + "https://www.googleapis.com/auth/analytics.manage.users.readonly", + "https://www.googleapis.com/auth/analytics.readonly", + ), + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + +@pytest.mark.parametrize( + "transport_class", + [ + transports.AnalyticsAdminServiceGrpcTransport, + transports.AnalyticsAdminServiceGrpcAsyncIOTransport, + ], +) +def test_analytics_admin_service_transport_channel_mtls_with_adc(transport_class): mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel", autospec=True + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=( + "https://www.googleapis.com/auth/analytics.edit", + "https://www.googleapis.com/auth/analytics.manage.users", + "https://www.googleapis.com/auth/analytics.manage.users.readonly", + "https://www.googleapis.com/auth/analytics.readonly", + ), + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel - transport = transports.AnalyticsAdminServiceGrpcTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=( - "https://www.googleapis.com/auth/analytics.edit", - "https://www.googleapis.com/auth/analytics.manage.users", - "https://www.googleapis.com/auth/analytics.manage.users.readonly", - "https://www.googleapis.com/auth/analytics.readonly", - ), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel +def test_account_path(): + account = "squid" -@mock.patch("grpc.ssl_channel_credentials", autospec=True) -@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) -def test_analytics_admin_service_grpc_asyncio_transport_channel_mtls_with_client_cert_source( - grpc_create_channel, grpc_ssl_channel_cred -): - # Check that if channel is None, but api_mtls_endpoint and client_cert_source - # are provided, then a mTLS channel will be created. - mock_cred = mock.Mock() + expected = "accounts/{account}".format(account=account,) + actual = AnalyticsAdminServiceClient.account_path(account) + assert expected == actual - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel +def test_parse_account_path(): + expected = { + "account": "clam", + } + path = AnalyticsAdminServiceClient.account_path(**expected) - transport = transports.AnalyticsAdminServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=( - "https://www.googleapis.com/auth/analytics.edit", - "https://www.googleapis.com/auth/analytics.manage.users", - "https://www.googleapis.com/auth/analytics.manage.users.readonly", - "https://www.googleapis.com/auth/analytics.readonly", - ), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + # Check that the path construction is reversible. + actual = AnalyticsAdminServiceClient.parse_account_path(path) + assert expected == actual -@pytest.mark.parametrize( - "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] -) -@mock.patch("google.api_core.grpc_helpers.create_channel", autospec=True) -def test_analytics_admin_service_grpc_transport_channel_mtls_with_adc( - grpc_create_channel, api_mtls_endpoint -): - # Check that if channel and client_cert_source are None, but api_mtls_endpoint - # is provided, then a mTLS channel will be created with SSL ADC. - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel +def test_account_summary_path(): + account_summary = "whelk" - # Mock google.auth.transport.grpc.SslCredentials class. - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - mock_cred = mock.Mock() - transport = transports.AnalyticsAdminServiceGrpcTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint=api_mtls_endpoint, - client_cert_source=None, - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=( - "https://www.googleapis.com/auth/analytics.edit", - "https://www.googleapis.com/auth/analytics.manage.users", - "https://www.googleapis.com/auth/analytics.manage.users.readonly", - "https://www.googleapis.com/auth/analytics.readonly", - ), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + expected = "accountSummaries/{account_summary}".format( + account_summary=account_summary, + ) + actual = AnalyticsAdminServiceClient.account_summary_path(account_summary) + assert expected == actual -@pytest.mark.parametrize( - "api_mtls_endpoint", ["mtls.squid.clam.whelk", "mtls.squid.clam.whelk:443"] -) -@mock.patch("google.api_core.grpc_helpers_async.create_channel", autospec=True) -def test_analytics_admin_service_grpc_asyncio_transport_channel_mtls_with_adc( - grpc_create_channel, api_mtls_endpoint -): - # Check that if channel and client_cert_source are None, but api_mtls_endpoint - # is provided, then a mTLS channel will be created with SSL ADC. - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel +def test_parse_account_summary_path(): + expected = { + "account_summary": "octopus", + } + path = AnalyticsAdminServiceClient.account_summary_path(**expected) - # Mock google.auth.transport.grpc.SslCredentials class. - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - mock_cred = mock.Mock() - transport = transports.AnalyticsAdminServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint=api_mtls_endpoint, - client_cert_source=None, - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=( - "https://www.googleapis.com/auth/analytics.edit", - "https://www.googleapis.com/auth/analytics.manage.users", - "https://www.googleapis.com/auth/analytics.manage.users.readonly", - "https://www.googleapis.com/auth/analytics.readonly", - ), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - ) - assert transport.grpc_channel == mock_grpc_channel + # Check that the path construction is reversible. + actual = AnalyticsAdminServiceClient.parse_account_summary_path(path) + assert expected == actual def test_android_app_data_stream_path(): - property = "squid" - android_app_data_stream = "clam" + property = "oyster" + android_app_data_stream = "nudibranch" expected = "properties/{property}/androidAppDataStreams/{android_app_data_stream}".format( property=property, android_app_data_stream=android_app_data_stream, @@ -11543,8 +12487,8 @@ def test_android_app_data_stream_path(): def test_parse_android_app_data_stream_path(): expected = { - "property": "whelk", - "android_app_data_stream": "octopus", + "property": "cuttlefish", + "android_app_data_stream": "mussel", } path = AnalyticsAdminServiceClient.android_app_data_stream_path(**expected) @@ -11553,76 +12497,95 @@ def test_parse_android_app_data_stream_path(): assert expected == actual -def test_property_path(): - property = "squid" +def test_data_sharing_settings_path(): + account = "winkle" - expected = "properties/{property}".format(property=property,) - actual = AnalyticsAdminServiceClient.property_path(property) + expected = "accounts/{account}/dataSharingSettings".format(account=account,) + actual = AnalyticsAdminServiceClient.data_sharing_settings_path(account) assert expected == actual -def test_parse_property_path(): +def test_parse_data_sharing_settings_path(): expected = { - "property": "clam", + "account": "nautilus", } - path = AnalyticsAdminServiceClient.property_path(**expected) + path = AnalyticsAdminServiceClient.data_sharing_settings_path(**expected) # Check that the path construction is reversible. - actual = AnalyticsAdminServiceClient.parse_property_path(path) + actual = AnalyticsAdminServiceClient.parse_data_sharing_settings_path(path) assert expected == actual -def test_user_link_path(): - account = "squid" - user_link = "clam" +def test_enhanced_measurement_settings_path(): + property = "scallop" + web_data_stream = "abalone" - expected = "accounts/{account}/userLinks/{user_link}".format( - account=account, user_link=user_link, + expected = "properties/{property}/webDataStreams/{web_data_stream}/enhancedMeasurementSettings".format( + property=property, web_data_stream=web_data_stream, + ) + actual = AnalyticsAdminServiceClient.enhanced_measurement_settings_path( + property, web_data_stream ) - actual = AnalyticsAdminServiceClient.user_link_path(account, user_link) assert expected == actual -def test_parse_user_link_path(): +def test_parse_enhanced_measurement_settings_path(): expected = { - "account": "whelk", - "user_link": "octopus", + "property": "squid", + "web_data_stream": "clam", } - path = AnalyticsAdminServiceClient.user_link_path(**expected) + path = AnalyticsAdminServiceClient.enhanced_measurement_settings_path(**expected) # Check that the path construction is reversible. - actual = AnalyticsAdminServiceClient.parse_user_link_path(path) + actual = AnalyticsAdminServiceClient.parse_enhanced_measurement_settings_path(path) assert expected == actual -def test_enhanced_measurement_settings_path(): - property = "squid" - web_data_stream = "clam" +def test_firebase_link_path(): + property = "whelk" + firebase_link = "octopus" - expected = "properties/{property}/webDataStreams/{web_data_stream}/enhancedMeasurementSettings".format( - property=property, web_data_stream=web_data_stream, - ) - actual = AnalyticsAdminServiceClient.enhanced_measurement_settings_path( - property, web_data_stream + expected = "properties/{property}/firebaseLinks/{firebase_link}".format( + property=property, firebase_link=firebase_link, ) + actual = AnalyticsAdminServiceClient.firebase_link_path(property, firebase_link) assert expected == actual -def test_parse_enhanced_measurement_settings_path(): +def test_parse_firebase_link_path(): expected = { - "property": "whelk", - "web_data_stream": "octopus", + "property": "oyster", + "firebase_link": "nudibranch", } - path = AnalyticsAdminServiceClient.enhanced_measurement_settings_path(**expected) + path = AnalyticsAdminServiceClient.firebase_link_path(**expected) # Check that the path construction is reversible. - actual = AnalyticsAdminServiceClient.parse_enhanced_measurement_settings_path(path) + actual = AnalyticsAdminServiceClient.parse_firebase_link_path(path) + assert expected == actual + + +def test_global_site_tag_path(): + property = "cuttlefish" + + expected = "properties/{property}/globalSiteTag".format(property=property,) + actual = AnalyticsAdminServiceClient.global_site_tag_path(property) + assert expected == actual + + +def test_parse_global_site_tag_path(): + expected = { + "property": "mussel", + } + path = AnalyticsAdminServiceClient.global_site_tag_path(**expected) + + # Check that the path construction is reversible. + actual = AnalyticsAdminServiceClient.parse_global_site_tag_path(path) assert expected == actual def test_google_ads_link_path(): - property = "squid" - google_ads_link = "clam" + property = "winkle" + google_ads_link = "nautilus" expected = "properties/{property}/googleAdsLinks/{google_ads_link}".format( property=property, google_ads_link=google_ads_link, @@ -11633,8 +12596,8 @@ def test_google_ads_link_path(): def test_parse_google_ads_link_path(): expected = { - "property": "whelk", - "google_ads_link": "octopus", + "property": "scallop", + "google_ads_link": "abalone", } path = AnalyticsAdminServiceClient.google_ads_link_path(**expected) @@ -11643,32 +12606,76 @@ def test_parse_google_ads_link_path(): assert expected == actual -def test_firebase_link_path(): +def test_ios_app_data_stream_path(): property = "squid" - firebase_link = "clam" + ios_app_data_stream = "clam" - expected = "properties/{property}/firebaseLinks/{firebase_link}".format( - property=property, firebase_link=firebase_link, + expected = "properties/{property}/iosAppDataStreams/{ios_app_data_stream}".format( + property=property, ios_app_data_stream=ios_app_data_stream, + ) + actual = AnalyticsAdminServiceClient.ios_app_data_stream_path( + property, ios_app_data_stream ) - actual = AnalyticsAdminServiceClient.firebase_link_path(property, firebase_link) assert expected == actual -def test_parse_firebase_link_path(): +def test_parse_ios_app_data_stream_path(): expected = { "property": "whelk", - "firebase_link": "octopus", + "ios_app_data_stream": "octopus", } - path = AnalyticsAdminServiceClient.firebase_link_path(**expected) + path = AnalyticsAdminServiceClient.ios_app_data_stream_path(**expected) # Check that the path construction is reversible. - actual = AnalyticsAdminServiceClient.parse_firebase_link_path(path) + actual = AnalyticsAdminServiceClient.parse_ios_app_data_stream_path(path) + assert expected == actual + + +def test_property_path(): + property = "oyster" + + expected = "properties/{property}".format(property=property,) + actual = AnalyticsAdminServiceClient.property_path(property) + assert expected == actual + + +def test_parse_property_path(): + expected = { + "property": "nudibranch", + } + path = AnalyticsAdminServiceClient.property_path(**expected) + + # Check that the path construction is reversible. + actual = AnalyticsAdminServiceClient.parse_property_path(path) + assert expected == actual + + +def test_user_link_path(): + account = "cuttlefish" + user_link = "mussel" + + expected = "accounts/{account}/userLinks/{user_link}".format( + account=account, user_link=user_link, + ) + actual = AnalyticsAdminServiceClient.user_link_path(account, user_link) + assert expected == actual + + +def test_parse_user_link_path(): + expected = { + "account": "winkle", + "user_link": "nautilus", + } + path = AnalyticsAdminServiceClient.user_link_path(**expected) + + # Check that the path construction is reversible. + actual = AnalyticsAdminServiceClient.parse_user_link_path(path) assert expected == actual def test_web_data_stream_path(): - property = "squid" - web_data_stream = "clam" + property = "scallop" + web_data_stream = "abalone" expected = "properties/{property}/webDataStreams/{web_data_stream}".format( property=property, web_data_stream=web_data_stream, @@ -11679,8 +12686,8 @@ def test_web_data_stream_path(): def test_parse_web_data_stream_path(): expected = { - "property": "whelk", - "web_data_stream": "octopus", + "property": "squid", + "web_data_stream": "clam", } path = AnalyticsAdminServiceClient.web_data_stream_path(**expected) @@ -11689,45 +12696,123 @@ def test_parse_web_data_stream_path(): assert expected == actual -def test_ios_app_data_stream_path(): - property = "squid" - ios_app_data_stream = "clam" +def test_common_billing_account_path(): + billing_account = "whelk" - expected = "properties/{property}/iosAppDataStreams/{ios_app_data_stream}".format( - property=property, ios_app_data_stream=ios_app_data_stream, - ) - actual = AnalyticsAdminServiceClient.ios_app_data_stream_path( - property, ios_app_data_stream + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, ) + actual = AnalyticsAdminServiceClient.common_billing_account_path(billing_account) assert expected == actual -def test_parse_ios_app_data_stream_path(): +def test_parse_common_billing_account_path(): expected = { - "property": "whelk", - "ios_app_data_stream": "octopus", + "billing_account": "octopus", } - path = AnalyticsAdminServiceClient.ios_app_data_stream_path(**expected) + path = AnalyticsAdminServiceClient.common_billing_account_path(**expected) # Check that the path construction is reversible. - actual = AnalyticsAdminServiceClient.parse_ios_app_data_stream_path(path) + actual = AnalyticsAdminServiceClient.parse_common_billing_account_path(path) assert expected == actual -def test_account_path(): - account = "squid" +def test_common_folder_path(): + folder = "oyster" - expected = "accounts/{account}".format(account=account,) - actual = AnalyticsAdminServiceClient.account_path(account) + expected = "folders/{folder}".format(folder=folder,) + actual = AnalyticsAdminServiceClient.common_folder_path(folder) assert expected == actual -def test_parse_account_path(): +def test_parse_common_folder_path(): expected = { - "account": "clam", + "folder": "nudibranch", } - path = AnalyticsAdminServiceClient.account_path(**expected) + path = AnalyticsAdminServiceClient.common_folder_path(**expected) # Check that the path construction is reversible. - actual = AnalyticsAdminServiceClient.parse_account_path(path) + actual = AnalyticsAdminServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "cuttlefish" + + expected = "organizations/{organization}".format(organization=organization,) + actual = AnalyticsAdminServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "mussel", + } + path = AnalyticsAdminServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = AnalyticsAdminServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "winkle" + + expected = "projects/{project}".format(project=project,) + actual = AnalyticsAdminServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "nautilus", + } + path = AnalyticsAdminServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = AnalyticsAdminServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "scallop" + location = "abalone" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = AnalyticsAdminServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "squid", + "location": "clam", + } + path = AnalyticsAdminServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = AnalyticsAdminServiceClient.parse_common_location_path(path) assert expected == actual + + +def test_client_withDEFAULT_CLIENT_INFO(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.AnalyticsAdminServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = AnalyticsAdminServiceClient( + credentials=credentials.AnonymousCredentials(), client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.AnalyticsAdminServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = AnalyticsAdminServiceClient.get_transport_class() + transport = transport_class( + credentials=credentials.AnonymousCredentials(), client_info=client_info, + ) + prep.assert_called_once_with(client_info)