diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 108063d..b668c04 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,17 @@ +# Copyright 2022 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. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60 + digest: sha256:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6 + diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 30c3973..e446644 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,9 +3,10 @@ # # For syntax help see: # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax +# Note: This file is autogenerated. To make changes to the codeowner team, please update .repo-metadata.json. -# The @googleapis/yoshi-python is the default owner for changes in this repo -* @googleapis/yoshi-python +# @googleapis/yoshi-python is the default owner for changes in this repo +* @googleapis/yoshi-python -# The python-samples-reviewers team is the default owner for samples changes -/samples/ @googleapis/python-samples-owners \ No newline at end of file +# @googleapis/python-samples-reviewers is the default owner for samples changes +/samples/ @googleapis/python-samples-reviewers diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad0..466597e 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: python +handleGHRelease: true diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 0000000..d4ca941 --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 3e98ae7..37438d3 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -10,6 +10,5 @@ branchProtectionRules: - 'Kokoro' - 'cla/google' - 'Samples - Lint' - - 'Samples - Python 3.6' - 'Samples - Python 3.7' - 'Samples - Python 3.8' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..f7b8344 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,38 @@ +on: + pull_request: + branches: + - main +name: docs +jobs: + docs: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docs + run: | + nox -s docs + docfx: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docfx + run: | + nox -s docfx diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..1e8b05c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +on: + pull_request: + branches: + - main +name: lint +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run lint + run: | + nox -s lint + - name: Run lint_setup_py + run: | + nox -s lint_setup_py diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..e84424b --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,57 @@ +on: + pull_request: + branches: + - main +name: unittest +jobs: + unit: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.6', '3.7', '3.8', '3.9', '3.10'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit tests + env: + COVERAGE_FILE: .coverage-${{ matrix.python }} + run: | + nox -s unit-${{ matrix.python }} + - name: Upload coverage results + uses: actions/upload-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-${{ matrix.python }} + + cover: + runs-on: ubuntu-latest + needs: + - unit + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install coverage + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install coverage + - name: Download coverage results + uses: actions/download-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-results/ + - name: Report coverage results + run: | + coverage combine .coverage-results/.coverage* + coverage report --show-missing --fail-under=99 diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 3c81019..56ed227 100755 --- a/.kokoro/release.sh +++ b/.kokoro/release.sh @@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools export PYTHONUNBUFFERED=1 # Move into the package, build the distribution and upload. -TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") +TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-pypi-token-keystore-1") cd github/python-analytics-data python3 setup.py sdist bdist_wheel twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index c5b901a..5dbd253 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-analytics-data/.kokoro/release.sh" } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google-cloud-pypi-token-keystore-1" + } + } +} + # 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,google-cloud-pypi-token" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } diff --git a/.repo-metadata.json b/.repo-metadata.json index eb44809..aacff7a 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -4,7 +4,7 @@ "product_documentation": "https://developers.google.com/analytics/", "client_documentation": "https://googleapis.dev/python/analyticsdata/latest", "issue_tracker": "https://issuetracker.google.com/issues?q=componentid:187400%2B%20", - "release_level": "beta", + "release_level": "preview", "language": "python", "library_type": "GAPIC_AUTO", "repo": "googleapis/python-analytics-data", @@ -12,5 +12,6 @@ "api_id": "analyticsdata.googleapis.com", "requires_billing": true, "default_version": "v1beta", - "codeowner_team": "" + "codeowner_team": "", + "api_shortname": "analyticsdata" } diff --git a/CHANGELOG.md b/CHANGELOG.md index a75de78..2983d0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [0.11.0](https://github.com/googleapis/python-analytics-data/compare/v0.10.0...v0.11.0) (2022-02-24) + + +### Features + +* add api key support ([#182](https://github.com/googleapis/python-analytics-data/issues/182)) ([ad51ffd](https://github.com/googleapis/python-analytics-data/commit/ad51ffd1c461663d7ff055b69166004ea5a4d686)) + + +### Bug Fixes + +* **deps:** delete unused dependency libcst ([#191](https://github.com/googleapis/python-analytics-data/issues/191)) ([dbba912](https://github.com/googleapis/python-analytics-data/commit/dbba91295c9deacca67f8862da628e05cee6c4cc)) +* resolve DuplicateCredentialArgs error when using credentials_file ([97804fe](https://github.com/googleapis/python-analytics-data/commit/97804feb1031e3ff6ac3e6f6113b1d3123f1ec91)) + + +### Documentation + +* add autogenerated code snippets ([f34ee10](https://github.com/googleapis/python-analytics-data/commit/f34ee10dce4dae5f04aefedf9d8f3472491025d3)) + ## [0.10.0](https://www.github.com/googleapis/python-analytics-data/compare/v0.9.0...v0.10.0) (2021-11-01) diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py b/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py index d5ac261..55b5855 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.analytics.data_v1beta.types import analytics_data_api from google.analytics.data_v1beta.types import data @@ -103,6 +106,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return BetaAnalyticsDataClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> BetaAnalyticsDataTransport: """Returns the transport used by the client instance. @@ -181,6 +220,25 @@ async def run_report( Dimensions break down metrics across some common criteria, such as country or event name. + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_run_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunReportRequest( + ) + + # Make the request + response = client.run_report(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.RunReportRequest, dict]): The request object. The request to generate a report. @@ -234,6 +292,25 @@ async def run_pivot_report( in a pivot. Multiple pivots can be specified to further dissect your data. + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_run_pivot_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunPivotReportRequest( + ) + + # Make the request + response = client.run_pivot_report(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.RunPivotReportRequest, dict]): The request object. The request to generate a pivot @@ -284,6 +361,25 @@ async def batch_run_reports( r"""Returns multiple reports in a batch. All reports must be for the same GA4 Property. + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_batch_run_reports(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.BatchRunReportsRequest( + ) + + # Make the request + response = client.batch_run_reports(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.BatchRunReportsRequest, dict]): The request object. The batch request containing @@ -334,6 +430,25 @@ async def batch_run_pivot_reports( r"""Returns multiple pivot reports in a batch. All reports must be for the same GA4 Property. + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_batch_run_pivot_reports(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.BatchRunPivotReportsRequest( + ) + + # Make the request + response = client.batch_run_pivot_reports(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.BatchRunPivotReportsRequest, dict]): The request object. The batch request containing @@ -394,6 +509,26 @@ async def get_metadata( metadata are dimensions and metrics applicable to any property such as ``country`` and ``totalUsers``. + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_get_metadata(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.GetMetadataRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.GetMetadataRequest, dict]): The request object. Request for a property's dimension @@ -428,7 +563,7 @@ async def get_metadata( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -477,6 +612,25 @@ async def run_realtime_report( property. These reports show events and usage from the last 30 minutes. + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_run_realtime_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunRealtimeReportRequest( + ) + + # Make the request + response = client.run_realtime_report(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.RunRealtimeReportRequest, dict]): The request object. The request to generate a realtime @@ -536,6 +690,25 @@ async def check_compatibility( compatibility rules. This method checks compatibility for Core reports. + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_check_compatibility(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.CheckCompatibilityRequest( + ) + + # Make the request + response = client.check_compatibility(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.CheckCompatibilityRequest, dict]): The request object. The request for compatibility diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/client.py b/google/analytics/data_v1beta/services/beta_analytics_data/client.py index 6225f61..45216d4 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/client.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.analytics.data_v1beta.types import analytics_data_api from google.analytics.data_v1beta.types import data @@ -229,6 +231,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -279,50 +348,22 @@ def __init__( if client_options is None: 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = 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": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, BetaAnalyticsDataTransport): # transport is a BetaAnalyticsDataTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -334,6 +375,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -364,6 +414,26 @@ def run_report( Dimensions break down metrics across some common criteria, such as country or event name. + + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_run_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunReportRequest( + ) + + # Make the request + response = client.run_report(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.RunReportRequest, dict]): The request object. The request to generate a report. @@ -418,6 +488,26 @@ def run_pivot_report( in a pivot. Multiple pivots can be specified to further dissect your data. + + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_run_pivot_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunPivotReportRequest( + ) + + # Make the request + response = client.run_pivot_report(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.RunPivotReportRequest, dict]): The request object. The request to generate a pivot @@ -469,6 +559,26 @@ def batch_run_reports( r"""Returns multiple reports in a batch. All reports must be for the same GA4 Property. + + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_batch_run_reports(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.BatchRunReportsRequest( + ) + + # Make the request + response = client.batch_run_reports(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.BatchRunReportsRequest, dict]): The request object. The batch request containing @@ -520,6 +630,26 @@ def batch_run_pivot_reports( r"""Returns multiple pivot reports in a batch. All reports must be for the same GA4 Property. + + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_batch_run_pivot_reports(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.BatchRunPivotReportsRequest( + ) + + # Make the request + response = client.batch_run_pivot_reports(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.BatchRunPivotReportsRequest, dict]): The request object. The batch request containing @@ -581,6 +711,27 @@ def get_metadata( metadata are dimensions and metrics applicable to any property such as ``country`` and ``totalUsers``. + + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_get_metadata(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.GetMetadataRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.GetMetadataRequest, dict]): The request object. Request for a property's dimension @@ -615,7 +766,7 @@ def get_metadata( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -664,6 +815,26 @@ def run_realtime_report( property. These reports show events and usage from the last 30 minutes. + + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_run_realtime_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunRealtimeReportRequest( + ) + + # Make the request + response = client.run_realtime_report(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.RunRealtimeReportRequest, dict]): The request object. The request to generate a realtime @@ -724,6 +895,26 @@ def check_compatibility( compatibility rules. This method checks compatibility for Core reports. + + + .. code-block:: + + from google.analytics import data_v1beta + + def sample_check_compatibility(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.CheckCompatibilityRequest( + ) + + # Make the request + response = client.check_compatibility(request=request) + + # Handle the response + print(response) + Args: request (Union[google.analytics.data_v1beta.types.CheckCompatibilityRequest, dict]): The request object. The request for compatibility diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py index 656959f..63f81ed 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py @@ -18,10 +18,10 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -102,7 +102,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py index fe7c668..b1f1b6e 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -158,8 +158,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py index edcedcf..4163d3b 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py @@ -16,8 +16,8 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -203,8 +203,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/analytics/data_v1beta/types/data.py b/google/analytics/data_v1beta/types/data.py index 5d89f8c..19e8ddd 100644 --- a/google/analytics/data_v1beta/types/data.py +++ b/google/analytics/data_v1beta/types/data.py @@ -145,6 +145,7 @@ class MinuteRange(proto.Message): minutes of event data (``startMinutesAgo <= 29``), and 360 Analytics properties can request up to the last 60 minutes of event data (``startMinutesAgo <= 59``). + This field is a member of `oneof`_ ``_start_minutes_ago``. end_minutes_ago (int): The inclusive end minute for the query as a number of @@ -157,6 +158,7 @@ class MinuteRange(proto.Message): last 30 minutes of event data (``endMinutesAgo <= 29``), and 360 Analytics properties can request any minute in the last 60 minutes of event data (``endMinutesAgo <= 59``). + This field is a member of `oneof`_ ``_end_minutes_ago``. name (str): Assigns a name to this minute range. The dimension @@ -226,15 +228,18 @@ class DimensionExpression(proto.Message): lower_case (google.analytics.data_v1beta.types.DimensionExpression.CaseExpression): Used to convert a dimension value to lower case. + This field is a member of `oneof`_ ``one_expression``. upper_case (google.analytics.data_v1beta.types.DimensionExpression.CaseExpression): Used to convert a dimension value to upper case. + This field is a member of `oneof`_ ``one_expression``. concatenate (google.analytics.data_v1beta.types.DimensionExpression.ConcatenateExpression): Used to combine dimension values to a single dimension. For example, dimension "country, city": concatenate(country, ", ", city). + This field is a member of `oneof`_ ``one_expression``. """ @@ -333,17 +338,21 @@ class FilterExpression(proto.Message): Attributes: and_group (google.analytics.data_v1beta.types.FilterExpressionList): The FilterExpressions in and_group have an AND relationship. + This field is a member of `oneof`_ ``expr``. or_group (google.analytics.data_v1beta.types.FilterExpressionList): The FilterExpressions in or_group have an OR relationship. + This field is a member of `oneof`_ ``expr``. not_expression (google.analytics.data_v1beta.types.FilterExpression): The FilterExpression is NOT of not_expression. + This field is a member of `oneof`_ ``expr``. filter (google.analytics.data_v1beta.types.Filter): A primitive filter. All fields in filter in same FilterExpression needs to be either all dimensions or metrics. + This field is a member of `oneof`_ ``expr``. """ @@ -388,15 +397,19 @@ class Filter(proto.Message): name defined in dimensions or metrics. string_filter (google.analytics.data_v1beta.types.Filter.StringFilter): Strings related filter. + This field is a member of `oneof`_ ``one_filter``. in_list_filter (google.analytics.data_v1beta.types.Filter.InListFilter): A filter for in list values. + This field is a member of `oneof`_ ``one_filter``. numeric_filter (google.analytics.data_v1beta.types.Filter.NumericFilter): A filter for numeric or date values. + This field is a member of `oneof`_ ``one_filter``. between_filter (google.analytics.data_v1beta.types.Filter.BetweenFilter): A filter for two values. + This field is a member of `oneof`_ ``one_filter``. """ @@ -508,13 +521,16 @@ class OrderBy(proto.Message): Attributes: metric (google.analytics.data_v1beta.types.OrderBy.MetricOrderBy): Sorts results by a metric's values. + This field is a member of `oneof`_ ``one_order_by``. dimension (google.analytics.data_v1beta.types.OrderBy.DimensionOrderBy): Sorts results by a dimension's values. + This field is a member of `oneof`_ ``one_order_by``. pivot (google.analytics.data_v1beta.types.OrderBy.PivotOrderBy): Sorts results by a metric's values within a pivot column group. + This field is a member of `oneof`_ ``one_order_by``. desc (bool): If true, sorts by descending order. @@ -836,6 +852,7 @@ class ResponseMetaData(proto.Message): creating this report. To learn more, see `Access and data-restriction management `__. + This field is a member of `oneof`_ ``_schema_restriction_response``. currency_code (str): The currency code used in this report. Intended to be used @@ -850,6 +867,7 @@ class ResponseMetaData(proto.Message): (https://en.wikipedia.org/wiki/ISO_4217); for example "USD", "EUR", "JPY". To learn more, see https://support.google.com/analytics/answer/9796179. + This field is a member of `oneof`_ ``_currency_code``. time_zone (str): The property's current timezone. Intended to be used to @@ -857,10 +875,12 @@ class ResponseMetaData(proto.Message): ``minute``. Formatted as strings from the IANA Time Zone database (https://www.iana.org/time-zones); for example "America/New_York" or "Asia/Tokyo". + This field is a member of `oneof`_ ``_time_zone``. empty_reason (str): If empty reason is specified, the report is empty for this reason. + This field is a member of `oneof`_ ``_empty_reason``. """ @@ -884,6 +904,7 @@ class ActiveMetricRestriction(proto.Message): Attributes: metric_name (str): The name of the restricted metric. + This field is a member of `oneof`_ ``_metric_name``. restricted_metric_types (Sequence[google.analytics.data_v1beta.types.RestrictedMetricType]): The reason for this metric's restriction. @@ -1036,6 +1057,7 @@ class DimensionValue(proto.Message): value (str): Value as a string if the dimension type is a string. + This field is a member of `oneof`_ ``one_value``. """ @@ -1050,6 +1072,7 @@ class MetricValue(proto.Message): Attributes: value (str): Measurement value. See MetricHeader for type. + This field is a member of `oneof`_ ``one_value``. """ @@ -1069,9 +1092,11 @@ class NumericValue(proto.Message): Attributes: int64_value (int): Integer value + This field is a member of `oneof`_ ``one_value``. double_value (float): Double value + This field is a member of `oneof`_ ``one_value``. """ @@ -1249,11 +1274,13 @@ class DimensionCompatibility(proto.Message): for this compatibility information. The dimension metadata also contains other helpful information like the UI name and description. + This field is a member of `oneof`_ ``_dimension_metadata``. compatibility (google.analytics.data_v1beta.types.Compatibility): The compatibility of this dimension. If the compatibility is COMPATIBLE, this dimension can be successfully added to the report. + This field is a member of `oneof`_ ``_compatibility``. """ @@ -1274,11 +1301,13 @@ class MetricCompatibility(proto.Message): this compatibility information. The metric metadata also contains other helpful information like the UI name and description. + This field is a member of `oneof`_ ``_metric_metadata``. compatibility (google.analytics.data_v1beta.types.Compatibility): The compatibility of this metric. If the compatibility is COMPATIBLE, this metric can be successfully added to the report. + This field is a member of `oneof`_ ``_compatibility``. """ diff --git a/owlbot.py b/owlbot.py index 98cb83e..cef558f 100644 --- a/owlbot.py +++ b/owlbot.py @@ -61,11 +61,7 @@ """``^[a-zA-Z0-9_]$``""", ) -# Block pushing non-cloud libraries to Cloud RAD -s.replace( - ".kokoro/docs/common.cfg", - r'value: "docs-staging-v2"', - r'value: "docs-staging-v2-staging"' -) +# Work around bug in templates https://github.com/googleapis/synthtool/pull/1335 +s.replace(".github/workflows/unittest.yml", "--fail-under=100", "--fail-under=99") s.shell.run(["nox", "-s", "blacken"], hide_output=False) diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_pivot_reports_async.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_pivot_reports_async.py new file mode 100644 index 0000000..364ec7f --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_pivot_reports_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchRunPivotReports +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunPivotReports_async] +from google.analytics import data_v1beta + + +async def sample_batch_run_pivot_reports(): + # Create a client + client = data_v1beta.BetaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1beta.BatchRunPivotReportsRequest( + ) + + # Make the request + response = await client.batch_run_pivot_reports(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunPivotReports_async] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_pivot_reports_sync.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_pivot_reports_sync.py new file mode 100644 index 0000000..33ffcb3 --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_pivot_reports_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchRunPivotReports +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunPivotReports_sync] +from google.analytics import data_v1beta + + +def sample_batch_run_pivot_reports(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.BatchRunPivotReportsRequest( + ) + + # Make the request + response = client.batch_run_pivot_reports(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunPivotReports_sync] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_reports_async.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_reports_async.py new file mode 100644 index 0000000..d7391ed --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_reports_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchRunReports +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunReports_async] +from google.analytics import data_v1beta + + +async def sample_batch_run_reports(): + # Create a client + client = data_v1beta.BetaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1beta.BatchRunReportsRequest( + ) + + # Make the request + response = await client.batch_run_reports(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunReports_async] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_reports_sync.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_reports_sync.py new file mode 100644 index 0000000..9f70791 --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_reports_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchRunReports +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunReports_sync] +from google.analytics import data_v1beta + + +def sample_batch_run_reports(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.BatchRunReportsRequest( + ) + + # Make the request + response = client.batch_run_reports(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunReports_sync] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_check_compatibility_async.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_check_compatibility_async.py new file mode 100644 index 0000000..c709d9d --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_check_compatibility_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckCompatibility +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_CheckCompatibility_async] +from google.analytics import data_v1beta + + +async def sample_check_compatibility(): + # Create a client + client = data_v1beta.BetaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1beta.CheckCompatibilityRequest( + ) + + # Make the request + response = await client.check_compatibility(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_CheckCompatibility_async] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_check_compatibility_sync.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_check_compatibility_sync.py new file mode 100644 index 0000000..6e07165 --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_check_compatibility_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckCompatibility +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_CheckCompatibility_sync] +from google.analytics import data_v1beta + + +def sample_check_compatibility(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.CheckCompatibilityRequest( + ) + + # Make the request + response = client.check_compatibility(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_CheckCompatibility_sync] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_get_metadata_async.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_get_metadata_async.py new file mode 100644 index 0000000..061bf19 --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_get_metadata_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadata +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_GetMetadata_async] +from google.analytics import data_v1beta + + +async def sample_get_metadata(): + # Create a client + client = data_v1beta.BetaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1beta.GetMetadataRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_GetMetadata_async] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_get_metadata_sync.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_get_metadata_sync.py new file mode 100644 index 0000000..824990e --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_get_metadata_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadata +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_GetMetadata_sync] +from google.analytics import data_v1beta + + +def sample_get_metadata(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.GetMetadataRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_GetMetadata_sync] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_pivot_report_async.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_pivot_report_async.py new file mode 100644 index 0000000..3029d66 --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_pivot_report_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RunPivotReport +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunPivotReport_async] +from google.analytics import data_v1beta + + +async def sample_run_pivot_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1beta.RunPivotReportRequest( + ) + + # Make the request + response = await client.run_pivot_report(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunPivotReport_async] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_pivot_report_sync.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_pivot_report_sync.py new file mode 100644 index 0000000..697aedf --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_pivot_report_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RunPivotReport +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunPivotReport_sync] +from google.analytics import data_v1beta + + +def sample_run_pivot_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunPivotReportRequest( + ) + + # Make the request + response = client.run_pivot_report(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunPivotReport_sync] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_realtime_report_async.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_realtime_report_async.py new file mode 100644 index 0000000..d55a368 --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_realtime_report_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RunRealtimeReport +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunRealtimeReport_async] +from google.analytics import data_v1beta + + +async def sample_run_realtime_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1beta.RunRealtimeReportRequest( + ) + + # Make the request + response = await client.run_realtime_report(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunRealtimeReport_async] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_realtime_report_sync.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_realtime_report_sync.py new file mode 100644 index 0000000..ac27be4 --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_realtime_report_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RunRealtimeReport +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunRealtimeReport_sync] +from google.analytics import data_v1beta + + +def sample_run_realtime_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunRealtimeReportRequest( + ) + + # Make the request + response = client.run_realtime_report(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunRealtimeReport_sync] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_report_async.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_report_async.py new file mode 100644 index 0000000..e15981c --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_report_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RunReport +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunReport_async] +from google.analytics import data_v1beta + + +async def sample_run_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataAsyncClient() + + # Initialize request argument(s) + request = data_v1beta.RunReportRequest( + ) + + # Make the request + response = await client.run_report(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunReport_async] diff --git a/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_report_sync.py b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_report_sync.py new file mode 100644 index 0000000..d0b888a --- /dev/null +++ b/samples/generated_samples/analyticsdata_generated_data_v1beta_beta_analytics_data_run_report_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RunReport +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-analytics-data + + +# [START analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunReport_sync] +from google.analytics import data_v1beta + + +def sample_run_report(): + # Create a client + client = data_v1beta.BetaAnalyticsDataClient() + + # Initialize request argument(s) + request = data_v1beta.RunReportRequest( + ) + + # Make the request + response = client.run_report(request=request) + + # Handle the response + print(response) + +# [END analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunReport_sync] diff --git a/samples/generated_samples/snippet_metadata_data_v1beta.json b/samples/generated_samples/snippet_metadata_data_v1beta.json new file mode 100644 index 0000000..da72466 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_data_v1beta.json @@ -0,0 +1,627 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "BatchRunPivotReports" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_pivot_reports_async.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunPivotReports_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "BatchRunPivotReports" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_pivot_reports_sync.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunPivotReports_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "BatchRunReports" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_reports_async.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunReports_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "BatchRunReports" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_batch_run_reports_sync.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_BatchRunReports_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "CheckCompatibility" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_check_compatibility_async.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_CheckCompatibility_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "CheckCompatibility" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_check_compatibility_sync.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_CheckCompatibility_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "GetMetadata" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_get_metadata_async.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_GetMetadata_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "GetMetadata" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_get_metadata_sync.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_GetMetadata_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "RunPivotReport" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_run_pivot_report_async.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunPivotReport_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "RunPivotReport" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_run_pivot_report_sync.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunPivotReport_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "RunRealtimeReport" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_run_realtime_report_async.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunRealtimeReport_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "RunRealtimeReport" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_run_realtime_report_sync.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunRealtimeReport_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "RunReport" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_run_report_async.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunReport_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "BetaAnalyticsData" + }, + "shortName": "RunReport" + } + }, + "file": "analyticsdata_generated_data_v1beta_beta_analytics_data_run_report_sync.py", + "regionTag": "analyticsdata_generated_data_v1beta_BetaAnalyticsData_RunReport_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 93a9122..20cdfc6 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -14,6 +14,7 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys @@ -184,37 +185,45 @@ def blacken(session: nox.sessions.Session) -> None: def _session_tests( session: nox.sessions.Session, post_install: Callable = None ) -> None: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + if len(test_list) == 0: + print("No tests found, skipping directory.") + else: + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt index 9270945..c2845bf 100644 --- a/samples/snippets/requirements-test.txt +++ b/samples/snippets/requirements-test.txt @@ -1 +1 @@ -pytest==6.2.5 +pytest==7.0.1 diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index eac014f..91f58db 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,2 +1,2 @@ -google-analytics-data==0.9.0 -google-auth-oauthlib==0.4.6 \ No newline at end of file +google-analytics-data==0.10.0 +google-auth-oauthlib==0.5.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 08a0925..6dba6c2 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import os import setuptools # type: ignore -version = "0.10.0" +version = "0.11.0" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -49,7 +49,6 @@ # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 "google-api-core[grpc] >= 1.28.0, <3.0.0dev", - "libcst >= 0.2.5", "proto-plus >= 1.4.0", "packaging >= 14.3", ), diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 61f0ec4..5c1659b 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -6,6 +6,5 @@ # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 google-api-core==1.28.0 -libcst==0.2.5 proto-plus==1.4.0 packaging==14.3 diff --git a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py index e52e083..1ab02ae 100644 --- a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py +++ b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py @@ -251,20 +251,20 @@ def test_beta_analytics_data_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # 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() + client = client_class(transport=transport_name) # 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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -333,7 +333,7 @@ def test_beta_analytics_data_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -410,6 +410,87 @@ def test_beta_analytics_data_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [BetaAnalyticsDataClient, BetaAnalyticsDataAsyncClient] +) +@mock.patch.object( + BetaAnalyticsDataClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(BetaAnalyticsDataClient), +) +@mock.patch.object( + BetaAnalyticsDataAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(BetaAnalyticsDataAsyncClient), +) +def test_beta_analytics_data_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -428,7 +509,7 @@ def test_beta_analytics_data_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -442,24 +523,31 @@ def test_beta_analytics_data_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (BetaAnalyticsDataClient, transports.BetaAnalyticsDataGrpcTransport, "grpc"), + ( + BetaAnalyticsDataClient, + transports.BetaAnalyticsDataGrpcTransport, + "grpc", + grpc_helpers, + ), ( BetaAnalyticsDataAsyncClient, transports.BetaAnalyticsDataGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_beta_analytics_data_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -492,9 +580,77 @@ def test_beta_analytics_data_client_client_options_from_dict(): ) -def test_run_report( - transport: str = "grpc", request_type=analytics_data_api.RunReportRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + BetaAnalyticsDataClient, + transports.BetaAnalyticsDataGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + BetaAnalyticsDataAsyncClient, + transports.BetaAnalyticsDataGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_beta_analytics_data_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "analyticsdata.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/analytics", + "https://www.googleapis.com/auth/analytics.readonly", + ), + scopes=None, + default_host="analyticsdata.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [analytics_data_api.RunReportRequest, dict,]) +def test_run_report(request_type, transport: str = "grpc"): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -522,10 +678,6 @@ def test_run_report( assert response.kind == "kind_value" -def test_run_report_from_dict(): - test_run_report(request_type=dict) - - def test_run_report_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -630,9 +782,10 @@ async def test_run_report_field_headers_async(): assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] -def test_run_pivot_report( - transport: str = "grpc", request_type=analytics_data_api.RunPivotReportRequest -): +@pytest.mark.parametrize( + "request_type", [analytics_data_api.RunPivotReportRequest, dict,] +) +def test_run_pivot_report(request_type, transport: str = "grpc"): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -659,10 +812,6 @@ def test_run_pivot_report( assert response.kind == "kind_value" -def test_run_pivot_report_from_dict(): - test_run_pivot_report(request_type=dict) - - def test_run_pivot_report_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -767,9 +916,10 @@ async def test_run_pivot_report_field_headers_async(): assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] -def test_batch_run_reports( - transport: str = "grpc", request_type=analytics_data_api.BatchRunReportsRequest -): +@pytest.mark.parametrize( + "request_type", [analytics_data_api.BatchRunReportsRequest, dict,] +) +def test_batch_run_reports(request_type, transport: str = "grpc"): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -798,10 +948,6 @@ def test_batch_run_reports( assert response.kind == "kind_value" -def test_batch_run_reports_from_dict(): - test_batch_run_reports(request_type=dict) - - def test_batch_run_reports_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -914,9 +1060,10 @@ async def test_batch_run_reports_field_headers_async(): assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] -def test_batch_run_pivot_reports( - transport: str = "grpc", request_type=analytics_data_api.BatchRunPivotReportsRequest -): +@pytest.mark.parametrize( + "request_type", [analytics_data_api.BatchRunPivotReportsRequest, dict,] +) +def test_batch_run_pivot_reports(request_type, transport: str = "grpc"): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -945,10 +1092,6 @@ def test_batch_run_pivot_reports( assert response.kind == "kind_value" -def test_batch_run_pivot_reports_from_dict(): - test_batch_run_pivot_reports(request_type=dict) - - def test_batch_run_pivot_reports_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1061,9 +1204,8 @@ async def test_batch_run_pivot_reports_field_headers_async(): assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] -def test_get_metadata( - transport: str = "grpc", request_type=analytics_data_api.GetMetadataRequest -): +@pytest.mark.parametrize("request_type", [analytics_data_api.GetMetadataRequest, dict,]) +def test_get_metadata(request_type, transport: str = "grpc"): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1088,10 +1230,6 @@ def test_get_metadata( assert response.name == "name_value" -def test_get_metadata_from_dict(): - test_get_metadata(request_type=dict) - - def test_get_metadata_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1210,7 +1348,9 @@ def test_get_metadata_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_metadata_flattened_error(): @@ -1246,7 +1386,9 @@ async def test_get_metadata_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1263,9 +1405,10 @@ async def test_get_metadata_flattened_error_async(): ) -def test_run_realtime_report( - transport: str = "grpc", request_type=analytics_data_api.RunRealtimeReportRequest -): +@pytest.mark.parametrize( + "request_type", [analytics_data_api.RunRealtimeReportRequest, dict,] +) +def test_run_realtime_report(request_type, transport: str = "grpc"): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1295,10 +1438,6 @@ def test_run_realtime_report( assert response.kind == "kind_value" -def test_run_realtime_report_from_dict(): - test_run_realtime_report(request_type=dict) - - def test_run_realtime_report_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1414,9 +1553,10 @@ async def test_run_realtime_report_field_headers_async(): assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] -def test_check_compatibility( - transport: str = "grpc", request_type=analytics_data_api.CheckCompatibilityRequest -): +@pytest.mark.parametrize( + "request_type", [analytics_data_api.CheckCompatibilityRequest, dict,] +) +def test_check_compatibility(request_type, transport: str = "grpc"): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1442,10 +1582,6 @@ def test_check_compatibility( assert isinstance(response, analytics_data_api.CheckCompatibilityResponse) -def test_check_compatibility_from_dict(): - test_check_compatibility(request_type=dict) - - def test_check_compatibility_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1577,6 +1713,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.BetaAnalyticsDataGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = BetaAnalyticsDataClient(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = BetaAnalyticsDataClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.BetaAnalyticsDataGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -2085,7 +2238,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( @@ -2150,3 +2303,36 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (BetaAnalyticsDataClient, transports.BetaAnalyticsDataGrpcTransport), + ( + BetaAnalyticsDataAsyncClient, + transports.BetaAnalyticsDataGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + 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=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + )