From cb785b5b6885a7063f49de76ab2ff0145a83e4fe Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 14 May 2021 21:48:01 -0400 Subject: [PATCH] chore: migrate to owl bot (#13) This PR migrates from autosynth to [owl bot](https://github.com/googleapis/repo-automation-bots/tree/master/packages/owl-bot). owl bot will save time for maintainers as it will automatically open PRs when there are updates in [googleapis-gen](https://github.com/googleapis/googleapis-gen/tree/master/google) without requiring maintainers to run `synthtool` to build the client from protos. Additionally, similar to autosynth, PRs will be automatically opened when there are template updates. fix: add async client chore: add autogenerated snippets chore: remove auth, policy, and options from the reserved names list feat: support self-signed JWT flow for service accounts chore: enable GAPIC metadata generation --- .github/.OwlBot.lock.yaml | 4 + .github/.OwlBot.yaml | 26 + .github/header-checker-lint.yml | 2 +- .kokoro/release.sh | 4 +- .kokoro/release/common.cfg | 14 +- .pre-commit-config.yaml | 2 +- CONTRIBUTING.rst | 16 +- docs/_static/custom.css | 13 +- docs/servicemanagement_v1/service_manager.rst | 1 - google/cloud/servicemanagement/__init__.py | 20 +- google/cloud/servicemanagement_v1/__init__.py | 7 +- .../servicemanagement_v1/gapic_metadata.json | 173 ++++ .../servicemanagement_v1/services/__init__.py | 1 - .../services/service_manager/__init__.py | 2 - .../services/service_manager/async_client.py | 174 ++-- .../services/service_manager/client.py | 223 ++-- .../services/service_manager/pagers.py | 14 +- .../service_manager/transports/__init__.py | 2 - .../service_manager/transports/base.py | 172 ++-- .../service_manager/transports/grpc.py | 67 +- .../transports/grpc_asyncio.py | 69 +- .../servicemanagement_v1/types/__init__.py | 2 - .../servicemanagement_v1/types/resources.py | 69 +- .../types/servicemanager.py | 182 ++-- noxfile.py | 36 +- synth.py => owlbot.py | 21 +- renovate.json | 5 +- .../fixup_servicemanagement_v1_keywords.py | 35 +- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + .../gapic/servicemanagement_v1/__init__.py | 1 - .../test_service_manager.py | 959 ++++++++++-------- 33 files changed, 1303 insertions(+), 1058 deletions(-) create mode 100644 .github/.OwlBot.lock.yaml create mode 100644 .github/.OwlBot.yaml create mode 100644 google/cloud/servicemanagement_v1/gapic_metadata.json rename synth.py => owlbot.py (67%) create mode 100644 tests/__init__.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/gapic/__init__.py diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml new file mode 100644 index 0000000..d49860b --- /dev/null +++ b/.github/.OwlBot.lock.yaml @@ -0,0 +1,4 @@ +docker: + digest: sha256:457583330eec64daa02aeb7a72a04d33e7be2428f646671ce4045dcbc0191b1e + image: gcr.io/repo-automation-bots/owlbot-python:latest + diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml new file mode 100644 index 0000000..07cf1b4 --- /dev/null +++ b/.github/.OwlBot.yaml @@ -0,0 +1,26 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +docker: + image: gcr.io/repo-automation-bots/owlbot-python:latest + +deep-remove-regex: + - /owl-bot-staging + +deep-copy-regex: + - source: /google/api/servicemanagement/(v.*)/.*-py/(.*) + dest: /owl-bot-staging/$1/$2 + +begin-after-commit-hash: 6acf4a0a797f1082027985c55c4b14b60f673dd7 + diff --git a/.github/header-checker-lint.yml b/.github/header-checker-lint.yml index fc281c0..6fe78aa 100644 --- a/.github/header-checker-lint.yml +++ b/.github/header-checker-lint.yml @@ -1,6 +1,6 @@ {"allowedCopyrightHolders": ["Google LLC"], "allowedLicenses": ["Apache-2.0", "MIT", "BSD-3"], - "ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt"], + "ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt", "**/__init__.py", "samples/**/constraints.txt", "samples/**/constraints-test.txt"], "sourceFileExtensions": [ "ts", "js", diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 0470d4a..a97a73e 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_KEYSTORE_DIR}/73713_google_cloud_pypi_password") +TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") cd github/python-service-management python3 setup.py sdist bdist_wheel -twine upload --username gcloudpypi --password "${TWINE_PASSWORD}" dist/* +twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index 8dc31aa..836cd86 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,18 +23,8 @@ env_vars: { value: "github/python-service-management/.kokoro/release.sh" } -# Fetch PyPI password -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "google_cloud_pypi_password" - } - } -} - # Tokens needed to report release status back to GitHub env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" -} \ No newline at end of file + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token" +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 55cc59e..1bbd787 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,6 @@ repos: hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + rev: 3.9.1 hooks: - id: flake8 diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 70cf52f..98aedf8 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -160,21 +160,7 @@ Running System Tests auth settings and change some configuration in your project to run all the tests. -- System tests will be run against an actual project and - so you'll need to provide some environment variables to facilitate - authentication to your project: - - - ``GOOGLE_APPLICATION_CREDENTIALS``: The path to a JSON key file; - Such a file can be downloaded directly from the developer's console by clicking - "Generate new JSON key". See private key - `docs `__ - for more details. - -- Once you have downloaded your json keys, set the environment variable - ``GOOGLE_APPLICATION_CREDENTIALS`` to the absolute path of the json file:: - - $ export GOOGLE_APPLICATION_CREDENTIALS="/Users//path/to/app_credentials.json" - +- System tests will be run against an actual project. You should use local credentials from gcloud when possible. See `Best practices for application authentication `__. Some tests require a service account. For those tests see `Authenticating as a service account `__. ************* Test Coverage diff --git a/docs/_static/custom.css b/docs/_static/custom.css index bcd37bb..b0a2954 100644 --- a/docs/_static/custom.css +++ b/docs/_static/custom.css @@ -1,9 +1,20 @@ div#python2-eol { border-color: red; border-width: medium; -} +} /* Ensure minimum width for 'Parameters' / 'Returns' column */ dl.field-list > dt { min-width: 100px } + +/* Insert space between methods for readability */ +dl.method { + padding-top: 10px; + padding-bottom: 10px +} + +/* Insert empty space between classes */ +dl.class { + padding-bottom: 50px +} diff --git a/docs/servicemanagement_v1/service_manager.rst b/docs/servicemanagement_v1/service_manager.rst index c83380b..54acafe 100644 --- a/docs/servicemanagement_v1/service_manager.rst +++ b/docs/servicemanagement_v1/service_manager.rst @@ -5,7 +5,6 @@ ServiceManager :members: :inherited-members: - .. automodule:: google.cloud.servicemanagement_v1.services.service_manager.pagers :members: :inherited-members: diff --git a/google/cloud/servicemanagement/__init__.py b/google/cloud/servicemanagement/__init__.py index 47f1e1f..e980da0 100644 --- a/google/cloud/servicemanagement/__init__.py +++ b/google/cloud/servicemanagement/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +14,13 @@ # limitations under the License. # -from google.cloud.servicemanagement_v1.services.service_manager.async_client import ( - ServiceManagerAsyncClient, -) from google.cloud.servicemanagement_v1.services.service_manager.client import ( ServiceManagerClient, ) +from google.cloud.servicemanagement_v1.services.service_manager.async_client import ( + ServiceManagerAsyncClient, +) + from google.cloud.servicemanagement_v1.types.resources import ChangeReport from google.cloud.servicemanagement_v1.types.resources import ConfigFile from google.cloud.servicemanagement_v1.types.resources import ConfigRef @@ -84,15 +84,20 @@ ) __all__ = ( + "ServiceManagerClient", + "ServiceManagerAsyncClient", "ChangeReport", "ConfigFile", "ConfigRef", "ConfigSource", + "Diagnostic", + "ManagedService", + "OperationMetadata", + "Rollout", "CreateServiceConfigRequest", "CreateServiceRequest", "CreateServiceRolloutRequest", "DeleteServiceRequest", - "Diagnostic", "DisableServiceRequest", "DisableServiceResponse", "EnableServiceRequest", @@ -108,11 +113,6 @@ "ListServiceRolloutsResponse", "ListServicesRequest", "ListServicesResponse", - "ManagedService", - "OperationMetadata", - "Rollout", - "ServiceManagerAsyncClient", - "ServiceManagerClient", "SubmitConfigSourceRequest", "SubmitConfigSourceResponse", "UndeleteServiceRequest", diff --git a/google/cloud/servicemanagement_v1/__init__.py b/google/cloud/servicemanagement_v1/__init__.py index 132b70f..c980a83 100644 --- a/google/cloud/servicemanagement_v1/__init__.py +++ b/google/cloud/servicemanagement_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +15,8 @@ # from .services.service_manager import ServiceManagerClient +from .services.service_manager import ServiceManagerAsyncClient + from .types.resources import ChangeReport from .types.resources import ConfigFile from .types.resources import ConfigRef @@ -48,8 +49,8 @@ from .types.servicemanager import UndeleteServiceRequest from .types.servicemanager import UndeleteServiceResponse - __all__ = ( + "ServiceManagerAsyncClient", "ChangeReport", "ConfigFile", "ConfigRef", @@ -77,9 +78,9 @@ "ManagedService", "OperationMetadata", "Rollout", + "ServiceManagerClient", "SubmitConfigSourceRequest", "SubmitConfigSourceResponse", "UndeleteServiceRequest", "UndeleteServiceResponse", - "ServiceManagerClient", ) diff --git a/google/cloud/servicemanagement_v1/gapic_metadata.json b/google/cloud/servicemanagement_v1/gapic_metadata.json new file mode 100644 index 0000000..56131c0 --- /dev/null +++ b/google/cloud/servicemanagement_v1/gapic_metadata.json @@ -0,0 +1,173 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.servicemanagement_v1", + "protoPackage": "google.api.servicemanagement.v1", + "schema": "1.0", + "services": { + "ServiceManager": { + "clients": { + "grpc": { + "libraryClient": "ServiceManagerClient", + "rpcs": { + "CreateService": { + "methods": [ + "create_service" + ] + }, + "CreateServiceConfig": { + "methods": [ + "create_service_config" + ] + }, + "CreateServiceRollout": { + "methods": [ + "create_service_rollout" + ] + }, + "DeleteService": { + "methods": [ + "delete_service" + ] + }, + "DisableService": { + "methods": [ + "disable_service" + ] + }, + "EnableService": { + "methods": [ + "enable_service" + ] + }, + "GenerateConfigReport": { + "methods": [ + "generate_config_report" + ] + }, + "GetService": { + "methods": [ + "get_service" + ] + }, + "GetServiceConfig": { + "methods": [ + "get_service_config" + ] + }, + "GetServiceRollout": { + "methods": [ + "get_service_rollout" + ] + }, + "ListServiceConfigs": { + "methods": [ + "list_service_configs" + ] + }, + "ListServiceRollouts": { + "methods": [ + "list_service_rollouts" + ] + }, + "ListServices": { + "methods": [ + "list_services" + ] + }, + "SubmitConfigSource": { + "methods": [ + "submit_config_source" + ] + }, + "UndeleteService": { + "methods": [ + "undelete_service" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ServiceManagerAsyncClient", + "rpcs": { + "CreateService": { + "methods": [ + "create_service" + ] + }, + "CreateServiceConfig": { + "methods": [ + "create_service_config" + ] + }, + "CreateServiceRollout": { + "methods": [ + "create_service_rollout" + ] + }, + "DeleteService": { + "methods": [ + "delete_service" + ] + }, + "DisableService": { + "methods": [ + "disable_service" + ] + }, + "EnableService": { + "methods": [ + "enable_service" + ] + }, + "GenerateConfigReport": { + "methods": [ + "generate_config_report" + ] + }, + "GetService": { + "methods": [ + "get_service" + ] + }, + "GetServiceConfig": { + "methods": [ + "get_service_config" + ] + }, + "GetServiceRollout": { + "methods": [ + "get_service_rollout" + ] + }, + "ListServiceConfigs": { + "methods": [ + "list_service_configs" + ] + }, + "ListServiceRollouts": { + "methods": [ + "list_service_rollouts" + ] + }, + "ListServices": { + "methods": [ + "list_services" + ] + }, + "SubmitConfigSource": { + "methods": [ + "submit_config_source" + ] + }, + "UndeleteService": { + "methods": [ + "undelete_service" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/servicemanagement_v1/services/__init__.py b/google/cloud/servicemanagement_v1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/servicemanagement_v1/services/__init__.py +++ b/google/cloud/servicemanagement_v1/services/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/google/cloud/servicemanagement_v1/services/service_manager/__init__.py b/google/cloud/servicemanagement_v1/services/service_manager/__init__.py index 929bddd..a1fbec7 100644 --- a/google/cloud/servicemanagement_v1/services/service_manager/__init__.py +++ b/google/cloud/servicemanagement_v1/services/service_manager/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .client import ServiceManagerClient from .async_client import ServiceManagerAsyncClient diff --git a/google/cloud/servicemanagement_v1/services/service_manager/async_client.py b/google/cloud/servicemanagement_v1/services/service_manager/async_client.py index fa001c2..083495a 100644 --- a/google/cloud/servicemanagement_v1/services/service_manager/async_client.py +++ b/google/cloud/servicemanagement_v1/services/service_manager/async_client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict import functools import re @@ -22,49 +20,50 @@ import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # 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.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -from google.api import auth_pb2 as auth # type: ignore -from google.api import backend_pb2 as backend # type: ignore -from google.api import billing_pb2 as billing # type: ignore -from google.api import context_pb2 as context # type: ignore -from google.api import control_pb2 as control # type: ignore -from google.api import documentation_pb2 as documentation # type: ignore -from google.api import endpoint_pb2 as endpoint # type: ignore -from google.api import http_pb2 as http # type: ignore -from google.api import log_pb2 as log # type: ignore -from google.api import logging_pb2 as logging # type: ignore -from google.api import metric_pb2 as metric # type: ignore -from google.api import monitored_resource_pb2 as monitored_resource # type: ignore -from google.api import monitoring_pb2 as monitoring # type: ignore -from google.api import quota_pb2 as quota # type: ignore -from google.api import service_pb2 as service # type: ignore -from google.api import source_info_pb2 as source_info # type: ignore -from google.api import system_parameter_pb2 as system_parameter # type: ignore -from google.api import usage_pb2 as usage # type: ignore +from google.api import auth_pb2 # type: ignore +from google.api import backend_pb2 # type: ignore +from google.api import billing_pb2 # type: ignore +from google.api import context_pb2 # type: ignore +from google.api import control_pb2 # type: ignore +from google.api import documentation_pb2 # type: ignore +from google.api import endpoint_pb2 # type: ignore +from google.api import http_pb2 # type: ignore +from google.api import log_pb2 # type: ignore +from google.api import logging_pb2 # type: ignore +from google.api import metric_pb2 # type: ignore +from google.api import monitored_resource_pb2 # type: ignore +from google.api import monitoring_pb2 # type: ignore +from google.api import quota_pb2 # type: ignore +from google.api import service_pb2 # type: ignore +from google.api import source_info_pb2 # type: ignore +from google.api import system_parameter_pb2 # type: ignore +from google.api import usage_pb2 # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.servicemanagement_v1.services.service_manager import pagers from google.cloud.servicemanagement_v1.types import resources from google.cloud.servicemanagement_v1.types import servicemanager -from google.protobuf import any_pb2 as gp_any # type: ignore -from google.protobuf import api_pb2 as api # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.protobuf import type_pb2 as gp_type # type: ignore -from google.protobuf import wrappers_pb2 as wrappers # type: ignore - +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import api_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import type_pb2 # type: ignore +from google.protobuf import wrappers_pb2 # type: ignore from .transports.base import ServiceManagerTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import ServiceManagerGrpcAsyncIOTransport from .client import ServiceManagerClient class ServiceManagerAsyncClient: - """`Google Service Management API `__""" + """`Google Service Management + API `__ + """ _client: ServiceManagerClient @@ -77,24 +76,20 @@ class ServiceManagerAsyncClient: parse_common_billing_account_path = staticmethod( ServiceManagerClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(ServiceManagerClient.common_folder_path) parse_common_folder_path = staticmethod( ServiceManagerClient.parse_common_folder_path ) - common_organization_path = staticmethod( ServiceManagerClient.common_organization_path ) parse_common_organization_path = staticmethod( ServiceManagerClient.parse_common_organization_path ) - common_project_path = staticmethod(ServiceManagerClient.common_project_path) parse_common_project_path = staticmethod( ServiceManagerClient.parse_common_project_path ) - common_location_path = staticmethod(ServiceManagerClient.common_location_path) parse_common_location_path = staticmethod( ServiceManagerClient.parse_common_location_path @@ -102,7 +97,8 @@ class ServiceManagerAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -117,7 +113,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -134,7 +130,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ServiceManagerTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: ServiceManagerTransport: The transport used by the client instance. @@ -148,12 +144,12 @@ def transport(self) -> ServiceManagerTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, ServiceManagerTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the service manager client. + """Instantiates the service manager client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -185,7 +181,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = ServiceManagerClient( credentials=credentials, transport=transport, @@ -235,7 +230,6 @@ async def list_services( This corresponds to the ``consumer_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -264,7 +258,6 @@ async def list_services( # If we have keyword arguments corresponding to fields on the # request, apply these. - if producer_project_id is not None: request.producer_project_id = producer_project_id if consumer_id is not None: @@ -314,7 +307,6 @@ async def get_service( This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -342,7 +334,6 @@ async def get_service( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name @@ -385,7 +376,6 @@ async def create_service( This corresponds to the ``service`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -414,7 +404,6 @@ async def create_service( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service is not None: request.service = service @@ -464,13 +453,13 @@ async def delete_service( method. service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -510,7 +499,6 @@ async def delete_service( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name @@ -529,7 +517,7 @@ async def delete_service( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=resources.OperationMetadata, ) @@ -559,13 +547,13 @@ async def undelete_service( method. service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -595,7 +583,6 @@ async def undelete_service( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name @@ -639,13 +626,13 @@ async def list_service_configs( ListServiceConfigs method. service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -675,7 +662,6 @@ async def list_service_configs( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name @@ -709,7 +695,7 @@ async def get_service_config( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> service.Service: + ) -> service_pb2.Service: r"""Gets a service configuration (version) for a managed service. @@ -719,8 +705,9 @@ async def get_service_config( method. service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -742,7 +729,6 @@ async def get_service_config( This corresponds to the ``view`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -761,7 +747,7 @@ async def get_service_config( Example: - type: google.api.Service config_version: 3 name: + type: google.api.Service name: calendar.googleapis.com title: Google Calendar API apis: - name: google.calendar.v3.Calendar authentication: providers: - id: @@ -786,7 +772,6 @@ async def get_service_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if config_id is not None: @@ -813,11 +798,11 @@ async def create_service_config( request: servicemanager.CreateServiceConfigRequest = None, *, service_name: str = None, - service_config: service.Service = None, + service_config: service_pb2.Service = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> service.Service: + ) -> service_pb2.Service: r"""Creates a new service configuration (version) for a managed service. This method only stores the service configuration. To roll out the service configuration to backend systems please @@ -834,8 +819,9 @@ async def create_service_config( CreateServiceConfig method. service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -847,7 +833,6 @@ async def create_service_config( This corresponds to the ``service_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -866,7 +851,7 @@ async def create_service_config( Example: - type: google.api.Service config_version: 3 name: + type: google.api.Service name: calendar.googleapis.com title: Google Calendar API apis: - name: google.calendar.v3.Calendar authentication: providers: - id: @@ -891,7 +876,6 @@ async def create_service_config( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if service_config is not None: @@ -942,8 +926,9 @@ async def submit_config_source( SubmitConfigSource method. service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -964,7 +949,6 @@ async def submit_config_source( This corresponds to the ``validate_only`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -994,7 +978,6 @@ async def submit_config_source( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if config_source is not None: @@ -1044,8 +1027,9 @@ async def list_service_rollouts( 'ListServiceRollouts' service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1053,18 +1037,17 @@ async def list_service_rollouts( filter (:class:`str`): Required. Use ``filter`` to return subset of rollouts. The following filters are supported: -- To limit the - results to only those in - `status `__ + results to only those in status + (google.api.servicemanagement.v1.RolloutStatus) 'SUCCESS', use filter='status=SUCCESS' -- To limit the - results to those in - `status `__ + results to those in status + (google.api.servicemanagement.v1.RolloutStatus) 'CANCELLED' or 'FAILED', use filter='status=CANCELLED OR status=FAILED' This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1094,7 +1077,6 @@ async def list_service_rollouts( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if filter is not None: @@ -1139,8 +1121,9 @@ async def get_service_rollout( GetServiceRollout method. service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1152,7 +1135,6 @@ async def get_service_rollout( This corresponds to the ``rollout_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1183,7 +1165,6 @@ async def get_service_rollout( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if rollout_id is not None: @@ -1237,8 +1218,9 @@ async def create_service_rollout( 'CreateServiceRollout' service_name (:class:`str`): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1250,7 +1232,6 @@ async def create_service_rollout( This corresponds to the ``rollout`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1281,7 +1262,6 @@ async def create_service_rollout( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if rollout is not None: @@ -1313,8 +1293,8 @@ async def generate_config_report( self, request: servicemanager.GenerateConfigReportRequest = None, *, - new_config: gp_any.Any = None, - old_config: gp_any.Any = None, + new_config: any_pb2.Any = None, + old_config: any_pb2.Any = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -1358,7 +1338,6 @@ async def generate_config_report( This corresponds to the ``old_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1385,7 +1364,6 @@ async def generate_config_report( # If we have keyword arguments corresponding to fields on the # request, apply these. - if new_config is not None: request.new_config = new_config if old_config is not None: @@ -1450,7 +1428,6 @@ async def enable_service( This corresponds to the ``consumer_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1480,7 +1457,6 @@ async def enable_service( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if consumer_id is not None: @@ -1553,7 +1529,6 @@ async def disable_service( This corresponds to the ``consumer_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1583,7 +1558,6 @@ async def disable_service( # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if consumer_id is not None: diff --git a/google/cloud/servicemanagement_v1/services/service_manager/client.py b/google/cloud/servicemanagement_v1/services/service_manager/client.py index 29f75e9..7c291ca 100644 --- a/google/cloud/servicemanagement_v1/services/service_manager/client.py +++ b/google/cloud/servicemanagement_v1/services/service_manager/client.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from distutils import util import os @@ -23,45 +21,44 @@ import pkg_resources from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions # type: ignore +from google.api_core import 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.auth import credentials # type: ignore +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 -from google.api import auth_pb2 as auth # type: ignore -from google.api import backend_pb2 as backend # type: ignore -from google.api import billing_pb2 as billing # type: ignore -from google.api import context_pb2 as context # type: ignore -from google.api import control_pb2 as control # type: ignore -from google.api import documentation_pb2 as documentation # type: ignore -from google.api import endpoint_pb2 as endpoint # type: ignore -from google.api import http_pb2 as http # type: ignore -from google.api import log_pb2 as log # type: ignore -from google.api import logging_pb2 as logging # type: ignore -from google.api import metric_pb2 as metric # type: ignore -from google.api import monitored_resource_pb2 as monitored_resource # type: ignore -from google.api import monitoring_pb2 as monitoring # type: ignore -from google.api import quota_pb2 as quota # type: ignore -from google.api import service_pb2 as service # type: ignore -from google.api import source_info_pb2 as source_info # type: ignore -from google.api import system_parameter_pb2 as system_parameter # type: ignore -from google.api import usage_pb2 as usage # type: ignore +from google.api import auth_pb2 # type: ignore +from google.api import backend_pb2 # type: ignore +from google.api import billing_pb2 # type: ignore +from google.api import context_pb2 # type: ignore +from google.api import control_pb2 # type: ignore +from google.api import documentation_pb2 # type: ignore +from google.api import endpoint_pb2 # type: ignore +from google.api import http_pb2 # type: ignore +from google.api import log_pb2 # type: ignore +from google.api import logging_pb2 # type: ignore +from google.api import metric_pb2 # type: ignore +from google.api import monitored_resource_pb2 # type: ignore +from google.api import monitoring_pb2 # type: ignore +from google.api import quota_pb2 # type: ignore +from google.api import service_pb2 # type: ignore +from google.api import source_info_pb2 # type: ignore +from google.api import system_parameter_pb2 # type: ignore +from google.api import usage_pb2 # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.servicemanagement_v1.services.service_manager import pagers from google.cloud.servicemanagement_v1.types import resources from google.cloud.servicemanagement_v1.types import servicemanager -from google.protobuf import any_pb2 as gp_any # type: ignore -from google.protobuf import api_pb2 as api # type: ignore -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.protobuf import type_pb2 as gp_type # type: ignore -from google.protobuf import wrappers_pb2 as wrappers # type: ignore - +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import api_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import type_pb2 # type: ignore +from google.protobuf import wrappers_pb2 # type: ignore from .transports.base import ServiceManagerTransport, DEFAULT_CLIENT_INFO from .transports.grpc import ServiceManagerGrpcTransport from .transports.grpc_asyncio import ServiceManagerGrpcAsyncIOTransport @@ -82,7 +79,7 @@ class ServiceManagerClientMeta(type): _transport_registry["grpc_asyncio"] = ServiceManagerGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[ServiceManagerTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -101,11 +98,14 @@ def get_transport_class(cls, label: str = None,) -> Type[ServiceManagerTransport class ServiceManagerClient(metaclass=ServiceManagerClientMeta): - """`Google Service Management API `__""" + """`Google Service Management + API `__ + """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -139,7 +139,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -156,7 +157,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -175,16 +176,17 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ServiceManagerTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - ServiceManagerTransport: The transport used by the client instance. + ServiceManagerTransport: The transport used by the client + instance. """ return self._transport @staticmethod def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -197,7 +199,7 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: @staticmethod def common_folder_path(folder: str,) -> str: - """Return a fully-qualified folder string.""" + """Returns a fully-qualified folder string.""" return "folders/{folder}".format(folder=folder,) @staticmethod @@ -208,7 +210,7 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: @staticmethod def common_organization_path(organization: str,) -> str: - """Return a fully-qualified organization string.""" + """Returns a fully-qualified organization string.""" return "organizations/{organization}".format(organization=organization,) @staticmethod @@ -219,7 +221,7 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: @staticmethod def common_project_path(project: str,) -> str: - """Return a fully-qualified project string.""" + """Returns a fully-qualified project string.""" return "projects/{project}".format(project=project,) @staticmethod @@ -230,7 +232,7 @@ def parse_common_project_path(path: str) -> Dict[str, str]: @staticmethod def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -244,12 +246,12 @@ def parse_common_location_path(path: str) -> Dict[str, str]: def __init__( self, *, - credentials: Optional[credentials.Credentials] = None, + credentials: Optional[ga_credentials.Credentials] = None, transport: Union[str, ServiceManagerTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the service manager client. + """Instantiates the service manager client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -304,9 +306,10 @@ def __init__( client_cert_source_func = client_options.client_cert_source else: is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() if is_mtls else None - ) + 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: @@ -318,12 +321,14 @@ def __init__( elif use_mtls_env == "always": api_endpoint = self.DEFAULT_MTLS_ENDPOINT elif use_mtls_env == "auto": - api_endpoint = ( - self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT - ) + 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" + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " + "values: never, auto, always" ) # Save or instantiate the transport. @@ -338,8 +343,8 @@ def __init__( ) if client_options.scopes: raise ValueError( - "When providing a transport instance, " - "provide its scopes directly." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: @@ -396,7 +401,6 @@ def list_services( This corresponds to the ``consumer_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -427,10 +431,8 @@ def list_services( # there are no flattened fields. if not isinstance(request, servicemanager.ListServicesRequest): request = servicemanager.ListServicesRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if producer_project_id is not None: request.producer_project_id = producer_project_id if consumer_id is not None: @@ -476,7 +478,6 @@ def get_service( This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -506,10 +507,8 @@ def get_service( # there are no flattened fields. if not isinstance(request, servicemanager.GetServiceRequest): request = servicemanager.GetServiceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name @@ -548,7 +547,6 @@ def create_service( This corresponds to the ``service`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -579,10 +577,8 @@ def create_service( # there are no flattened fields. if not isinstance(request, servicemanager.CreateServiceRequest): request = servicemanager.CreateServiceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service is not None: request.service = service @@ -628,13 +624,13 @@ def delete_service( method. service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -676,10 +672,8 @@ def delete_service( # there are no flattened fields. if not isinstance(request, servicemanager.DeleteServiceRequest): request = servicemanager.DeleteServiceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name @@ -694,7 +688,7 @@ def delete_service( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=resources.OperationMetadata, ) @@ -724,13 +718,13 @@ def undelete_service( method. service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -762,10 +756,8 @@ def undelete_service( # there are no flattened fields. if not isinstance(request, servicemanager.UndeleteServiceRequest): request = servicemanager.UndeleteServiceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name @@ -805,13 +797,13 @@ def list_service_configs( ListServiceConfigs method. service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -843,10 +835,8 @@ def list_service_configs( # there are no flattened fields. if not isinstance(request, servicemanager.ListServiceConfigsRequest): request = servicemanager.ListServiceConfigsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name @@ -876,7 +866,7 @@ def get_service_config( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> service.Service: + ) -> service_pb2.Service: r"""Gets a service configuration (version) for a managed service. @@ -886,8 +876,9 @@ def get_service_config( method. service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -909,7 +900,6 @@ def get_service_config( This corresponds to the ``view`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -928,7 +918,7 @@ def get_service_config( Example: - type: google.api.Service config_version: 3 name: + type: google.api.Service name: calendar.googleapis.com title: Google Calendar API apis: - name: google.calendar.v3.Calendar authentication: providers: - id: @@ -955,10 +945,8 @@ def get_service_config( # there are no flattened fields. if not isinstance(request, servicemanager.GetServiceConfigRequest): request = servicemanager.GetServiceConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if config_id is not None: @@ -981,11 +969,11 @@ def create_service_config( request: servicemanager.CreateServiceConfigRequest = None, *, service_name: str = None, - service_config: service.Service = None, + service_config: service_pb2.Service = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> service.Service: + ) -> service_pb2.Service: r"""Creates a new service configuration (version) for a managed service. This method only stores the service configuration. To roll out the service configuration to backend systems please @@ -1002,8 +990,9 @@ def create_service_config( CreateServiceConfig method. service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1015,7 +1004,6 @@ def create_service_config( This corresponds to the ``service_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1034,7 +1022,7 @@ def create_service_config( Example: - type: google.api.Service config_version: 3 name: + type: google.api.Service name: calendar.googleapis.com title: Google Calendar API apis: - name: google.calendar.v3.Calendar authentication: providers: - id: @@ -1061,10 +1049,8 @@ def create_service_config( # there are no flattened fields. if not isinstance(request, servicemanager.CreateServiceConfigRequest): request = servicemanager.CreateServiceConfigRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if service_config is not None: @@ -1111,8 +1097,9 @@ def submit_config_source( SubmitConfigSource method. service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1133,7 +1120,6 @@ def submit_config_source( This corresponds to the ``validate_only`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1165,10 +1151,8 @@ def submit_config_source( # there are no flattened fields. if not isinstance(request, servicemanager.SubmitConfigSourceRequest): request = servicemanager.SubmitConfigSourceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if config_source is not None: @@ -1214,8 +1198,9 @@ def list_service_rollouts( 'ListServiceRollouts' service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1223,18 +1208,17 @@ def list_service_rollouts( filter (str): Required. Use ``filter`` to return subset of rollouts. The following filters are supported: -- To limit the - results to only those in - `status `__ + results to only those in status + (google.api.servicemanagement.v1.RolloutStatus) 'SUCCESS', use filter='status=SUCCESS' -- To limit the - results to those in - `status `__ + results to those in status + (google.api.servicemanagement.v1.RolloutStatus) 'CANCELLED' or 'FAILED', use filter='status=CANCELLED OR status=FAILED' This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1266,10 +1250,8 @@ def list_service_rollouts( # there are no flattened fields. if not isinstance(request, servicemanager.ListServiceRolloutsRequest): request = servicemanager.ListServiceRolloutsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if filter is not None: @@ -1310,8 +1292,9 @@ def get_service_rollout( GetServiceRollout method. service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1323,7 +1306,6 @@ def get_service_rollout( This corresponds to the ``rollout_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1356,10 +1338,8 @@ def get_service_rollout( # there are no flattened fields. if not isinstance(request, servicemanager.GetServiceRolloutRequest): request = servicemanager.GetServiceRolloutRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if rollout_id is not None: @@ -1409,8 +1389,9 @@ def create_service_rollout( 'CreateServiceRollout' service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. This corresponds to the ``service_name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1422,7 +1403,6 @@ def create_service_rollout( This corresponds to the ``rollout`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1455,10 +1435,8 @@ def create_service_rollout( # there are no flattened fields. if not isinstance(request, servicemanager.CreateServiceRolloutRequest): request = servicemanager.CreateServiceRolloutRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if rollout is not None: @@ -1486,8 +1464,8 @@ def generate_config_report( self, request: servicemanager.GenerateConfigReportRequest = None, *, - new_config: gp_any.Any = None, - old_config: gp_any.Any = None, + new_config: any_pb2.Any = None, + old_config: any_pb2.Any = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -1531,7 +1509,6 @@ def generate_config_report( This corresponds to the ``old_config`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1560,10 +1537,8 @@ def generate_config_report( # there are no flattened fields. if not isinstance(request, servicemanager.GenerateConfigReportRequest): request = servicemanager.GenerateConfigReportRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if new_config is not None: request.new_config = new_config if old_config is not None: @@ -1624,7 +1599,6 @@ def enable_service( This corresponds to the ``consumer_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1656,10 +1630,8 @@ def enable_service( # there are no flattened fields. if not isinstance(request, servicemanager.EnableServiceRequest): request = servicemanager.EnableServiceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if consumer_id is not None: @@ -1728,7 +1700,6 @@ def disable_service( This corresponds to the ``consumer_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -1760,10 +1731,8 @@ def disable_service( # there are no flattened fields. if not isinstance(request, servicemanager.DisableServiceRequest): request = servicemanager.DisableServiceRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if service_name is not None: request.service_name = service_name if consumer_id is not None: diff --git a/google/cloud/servicemanagement_v1/services/service_manager/pagers.py b/google/cloud/servicemanagement_v1/services/service_manager/pagers.py index 50c8118..17baaeb 100644 --- a/google/cloud/servicemanagement_v1/services/service_manager/pagers.py +++ b/google/cloud/servicemanagement_v1/services/service_manager/pagers.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from typing import ( Any, AsyncIterable, @@ -26,7 +24,7 @@ Optional, ) -from google.api import service_pb2 as service # type: ignore +from google.api import service_pb2 # type: ignore from google.cloud.servicemanagement_v1.types import resources from google.cloud.servicemanagement_v1.types import servicemanager @@ -119,7 +117,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -213,7 +211,7 @@ def pages(self) -> Iterable[servicemanager.ListServiceConfigsResponse]: self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[service.Service]: + def __iter__(self) -> Iterable[service_pb2.Service]: for page in self.pages: yield from page.service_configs @@ -247,7 +245,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -275,7 +273,7 @@ async def pages(self) -> AsyncIterable[servicemanager.ListServiceConfigsResponse self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[service.Service]: + def __aiter__(self) -> AsyncIterable[service_pb2.Service]: async def async_generator(): async for page in self.pages: for response in page.service_configs: @@ -375,7 +373,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and diff --git a/google/cloud/servicemanagement_v1/services/service_manager/transports/__init__.py b/google/cloud/servicemanagement_v1/services/service_manager/transports/__init__.py index fccec92..a7e0a1a 100644 --- a/google/cloud/servicemanagement_v1/services/service_manager/transports/__init__.py +++ b/google/cloud/servicemanagement_v1/services/service_manager/transports/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from collections import OrderedDict from typing import Dict, Type diff --git a/google/cloud/servicemanagement_v1/services/service_manager/transports/base.py b/google/cloud/servicemanagement_v1/services/service_manager/transports/base.py index 33fe533..1414f04 100644 --- a/google/cloud/servicemanagement_v1/services/service_manager/transports/base.py +++ b/google/cloud/servicemanagement_v1/services/service_manager/transports/base.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,23 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import abc -import typing +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import packaging.version import pkg_resources -from google import auth # type: ignore -from google.api_core import exceptions # type: ignore +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 from google.api_core import operations_v1 # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore -from google.api import service_pb2 as service # type: ignore +from google.api import service_pb2 # type: ignore from google.cloud.servicemanagement_v1.types import resources from google.cloud.servicemanagement_v1.types import servicemanager -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -41,6 +40,17 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() +try: + # google.auth.__version__ was added in 1.26.0 + _GOOGLE_AUTH_VERSION = google.auth.__version__ +except AttributeError: + try: # try pkg_resources if it is available + _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version + except pkg_resources.DistributionNotFound: # pragma: NO COVER + _GOOGLE_AUTH_VERSION = None + +_API_CORE_VERSION = google.api_core.__version__ + class ServiceManagerTransport(abc.ABC): """Abstract transport class for ServiceManager.""" @@ -52,21 +62,24 @@ class ServiceManagerTransport(abc.ABC): "https://www.googleapis.com/auth/service.management.readonly", ) + DEFAULT_HOST: str = "servicemanagement.googleapis.com" + def __init__( self, *, - host: str = "servicemanagement.googleapis.com", - credentials: credentials.Credentials = None, - credentials_file: typing.Optional[str] = None, - scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES, - quota_project_id: typing.Optional[str] = None, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, **kwargs, ) -> None: """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -75,7 +88,7 @@ def __init__( credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. This argument is mutually exclusive with credentials. - scope (Optional[Sequence[str]]): A list of scopes. + scopes (Optional[Sequence[str]]): A list of scopes. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -89,29 +102,76 @@ def __init__( host += ":443" self._host = host + scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + # Save the scopes. self._scopes = scopes or self.AUTH_SCOPES # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise exceptions.DuplicateCredentialArgs( + raise core_exceptions.DuplicateCredentialArgs( "'credentials_file' and 'credentials' are mutually exclusive" ) if credentials_file is not None: - credentials, _ = auth.load_credentials_from_file( - credentials_file, scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) elif credentials is None: - credentials, _ = auth.default( - scopes=self._scopes, quota_project_id=quota_project_id + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id ) # Save the credentials. self._credentials = credentials + # TODO(busunkim): These two class methods are in the base transport + # to avoid duplicating code across the transport classes. These functions + # should be deleted once the minimum required versions of google-api-core + # and google-auth are increased. + + # TODO: Remove this function once google-auth >= 1.25.0 is required + @classmethod + def _get_scopes_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Optional[Sequence[str]]]: + """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" + + scopes_kwargs = {} + + if _GOOGLE_AUTH_VERSION and ( + packaging.version.parse(_GOOGLE_AUTH_VERSION) + >= packaging.version.parse("1.25.0") + ): + scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} + else: + scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + + return scopes_kwargs + + # TODO: Remove this function once google-api-core >= 1.26.0 is required + @classmethod + def _get_self_signed_jwt_kwargs( + cls, host: str, scopes: Optional[Sequence[str]] + ) -> Dict[str, Union[Optional[Sequence[str]], str]]: + """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + + self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + + if _API_CORE_VERSION and ( + packaging.version.parse(_API_CORE_VERSION) + >= packaging.version.parse("1.26.0") + ): + self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES + self_signed_jwt_kwargs["scopes"] = scopes + self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST + else: + self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + + return self_signed_jwt_kwargs + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -182,11 +242,11 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_services( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.ListServicesRequest], - typing.Union[ + Union[ servicemanager.ListServicesResponse, - typing.Awaitable[servicemanager.ListServicesResponse], + Awaitable[servicemanager.ListServicesResponse], ], ]: raise NotImplementedError() @@ -194,49 +254,47 @@ def list_services( @property def get_service( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.GetServiceRequest], - typing.Union[ - resources.ManagedService, typing.Awaitable[resources.ManagedService] - ], + Union[resources.ManagedService, Awaitable[resources.ManagedService]], ]: raise NotImplementedError() @property def create_service( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.CreateServiceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_service( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.DeleteServiceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def undelete_service( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.UndeleteServiceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def list_service_configs( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.ListServiceConfigsRequest], - typing.Union[ + Union[ servicemanager.ListServiceConfigsResponse, - typing.Awaitable[servicemanager.ListServiceConfigsResponse], + Awaitable[servicemanager.ListServiceConfigsResponse], ], ]: raise NotImplementedError() @@ -244,38 +302,38 @@ def list_service_configs( @property def get_service_config( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.GetServiceConfigRequest], - typing.Union[service.Service, typing.Awaitable[service.Service]], + Union[service_pb2.Service, Awaitable[service_pb2.Service]], ]: raise NotImplementedError() @property def create_service_config( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.CreateServiceConfigRequest], - typing.Union[service.Service, typing.Awaitable[service.Service]], + Union[service_pb2.Service, Awaitable[service_pb2.Service]], ]: raise NotImplementedError() @property def submit_config_source( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.SubmitConfigSourceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def list_service_rollouts( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.ListServiceRolloutsRequest], - typing.Union[ + Union[ servicemanager.ListServiceRolloutsResponse, - typing.Awaitable[servicemanager.ListServiceRolloutsResponse], + Awaitable[servicemanager.ListServiceRolloutsResponse], ], ]: raise NotImplementedError() @@ -283,29 +341,29 @@ def list_service_rollouts( @property def get_service_rollout( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.GetServiceRolloutRequest], - typing.Union[resources.Rollout, typing.Awaitable[resources.Rollout]], + Union[resources.Rollout, Awaitable[resources.Rollout]], ]: raise NotImplementedError() @property def create_service_rollout( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.CreateServiceRolloutRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def generate_config_report( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.GenerateConfigReportRequest], - typing.Union[ + Union[ servicemanager.GenerateConfigReportResponse, - typing.Awaitable[servicemanager.GenerateConfigReportResponse], + Awaitable[servicemanager.GenerateConfigReportResponse], ], ]: raise NotImplementedError() @@ -313,18 +371,18 @@ def generate_config_report( @property def enable_service( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.EnableServiceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def disable_service( self, - ) -> typing.Callable[ + ) -> Callable[ [servicemanager.DisableServiceRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc.py b/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc.py index 0cab753..bfee8dc 100644 --- a/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc.py +++ b/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,31 +13,30 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple +from typing import Callable, Dict, Optional, Sequence, Tuple, Union from google.api_core import grpc_helpers # type: ignore from google.api_core import operations_v1 # type: ignore from google.api_core import gapic_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore -from google.api import service_pb2 as service # type: ignore +from google.api import service_pb2 # type: ignore from google.cloud.servicemanagement_v1.types import resources from google.cloud.servicemanagement_v1.types import servicemanager -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import ServiceManagerTransport, DEFAULT_CLIENT_INFO class ServiceManagerGrpcTransport(ServiceManagerTransport): """gRPC backend transport for ServiceManager. - `Google Service Management API `__ + `Google Service Management + API `__ This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -54,7 +52,7 @@ def __init__( self, *, host: str = "servicemanagement.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -68,7 +66,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -179,7 +178,7 @@ def __init__( def create_channel( cls, host: str = "servicemanagement.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -210,13 +209,15 @@ def create_channel( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -306,7 +307,7 @@ def get_service( @property def create_service( self, - ) -> Callable[[servicemanager.CreateServiceRequest], operations.Operation]: + ) -> Callable[[servicemanager.CreateServiceRequest], operations_pb2.Operation]: r"""Return a callable for the create service method over gRPC. Creates a new managed service. @@ -328,14 +329,14 @@ def create_service( self._stubs["create_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/CreateService", request_serializer=servicemanager.CreateServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_service"] @property def delete_service( self, - ) -> Callable[[servicemanager.DeleteServiceRequest], operations.Operation]: + ) -> Callable[[servicemanager.DeleteServiceRequest], operations_pb2.Operation]: r"""Return a callable for the delete service method over gRPC. Deletes a managed service. This method will change the service @@ -361,14 +362,14 @@ def delete_service( self._stubs["delete_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/DeleteService", request_serializer=servicemanager.DeleteServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_service"] @property def undelete_service( self, - ) -> Callable[[servicemanager.UndeleteServiceRequest], operations.Operation]: + ) -> Callable[[servicemanager.UndeleteServiceRequest], operations_pb2.Operation]: r"""Return a callable for the undelete service method over gRPC. Revives a previously deleted managed service. The @@ -393,7 +394,7 @@ def undelete_service( self._stubs["undelete_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/UndeleteService", request_serializer=servicemanager.UndeleteServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["undelete_service"] @@ -430,7 +431,7 @@ def list_service_configs( @property def get_service_config( self, - ) -> Callable[[servicemanager.GetServiceConfigRequest], service.Service]: + ) -> Callable[[servicemanager.GetServiceConfigRequest], service_pb2.Service]: r"""Return a callable for the get service config method over gRPC. Gets a service configuration (version) for a managed @@ -450,14 +451,14 @@ def get_service_config( self._stubs["get_service_config"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/GetServiceConfig", request_serializer=servicemanager.GetServiceConfigRequest.serialize, - response_deserializer=service.Service.FromString, + response_deserializer=service_pb2.Service.FromString, ) return self._stubs["get_service_config"] @property def create_service_config( self, - ) -> Callable[[servicemanager.CreateServiceConfigRequest], service.Service]: + ) -> Callable[[servicemanager.CreateServiceConfigRequest], service_pb2.Service]: r"""Return a callable for the create service config method over gRPC. Creates a new service configuration (version) for a managed @@ -484,14 +485,14 @@ def create_service_config( self._stubs["create_service_config"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/CreateServiceConfig", request_serializer=servicemanager.CreateServiceConfigRequest.serialize, - response_deserializer=service.Service.FromString, + response_deserializer=service_pb2.Service.FromString, ) return self._stubs["create_service_config"] @property def submit_config_source( self, - ) -> Callable[[servicemanager.SubmitConfigSourceRequest], operations.Operation]: + ) -> Callable[[servicemanager.SubmitConfigSourceRequest], operations_pb2.Operation]: r"""Return a callable for the submit config source method over gRPC. Creates a new service configuration (version) for a managed @@ -522,7 +523,7 @@ def submit_config_source( self._stubs["submit_config_source"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/SubmitConfigSource", request_serializer=servicemanager.SubmitConfigSourceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["submit_config_source"] @@ -587,7 +588,9 @@ def get_service_rollout( @property def create_service_rollout( self, - ) -> Callable[[servicemanager.CreateServiceRolloutRequest], operations.Operation]: + ) -> Callable[ + [servicemanager.CreateServiceRolloutRequest], operations_pb2.Operation + ]: r"""Return a callable for the create service rollout method over gRPC. Creates a new service configuration rollout. Based on @@ -622,7 +625,7 @@ def create_service_rollout( self._stubs["create_service_rollout"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/CreateServiceRollout", request_serializer=servicemanager.CreateServiceRolloutRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_service_rollout"] @@ -669,7 +672,7 @@ def generate_config_report( @property def enable_service( self, - ) -> Callable[[servicemanager.EnableServiceRequest], operations.Operation]: + ) -> Callable[[servicemanager.EnableServiceRequest], operations_pb2.Operation]: r"""Return a callable for the enable service method over gRPC. Enables a @@ -694,14 +697,14 @@ def enable_service( self._stubs["enable_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/EnableService", request_serializer=servicemanager.EnableServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["enable_service"] @property def disable_service( self, - ) -> Callable[[servicemanager.DisableServiceRequest], operations.Operation]: + ) -> Callable[[servicemanager.DisableServiceRequest], operations_pb2.Operation]: r"""Return a callable for the disable service method over gRPC. Disables a @@ -726,7 +729,7 @@ def disable_service( self._stubs["disable_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/DisableService", request_serializer=servicemanager.DisableServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["disable_service"] diff --git a/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc_asyncio.py b/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc_asyncio.py index 7b3ae3e..3164b28 100644 --- a/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc_asyncio.py +++ b/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc_asyncio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,25 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple +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 operations_v1 # type: ignore -from google import auth # type: ignore -from google.auth import credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore -from google.api import service_pb2 as service # type: ignore +from google.api import service_pb2 # type: ignore from google.cloud.servicemanagement_v1.types import resources from google.cloud.servicemanagement_v1.types import servicemanager -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import ServiceManagerTransport, DEFAULT_CLIENT_INFO from .grpc import ServiceManagerGrpcTransport @@ -40,7 +37,8 @@ class ServiceManagerGrpcAsyncIOTransport(ServiceManagerTransport): """gRPC AsyncIO backend transport for ServiceManager. - `Google Service Management API `__ + `Google Service Management + API `__ This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -57,7 +55,7 @@ class ServiceManagerGrpcAsyncIOTransport(ServiceManagerTransport): def create_channel( cls, host: str = "servicemanagement.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, @@ -84,13 +82,15 @@ def create_channel( Returns: aio.Channel: A gRPC AsyncIO channel object. """ - scopes = scopes or cls.AUTH_SCOPES + + self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) + return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, - scopes=scopes, quota_project_id=quota_project_id, + **self_signed_jwt_kwargs, **kwargs, ) @@ -98,7 +98,7 @@ def __init__( self, *, host: str = "servicemanagement.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, channel: aio.Channel = None, @@ -112,7 +112,8 @@ def __init__( """Instantiate the transport. Args: - host (Optional[str]): The hostname to connect to. + host (Optional[str]): + The hostname to connect to. credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none @@ -171,7 +172,6 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel self._ssl_channel_credentials = None - else: if api_mtls_endpoint: host = api_mtls_endpoint @@ -316,7 +316,7 @@ def get_service( def create_service( self, ) -> Callable[ - [servicemanager.CreateServiceRequest], Awaitable[operations.Operation] + [servicemanager.CreateServiceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the create service method over gRPC. @@ -339,7 +339,7 @@ def create_service( self._stubs["create_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/CreateService", request_serializer=servicemanager.CreateServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_service"] @@ -347,7 +347,7 @@ def create_service( def delete_service( self, ) -> Callable[ - [servicemanager.DeleteServiceRequest], Awaitable[operations.Operation] + [servicemanager.DeleteServiceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the delete service method over gRPC. @@ -374,7 +374,7 @@ def delete_service( self._stubs["delete_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/DeleteService", request_serializer=servicemanager.DeleteServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_service"] @@ -382,7 +382,7 @@ def delete_service( def undelete_service( self, ) -> Callable[ - [servicemanager.UndeleteServiceRequest], Awaitable[operations.Operation] + [servicemanager.UndeleteServiceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the undelete service method over gRPC. @@ -408,7 +408,7 @@ def undelete_service( self._stubs["undelete_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/UndeleteService", request_serializer=servicemanager.UndeleteServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["undelete_service"] @@ -445,7 +445,9 @@ def list_service_configs( @property def get_service_config( self, - ) -> Callable[[servicemanager.GetServiceConfigRequest], Awaitable[service.Service]]: + ) -> Callable[ + [servicemanager.GetServiceConfigRequest], Awaitable[service_pb2.Service] + ]: r"""Return a callable for the get service config method over gRPC. Gets a service configuration (version) for a managed @@ -465,7 +467,7 @@ def get_service_config( self._stubs["get_service_config"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/GetServiceConfig", request_serializer=servicemanager.GetServiceConfigRequest.serialize, - response_deserializer=service.Service.FromString, + response_deserializer=service_pb2.Service.FromString, ) return self._stubs["get_service_config"] @@ -473,7 +475,7 @@ def get_service_config( def create_service_config( self, ) -> Callable[ - [servicemanager.CreateServiceConfigRequest], Awaitable[service.Service] + [servicemanager.CreateServiceConfigRequest], Awaitable[service_pb2.Service] ]: r"""Return a callable for the create service config method over gRPC. @@ -501,7 +503,7 @@ def create_service_config( self._stubs["create_service_config"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/CreateServiceConfig", request_serializer=servicemanager.CreateServiceConfigRequest.serialize, - response_deserializer=service.Service.FromString, + response_deserializer=service_pb2.Service.FromString, ) return self._stubs["create_service_config"] @@ -509,7 +511,7 @@ def create_service_config( def submit_config_source( self, ) -> Callable[ - [servicemanager.SubmitConfigSourceRequest], Awaitable[operations.Operation] + [servicemanager.SubmitConfigSourceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the submit config source method over gRPC. @@ -541,7 +543,7 @@ def submit_config_source( self._stubs["submit_config_source"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/SubmitConfigSource", request_serializer=servicemanager.SubmitConfigSourceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["submit_config_source"] @@ -609,7 +611,8 @@ def get_service_rollout( def create_service_rollout( self, ) -> Callable[ - [servicemanager.CreateServiceRolloutRequest], Awaitable[operations.Operation] + [servicemanager.CreateServiceRolloutRequest], + Awaitable[operations_pb2.Operation], ]: r"""Return a callable for the create service rollout method over gRPC. @@ -645,7 +648,7 @@ def create_service_rollout( self._stubs["create_service_rollout"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/CreateServiceRollout", request_serializer=servicemanager.CreateServiceRolloutRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_service_rollout"] @@ -693,7 +696,7 @@ def generate_config_report( def enable_service( self, ) -> Callable[ - [servicemanager.EnableServiceRequest], Awaitable[operations.Operation] + [servicemanager.EnableServiceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the enable service method over gRPC. @@ -719,7 +722,7 @@ def enable_service( self._stubs["enable_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/EnableService", request_serializer=servicemanager.EnableServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["enable_service"] @@ -727,7 +730,7 @@ def enable_service( def disable_service( self, ) -> Callable[ - [servicemanager.DisableServiceRequest], Awaitable[operations.Operation] + [servicemanager.DisableServiceRequest], Awaitable[operations_pb2.Operation] ]: r"""Return a callable for the disable service method over gRPC. @@ -753,7 +756,7 @@ def disable_service( self._stubs["disable_service"] = self.grpc_channel.unary_unary( "/google.api.servicemanagement.v1.ServiceManager/DisableService", request_serializer=servicemanager.DisableServiceRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["disable_service"] diff --git a/google/cloud/servicemanagement_v1/types/__init__.py b/google/cloud/servicemanagement_v1/types/__init__.py index c7734db..d73013e 100644 --- a/google/cloud/servicemanagement_v1/types/__init__.py +++ b/google/cloud/servicemanagement_v1/types/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - from .resources import ( ChangeReport, ConfigFile, diff --git a/google/cloud/servicemanagement_v1/types/resources.py b/google/cloud/servicemanagement_v1/types/resources.py index 785979a..1cfe21d 100644 --- a/google/cloud/servicemanagement_v1/types/resources.py +++ b/google/cloud/servicemanagement_v1/types/resources.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,12 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.api import config_change_pb2 as config_change # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.api import config_change_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -44,16 +41,15 @@ class ManagedService(proto.Message): Attributes: service_name (str): The name of the service. See the - `overview `__ for naming - requirements. + `overview `__ + for naming requirements. producer_project_id (str): ID of the project that produces and owns this service. """ - service_name = proto.Field(proto.STRING, number=2) - - producer_project_id = proto.Field(proto.STRING, number=3) + service_name = proto.Field(proto.STRING, number=2,) + producer_project_id = proto.Field(proto.STRING, number=3,) class OperationMetadata(proto.Message): @@ -87,7 +83,6 @@ class Status(proto.Enum): class Step(proto.Message): r"""Represents the status of one operation step. - Attributes: description (str): The short description of the step. @@ -95,22 +90,17 @@ class Step(proto.Message): The status code. """ - description = proto.Field(proto.STRING, number=2) - + description = proto.Field(proto.STRING, number=2,) status = proto.Field(proto.ENUM, number=4, enum="OperationMetadata.Status",) - resource_names = proto.RepeatedField(proto.STRING, number=1) - + resource_names = proto.RepeatedField(proto.STRING, number=1,) steps = proto.RepeatedField(proto.MESSAGE, number=2, message=Step,) - - progress_percentage = proto.Field(proto.INT32, number=3) - - start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) + progress_percentage = proto.Field(proto.INT32, number=3,) + start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) class Diagnostic(proto.Message): r"""Represents a diagnostic message (error or warning) - Attributes: location (str): File name and line number of the error or @@ -126,11 +116,9 @@ class Kind(proto.Enum): WARNING = 0 ERROR = 1 - location = proto.Field(proto.STRING, number=1) - + location = proto.Field(proto.STRING, number=1,) kind = proto.Field(proto.ENUM, number=2, enum=Kind,) - - message = proto.Field(proto.STRING, number=3) + message = proto.Field(proto.STRING, number=3,) class ConfigSource(proto.Message): @@ -148,14 +136,12 @@ class ConfigSource(proto.Message): a service configuration (``google.api.Service``). """ - id = proto.Field(proto.STRING, number=5) - + id = proto.Field(proto.STRING, number=5,) files = proto.RepeatedField(proto.MESSAGE, number=2, message="ConfigFile",) class ConfigFile(proto.Message): r"""Generic specification of a source configuration file - Attributes: file_path (str): The file name of the configuration file (full @@ -176,16 +162,13 @@ class FileType(proto.Enum): FILE_DESCRIPTOR_SET_PROTO = 4 PROTO_FILE = 6 - file_path = proto.Field(proto.STRING, number=1) - - file_contents = proto.Field(proto.BYTES, number=3) - + file_path = proto.Field(proto.STRING, number=1,) + file_contents = proto.Field(proto.BYTES, number=3,) file_type = proto.Field(proto.ENUM, number=4, enum=FileType,) class ConfigRef(proto.Message): r"""Represents a service configuration with its name and id. - Attributes: name (str): Resource name of a service config. It must @@ -193,7 +176,7 @@ class ConfigRef(proto.Message): name}/configs/{config id}". """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class ChangeReport(proto.Message): @@ -212,7 +195,7 @@ class ChangeReport(proto.Message): """ config_changes = proto.RepeatedField( - proto.MESSAGE, number=1, message=config_change.ConfigChange, + proto.MESSAGE, number=1, message=config_change_pb2.ConfigChange, ) @@ -307,31 +290,25 @@ class TrafficPercentStrategy(proto.Message): the sum must equal to 100.0. """ - percentages = proto.MapField(proto.STRING, proto.DOUBLE, number=1) + percentages = proto.MapField(proto.STRING, proto.DOUBLE, number=1,) class DeleteServiceStrategy(proto.Message): r"""Strategy used to delete a service. This strategy is a placeholder only used by the system generated rollout to delete a service. - """ - - rollout_id = proto.Field(proto.STRING, number=1) - - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - created_by = proto.Field(proto.STRING, number=3) + """ + rollout_id = proto.Field(proto.STRING, number=1,) + create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + created_by = proto.Field(proto.STRING, number=3,) status = proto.Field(proto.ENUM, number=4, enum=RolloutStatus,) - traffic_percent_strategy = proto.Field( proto.MESSAGE, number=5, oneof="strategy", message=TrafficPercentStrategy, ) - delete_service_strategy = proto.Field( proto.MESSAGE, number=200, oneof="strategy", message=DeleteServiceStrategy, ) - - service_name = proto.Field(proto.STRING, number=8) + service_name = proto.Field(proto.STRING, number=8,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/servicemanagement_v1/types/servicemanager.py b/google/cloud/servicemanagement_v1/types/servicemanager.py index 1162e10..3cbd9ed 100644 --- a/google/cloud/servicemanagement_v1/types/servicemanager.py +++ b/google/cloud/servicemanagement_v1/types/servicemanager.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.api import service_pb2 as ga_service # type: ignore +from google.api import service_pb2 # type: ignore from google.cloud.servicemanagement_v1.types import resources -from google.protobuf import any_pb2 as gp_any # type: ignore +from google.protobuf import any_pb2 # type: ignore __protobuf__ = proto.module( @@ -55,7 +52,6 @@ class ListServicesRequest(proto.Message): r"""Request message for ``ListServices`` method. - Attributes: producer_project_id (str): Include services produced by the specified @@ -76,18 +72,14 @@ class ListServicesRequest(proto.Message): - project: """ - producer_project_id = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=5) - - page_token = proto.Field(proto.STRING, number=6) - - consumer_id = proto.Field(proto.STRING, number=7) + producer_project_id = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=5,) + page_token = proto.Field(proto.STRING, number=6,) + consumer_id = proto.Field(proto.STRING, number=7,) class ListServicesResponse(proto.Message): r"""Response message for ``ListServices`` method. - Attributes: services (Sequence[google.cloud.servicemanagement_v1.types.ManagedService]): The returned services will only have the name @@ -104,13 +96,11 @@ def raw_page(self): services = proto.RepeatedField( proto.MESSAGE, number=1, message=resources.ManagedService, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class GetServiceRequest(proto.Message): r"""Request message for ``GetService`` method. - Attributes: service_name (str): Required. The name of the service. See the @@ -118,12 +108,11 @@ class GetServiceRequest(proto.Message): example: ``example.googleapis.com``. """ - service_name = proto.Field(proto.STRING, number=1) + service_name = proto.Field(proto.STRING, number=1,) class CreateServiceRequest(proto.Message): r"""Request message for CreateService method. - Attributes: service (google.cloud.servicemanagement_v1.types.ManagedService): Required. Initial values for the service @@ -135,33 +124,32 @@ class CreateServiceRequest(proto.Message): class DeleteServiceRequest(proto.Message): r"""Request message for DeleteService method. - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. """ - service_name = proto.Field(proto.STRING, number=1) + service_name = proto.Field(proto.STRING, number=1,) class UndeleteServiceRequest(proto.Message): r"""Request message for UndeleteService method. - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. """ - service_name = proto.Field(proto.STRING, number=1) + service_name = proto.Field(proto.STRING, number=1,) class UndeleteServiceResponse(proto.Message): r"""Response message for UndeleteService method. - Attributes: service (google.cloud.servicemanagement_v1.types.ManagedService): Revived service resource. @@ -172,12 +160,12 @@ class UndeleteServiceResponse(proto.Message): class GetServiceConfigRequest(proto.Message): r"""Request message for GetServiceConfig method. - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. config_id (str): Required. The id of the service configuration resource. @@ -193,21 +181,19 @@ class ConfigView(proto.Enum): BASIC = 0 FULL = 1 - service_name = proto.Field(proto.STRING, number=1) - - config_id = proto.Field(proto.STRING, number=2) - + service_name = proto.Field(proto.STRING, number=1,) + config_id = proto.Field(proto.STRING, number=2,) view = proto.Field(proto.ENUM, number=3, enum=ConfigView,) class ListServiceConfigsRequest(proto.Message): r"""Request message for ListServiceConfigs method. - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. page_token (str): The token of the page to retrieve. page_size (int): @@ -216,16 +202,13 @@ class ListServiceConfigsRequest(proto.Message): Maximum value is 100. """ - service_name = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) + service_name = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) class ListServiceConfigsResponse(proto.Message): r"""Response message for ListServiceConfigs method. - Attributes: service_configs (Sequence[google.api.service_pb2.Service]): The list of service configuration resources. @@ -238,37 +221,35 @@ def raw_page(self): return self service_configs = proto.RepeatedField( - proto.MESSAGE, number=1, message=ga_service.Service, + proto.MESSAGE, number=1, message=service_pb2.Service, ) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class CreateServiceConfigRequest(proto.Message): r"""Request message for CreateServiceConfig method. - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. service_config (google.api.service_pb2.Service): Required. The service configuration resource. """ - service_name = proto.Field(proto.STRING, number=1) - - service_config = proto.Field(proto.MESSAGE, number=2, message=ga_service.Service,) + service_name = proto.Field(proto.STRING, number=1,) + service_config = proto.Field(proto.MESSAGE, number=2, message=service_pb2.Service,) class SubmitConfigSourceRequest(proto.Message): r"""Request message for SubmitConfigSource method. - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. config_source (google.cloud.servicemanagement_v1.types.ConfigSource): Required. The source configuration for the service. @@ -279,52 +260,48 @@ class SubmitConfigSourceRequest(proto.Message): sources will NOT be persisted. """ - service_name = proto.Field(proto.STRING, number=1) - + service_name = proto.Field(proto.STRING, number=1,) config_source = proto.Field( proto.MESSAGE, number=2, message=resources.ConfigSource, ) - - validate_only = proto.Field(proto.BOOL, number=3) + validate_only = proto.Field(proto.BOOL, number=3,) class SubmitConfigSourceResponse(proto.Message): r"""Response message for SubmitConfigSource method. - Attributes: service_config (google.api.service_pb2.Service): The generated service configuration. """ - service_config = proto.Field(proto.MESSAGE, number=1, message=ga_service.Service,) + service_config = proto.Field(proto.MESSAGE, number=1, message=service_pb2.Service,) class CreateServiceRolloutRequest(proto.Message): r"""Request message for 'CreateServiceRollout' - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. rollout (google.cloud.servicemanagement_v1.types.Rollout): Required. The rollout resource. The ``service_name`` field is output only. """ - service_name = proto.Field(proto.STRING, number=1) - + service_name = proto.Field(proto.STRING, number=1,) rollout = proto.Field(proto.MESSAGE, number=2, message=resources.Rollout,) class ListServiceRolloutsRequest(proto.Message): r"""Request message for 'ListServiceRollouts' - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. page_token (str): The token of the page to retrieve. page_size (int): @@ -334,27 +311,22 @@ class ListServiceRolloutsRequest(proto.Message): filter (str): Required. Use ``filter`` to return subset of rollouts. The following filters are supported: -- To limit the results to - only those in - `status `__ - 'SUCCESS', use filter='status=SUCCESS' -- To limit the - results to those in - `status `__ + only those in status + (google.api.servicemanagement.v1.RolloutStatus) 'SUCCESS', + use filter='status=SUCCESS' -- To limit the results to those + in status (google.api.servicemanagement.v1.RolloutStatus) 'CANCELLED' or 'FAILED', use filter='status=CANCELLED OR status=FAILED' """ - service_name = proto.Field(proto.STRING, number=1) - - page_token = proto.Field(proto.STRING, number=2) - - page_size = proto.Field(proto.INT32, number=3) - - filter = proto.Field(proto.STRING, number=4) + service_name = proto.Field(proto.STRING, number=1,) + page_token = proto.Field(proto.STRING, number=2,) + page_size = proto.Field(proto.INT32, number=3,) + filter = proto.Field(proto.STRING, number=4,) class ListServiceRolloutsResponse(proto.Message): r"""Response message for ListServiceRollouts method. - Attributes: rollouts (Sequence[google.cloud.servicemanagement_v1.types.Rollout]): The list of rollout resources. @@ -367,30 +339,27 @@ def raw_page(self): return self rollouts = proto.RepeatedField(proto.MESSAGE, number=1, message=resources.Rollout,) - - next_page_token = proto.Field(proto.STRING, number=2) + next_page_token = proto.Field(proto.STRING, number=2,) class GetServiceRolloutRequest(proto.Message): r"""Request message for GetServiceRollout method. - Attributes: service_name (str): Required. The name of the service. See the - `overview `__ for naming - requirements. For example: ``example.googleapis.com``. + `overview `__ + for naming requirements. For example: + ``example.googleapis.com``. rollout_id (str): Required. The id of the rollout resource. """ - service_name = proto.Field(proto.STRING, number=1) - - rollout_id = proto.Field(proto.STRING, number=2) + service_name = proto.Field(proto.STRING, number=1,) + rollout_id = proto.Field(proto.STRING, number=2,) class EnableServiceRequest(proto.Message): r"""Request message for EnableService method. - Attributes: service_name (str): Required. Name of the service to enable. @@ -409,18 +378,16 @@ class EnableServiceRequest(proto.Message): google.api.servicecontrol.v1.Operation.consumer_id. """ - service_name = proto.Field(proto.STRING, number=1) - - consumer_id = proto.Field(proto.STRING, number=2) + service_name = proto.Field(proto.STRING, number=1,) + consumer_id = proto.Field(proto.STRING, number=2,) class EnableServiceResponse(proto.Message): - r"""Operation payload for EnableService method.""" + r"""Operation payload for EnableService method. """ class DisableServiceRequest(proto.Message): r"""Request message for DisableService method. - Attributes: service_name (str): Required. Name of the service to disable. @@ -439,18 +406,16 @@ class DisableServiceRequest(proto.Message): google.api.servicecontrol.v1.Operation.consumer_id. """ - service_name = proto.Field(proto.STRING, number=1) - - consumer_id = proto.Field(proto.STRING, number=2) + service_name = proto.Field(proto.STRING, number=1,) + consumer_id = proto.Field(proto.STRING, number=2,) class DisableServiceResponse(proto.Message): - r"""Operation payload for DisableService method.""" + r"""Operation payload for DisableService method. """ class GenerateConfigReportRequest(proto.Message): r"""Request message for GenerateConfigReport method. - Attributes: new_config (google.protobuf.any_pb2.Any): Required. Service configuration for which we want to @@ -468,14 +433,12 @@ class GenerateConfigReportRequest(proto.Message): and [google.api.Service][google.api.Service] """ - new_config = proto.Field(proto.MESSAGE, number=1, message=gp_any.Any,) - - old_config = proto.Field(proto.MESSAGE, number=2, message=gp_any.Any,) + new_config = proto.Field(proto.MESSAGE, number=1, message=any_pb2.Any,) + old_config = proto.Field(proto.MESSAGE, number=2, message=any_pb2.Any,) class GenerateConfigReportResponse(proto.Message): r"""Response message for GenerateConfigReport method. - Attributes: service_name (str): Name of the service this report belongs to. @@ -491,14 +454,11 @@ class GenerateConfigReportResponse(proto.Message): belongs to. """ - service_name = proto.Field(proto.STRING, number=1) - - id = proto.Field(proto.STRING, number=2) - + service_name = proto.Field(proto.STRING, number=1,) + id = proto.Field(proto.STRING, number=2,) change_reports = proto.RepeatedField( proto.MESSAGE, number=3, message=resources.ChangeReport, ) - diagnostics = proto.RepeatedField( proto.MESSAGE, number=4, message=resources.Diagnostic, ) diff --git a/noxfile.py b/noxfile.py index 15d75d3..1d45cad 100644 --- a/noxfile.py +++ b/noxfile.py @@ -18,6 +18,7 @@ from __future__ import absolute_import import os +import pathlib import shutil import nox @@ -30,6 +31,8 @@ SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + # 'docfx' is excluded since it only needs to run in 'docs-presubmit' nox.options.sessions = [ "unit", @@ -59,16 +62,9 @@ def lint(session): session.run("flake8", "google", "tests") -@nox.session(python="3.6") +@nox.session(python=DEFAULT_PYTHON_VERSION) def blacken(session): - """Run black. - - Format code to uniform standard. - - This currently uses Python 3.6 due to the automated Kokoro run of synthtool. - That run uses an image that doesn't have 3.6 installed. Before updating this - check the state of the `gcp_ubuntu_config` we use for that Kokoro run. - """ + """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) session.run( "black", *BLACK_PATHS, @@ -84,13 +80,15 @@ def lint_setup_py(session): def default(session): # Install all test dependencies, then install this package in-place. - session.install("asyncmock", "pytest-asyncio") - session.install( - "mock", "pytest", "pytest-cov", + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) + session.install("asyncmock", "pytest-asyncio", "-c", constraints_path) - session.install("-e", ".") + session.install("mock", "pytest", "pytest-cov", "-c", constraints_path) + + session.install("-e", ".", "-c", constraints_path) # Run py.test against the unit tests. session.run( @@ -117,15 +115,15 @@ def unit(session): @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) system_test_path = os.path.join("tests", "system.py") system_test_folder_path = os.path.join("tests", "system") # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": session.skip("RUN_SYSTEM_TESTS is set to false, skipping") - # Sanity check: Only run tests if the environment variable is set. - if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): - session.skip("Credentials must be set via environment variable") # Install pyopenssl for mTLS testing. if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": session.install("pyopenssl") @@ -141,10 +139,8 @@ def system(session): # Install all test dependencies, then install this package into the # virtualenv's dist-packages. - session.install( - "mock", "pytest", "google-cloud-testutils", - ) - session.install("-e", ".") + session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) + session.install("-e", ".", "-c", constraints_path) # Run py.test against the system tests. if system_test_exists: diff --git a/synth.py b/owlbot.py similarity index 67% rename from synth.py rename to owlbot.py index b9dfb72..99199e5 100644 --- a/synth.py +++ b/owlbot.py @@ -20,26 +20,15 @@ import synthtool.gcp as gcp from synthtool.languages import python -gapic = gcp.GAPICBazel() common = gcp.CommonTemplates() -versions = [ - "v1", - -] # add new versions at the end of the list - -# ---------------------------------------------------------------------------- -# Generate servicemanagement GAPIC layer -# ---------------------------------------------------------------------------- -for version in versions: - library = gapic.py_library( - service="servicemanagement", - version=version, - bazel_target=f"//google/api/servicemanagement/{version}:google-cloud-servicemanagement-{version}-py", - ) +default_version = "v1" +for library in s.get_staging_dirs(default_version): s.move(library, excludes=["setup.py", "README.rst", "docs/index.rst"]) +s.remove_staging_dirs() + # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- @@ -52,4 +41,4 @@ templated_files, excludes=excludes ) -s.shell.run(["nox", "-s", "blacken"], hide_output=False) +s.shell.run(["nox", "-s", "blacken"], hide_output=False) \ No newline at end of file diff --git a/renovate.json b/renovate.json index f08bc22..c048955 100644 --- a/renovate.json +++ b/renovate.json @@ -2,5 +2,8 @@ "extends": [ "config:base", ":preserveSemverRanges" ], - "ignorePaths": [".pre-commit-config.yaml"] + "ignorePaths": [".pre-commit-config.yaml"], + "pip_requirements": { + "fileMatch": ["requirements-test.txt", "samples/[\\S/]*constraints.txt", "samples/[\\S/]*constraints-test.txt"] + } } diff --git a/scripts/fixup_servicemanagement_v1_keywords.py b/scripts/fixup_servicemanagement_v1_keywords.py index 6f515e7..1ac6d2a 100644 --- a/scripts/fixup_servicemanagement_v1_keywords.py +++ b/scripts/fixup_servicemanagement_v1_keywords.py @@ -1,6 +1,5 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import argparse import os import libcst as cst @@ -41,22 +39,21 @@ def partition( class servicemanagementCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_service': ('service', ), - 'create_service_config': ('service_name', 'service_config', ), - 'create_service_rollout': ('service_name', 'rollout', ), - 'delete_service': ('service_name', ), - 'disable_service': ('service_name', 'consumer_id', ), - 'enable_service': ('service_name', 'consumer_id', ), - 'generate_config_report': ('new_config', 'old_config', ), - 'get_service': ('service_name', ), - 'get_service_config': ('service_name', 'config_id', 'view', ), - 'get_service_rollout': ('service_name', 'rollout_id', ), - 'list_service_configs': ('service_name', 'page_token', 'page_size', ), - 'list_service_rollouts': ('service_name', 'filter', 'page_token', 'page_size', ), - 'list_services': ('producer_project_id', 'page_size', 'page_token', 'consumer_id', ), - 'submit_config_source': ('service_name', 'config_source', 'validate_only', ), - 'undelete_service': ('service_name', ), - + 'create_service': ('service', ), + 'create_service_config': ('service_name', 'service_config', ), + 'create_service_rollout': ('service_name', 'rollout', ), + 'delete_service': ('service_name', ), + 'disable_service': ('service_name', 'consumer_id', ), + 'enable_service': ('service_name', 'consumer_id', ), + 'generate_config_report': ('new_config', 'old_config', ), + 'get_service': ('service_name', ), + 'get_service_config': ('service_name', 'config_id', 'view', ), + 'get_service_rollout': ('service_name', 'rollout_id', ), + 'list_service_configs': ('service_name', 'page_token', 'page_size', ), + 'list_service_rollouts': ('service_name', 'filter', 'page_token', 'page_size', ), + 'list_services': ('producer_project_id', 'page_size', 'page_token', 'consumer_id', ), + 'submit_config_source': ('service_name', 'config_source', 'validate_only', ), + 'undelete_service': ('service_name', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -87,7 +84,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: value=cst.Dict([ cst.DictElement( cst.SimpleString("'{}'".format(name)), - cst.Element(value=arg.value) +cst.Element(value=arg.value) ) # Note: the args + kwargs looks silly, but keep in mind that # the control parameters had to be stripped out, and that diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +# -*- 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. +# diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,15 @@ +# -*- 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. +# diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/__init__.py @@ -0,0 +1,15 @@ +# -*- 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. +# diff --git a/tests/unit/gapic/servicemanagement_v1/__init__.py b/tests/unit/gapic/servicemanagement_v1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/servicemanagement_v1/__init__.py +++ b/tests/unit/gapic/servicemanagement_v1/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/unit/gapic/servicemanagement_v1/test_service_manager.py b/tests/unit/gapic/servicemanagement_v1/test_service_manager.py index 3e01b6f..470a813 100644 --- a/tests/unit/gapic/servicemanagement_v1/test_service_manager.py +++ b/tests/unit/gapic/servicemanagement_v1/test_service_manager.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import os import mock +import packaging.version import grpc from grpc.experimental import aio @@ -24,36 +23,36 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth -from google.api import auth_pb2 as ga_auth # type: ignore -from google.api import backend_pb2 as backend # type: ignore -from google.api import billing_pb2 as billing # type: ignore -from google.api import context_pb2 as context # type: ignore -from google.api import control_pb2 as control # type: ignore -from google.api import documentation_pb2 as documentation # type: ignore -from google.api import endpoint_pb2 as endpoint # type: ignore -from google.api import http_pb2 as http # type: ignore -from google.api import label_pb2 as label # type: ignore -from google.api import launch_stage_pb2 as launch_stage # type: ignore -from google.api import log_pb2 as log # type: ignore -from google.api import logging_pb2 as logging # type: ignore -from google.api import metric_pb2 as metric # type: ignore -from google.api import monitored_resource_pb2 as monitored_resource # type: ignore -from google.api import monitoring_pb2 as monitoring # type: ignore -from google.api import quota_pb2 as quota # type: ignore -from google.api import service_pb2 as service # type: ignore -from google.api import source_info_pb2 as source_info # type: ignore -from google.api import system_parameter_pb2 as system_parameter # type: ignore -from google.api import usage_pb2 as usage # type: ignore + +from google.api import auth_pb2 # type: ignore +from google.api import backend_pb2 # type: ignore +from google.api import billing_pb2 # type: ignore +from google.api import context_pb2 # type: ignore +from google.api import control_pb2 # type: ignore +from google.api import documentation_pb2 # type: ignore +from google.api import endpoint_pb2 # type: ignore +from google.api import http_pb2 # type: ignore +from google.api import label_pb2 # type: ignore +from google.api import launch_stage_pb2 # type: ignore +from google.api import log_pb2 # type: ignore +from google.api import logging_pb2 # type: ignore +from google.api import metric_pb2 # type: ignore +from google.api import monitored_resource_pb2 # type: ignore +from google.api import monitoring_pb2 # type: ignore +from google.api import quota_pb2 # type: ignore +from google.api import service_pb2 # type: ignore +from google.api import source_info_pb2 # type: ignore +from google.api import system_parameter_pb2 # type: ignore +from google.api import usage_pb2 # type: ignore from google.api_core import client_options -from google.api_core import exceptions +from google.api_core import exceptions as core_exceptions from google.api_core import future from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 -from google.auth import credentials +from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.servicemanagement_v1.services.service_manager import ( ServiceManagerAsyncClient, @@ -63,17 +62,47 @@ ) from google.cloud.servicemanagement_v1.services.service_manager import pagers from google.cloud.servicemanagement_v1.services.service_manager import transports +from google.cloud.servicemanagement_v1.services.service_manager.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.servicemanagement_v1.services.service_manager.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.servicemanagement_v1.types import resources from google.cloud.servicemanagement_v1.types import servicemanager from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import any_pb2 as gp_any # type: ignore -from google.protobuf import api_pb2 as api # type: ignore -from google.protobuf import duration_pb2 as duration # type: ignore -from google.protobuf import source_context_pb2 as source_context # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore -from google.protobuf import type_pb2 as gp_type # type: ignore -from google.protobuf import wrappers_pb2 as wrappers # type: ignore +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import api_pb2 # type: ignore +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import source_context_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.protobuf import type_pb2 # type: ignore +from google.protobuf import wrappers_pb2 # type: ignore +import google.auth + + +# TODO(busunkim): Once google-api-core >= 1.26.0 is required: +# - Delete all the api-core and auth "less than" test cases +# - Delete these pytest markers (Make the "greater than or equal to" tests the default). +requires_google_auth_lt_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), + reason="This test requires google-auth < 1.25.0", +) +requires_google_auth_gte_1_25_0 = pytest.mark.skipif( + packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), + reason="This test requires google-auth >= 1.25.0", +) + +requires_api_core_lt_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), + reason="This test requires google-api-core < 1.26.0", +) + +requires_api_core_gte_1_26_0 = pytest.mark.skipif( + packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), + reason="This test requires google-api-core >= 1.26.0", +) def client_cert_source_callback(): @@ -124,7 +153,7 @@ def test__get_default_mtls_endpoint(): "client_class", [ServiceManagerClient, ServiceManagerAsyncClient,] ) def test_service_manager_client_from_service_account_info(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -141,7 +170,7 @@ def test_service_manager_client_from_service_account_info(client_class): "client_class", [ServiceManagerClient, ServiceManagerAsyncClient,] ) def test_service_manager_client_from_service_account_file(client_class): - creds = credentials.AnonymousCredentials() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -194,7 +223,7 @@ def test_service_manager_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ServiceManagerClient, "get_transport_class") as gtc: - transport = transport_class(credentials=credentials.AnonymousCredentials()) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -482,7 +511,7 @@ def test_list_services( transport: str = "grpc", request_type=servicemanager.ListServicesRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -495,19 +524,15 @@ def test_list_services( call.return_value = servicemanager.ListServicesResponse( next_page_token="next_page_token_value", ) - response = client.list_services(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServicesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListServicesPager) - assert response.next_page_token == "next_page_token_value" @@ -519,7 +544,7 @@ def test_list_services_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -527,7 +552,6 @@ def test_list_services_empty_call(): client.list_services() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServicesRequest() @@ -536,7 +560,7 @@ async def test_list_services_async( transport: str = "grpc_asyncio", request_type=servicemanager.ListServicesRequest ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -551,18 +575,15 @@ async def test_list_services_async( next_page_token="next_page_token_value", ) ) - response = await client.list_services(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServicesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListServicesAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -572,13 +593,12 @@ async def test_list_services_async_from_dict(): def test_list_services_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_services), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = servicemanager.ListServicesResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_services( @@ -590,14 +610,12 @@ def test_list_services_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].producer_project_id == "producer_project_id_value" - assert args[0].consumer_id == "consumer_id_value" def test_list_services_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -611,7 +629,9 @@ def test_list_services_flattened_error(): @pytest.mark.asyncio async def test_list_services_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_services), "__call__") as call: @@ -632,15 +652,15 @@ async def test_list_services_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].producer_project_id == "producer_project_id_value" - assert args[0].consumer_id == "consumer_id_value" @pytest.mark.asyncio async def test_list_services_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -653,7 +673,7 @@ async def test_list_services_flattened_error_async(): def test_list_services_pager(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_services), "__call__") as call: @@ -688,7 +708,7 @@ def test_list_services_pager(): def test_list_services_pages(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_services), "__call__") as call: @@ -718,7 +738,7 @@ def test_list_services_pages(): @pytest.mark.asyncio async def test_list_services_async_pager(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -755,7 +775,7 @@ async def test_list_services_async_pager(): @pytest.mark.asyncio async def test_list_services_async_pages(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -791,7 +811,7 @@ def test_get_service( transport: str = "grpc", request_type=servicemanager.GetServiceRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -805,21 +825,16 @@ def test_get_service( service_name="service_name_value", producer_project_id="producer_project_id_value", ) - response = client.get_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.ManagedService) - assert response.service_name == "service_name_value" - assert response.producer_project_id == "producer_project_id_value" @@ -831,7 +846,7 @@ def test_get_service_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -839,7 +854,6 @@ def test_get_service_empty_call(): client.get_service() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceRequest() @@ -848,7 +862,7 @@ async def test_get_service_async( transport: str = "grpc_asyncio", request_type=servicemanager.GetServiceRequest ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -864,20 +878,16 @@ async def test_get_service_async( producer_project_id="producer_project_id_value", ) ) - response = await client.get_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.ManagedService) - assert response.service_name == "service_name_value" - assert response.producer_project_id == "producer_project_id_value" @@ -887,13 +897,12 @@ async def test_get_service_async_from_dict(): def test_get_service_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = resources.ManagedService() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_service(service_name="service_name_value",) @@ -902,12 +911,11 @@ def test_get_service_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" def test_get_service_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -919,7 +927,9 @@ def test_get_service_flattened_error(): @pytest.mark.asyncio async def test_get_service_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_service), "__call__") as call: @@ -937,13 +947,14 @@ async def test_get_service_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" @pytest.mark.asyncio async def test_get_service_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -957,7 +968,7 @@ def test_create_service( transport: str = "grpc", request_type=servicemanager.CreateServiceRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -968,13 +979,11 @@ def test_create_service( with mock.patch.object(type(client.transport.create_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceRequest() # Establish that the response is the type that we expect. @@ -989,7 +998,7 @@ def test_create_service_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -997,7 +1006,6 @@ def test_create_service_empty_call(): client.create_service() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceRequest() @@ -1006,7 +1014,7 @@ async def test_create_service_async( transport: str = "grpc_asyncio", request_type=servicemanager.CreateServiceRequest ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1019,13 +1027,11 @@ async def test_create_service_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceRequest() # Establish that the response is the type that we expect. @@ -1038,13 +1044,12 @@ async def test_create_service_async_from_dict(): def test_create_service_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_service( @@ -1055,14 +1060,13 @@ def test_create_service_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service == resources.ManagedService( service_name="service_name_value" ) def test_create_service_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1075,7 +1079,9 @@ def test_create_service_flattened_error(): @pytest.mark.asyncio async def test_create_service_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_service), "__call__") as call: @@ -1095,7 +1101,6 @@ async def test_create_service_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service == resources.ManagedService( service_name="service_name_value" ) @@ -1103,7 +1108,9 @@ async def test_create_service_flattened_async(): @pytest.mark.asyncio async def test_create_service_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1118,7 +1125,7 @@ def test_delete_service( transport: str = "grpc", request_type=servicemanager.DeleteServiceRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1129,13 +1136,11 @@ def test_delete_service( with mock.patch.object(type(client.transport.delete_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.DeleteServiceRequest() # Establish that the response is the type that we expect. @@ -1150,7 +1155,7 @@ def test_delete_service_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1158,7 +1163,6 @@ def test_delete_service_empty_call(): client.delete_service() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.DeleteServiceRequest() @@ -1167,7 +1171,7 @@ async def test_delete_service_async( transport: str = "grpc_asyncio", request_type=servicemanager.DeleteServiceRequest ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1180,13 +1184,11 @@ async def test_delete_service_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.DeleteServiceRequest() # Establish that the response is the type that we expect. @@ -1199,13 +1201,12 @@ async def test_delete_service_async_from_dict(): def test_delete_service_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_service(service_name="service_name_value",) @@ -1214,12 +1215,11 @@ def test_delete_service_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" def test_delete_service_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1231,7 +1231,9 @@ def test_delete_service_flattened_error(): @pytest.mark.asyncio async def test_delete_service_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_service), "__call__") as call: @@ -1249,13 +1251,14 @@ async def test_delete_service_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" @pytest.mark.asyncio async def test_delete_service_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1269,7 +1272,7 @@ def test_undelete_service( transport: str = "grpc", request_type=servicemanager.UndeleteServiceRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1280,13 +1283,11 @@ def test_undelete_service( with mock.patch.object(type(client.transport.undelete_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.undelete_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.UndeleteServiceRequest() # Establish that the response is the type that we expect. @@ -1301,7 +1302,7 @@ def test_undelete_service_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1309,7 +1310,6 @@ def test_undelete_service_empty_call(): client.undelete_service() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.UndeleteServiceRequest() @@ -1318,7 +1318,7 @@ async def test_undelete_service_async( transport: str = "grpc_asyncio", request_type=servicemanager.UndeleteServiceRequest ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1331,13 +1331,11 @@ async def test_undelete_service_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.undelete_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.UndeleteServiceRequest() # Establish that the response is the type that we expect. @@ -1350,13 +1348,12 @@ async def test_undelete_service_async_from_dict(): def test_undelete_service_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undelete_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.undelete_service(service_name="service_name_value",) @@ -1365,12 +1362,11 @@ def test_undelete_service_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" def test_undelete_service_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1382,7 +1378,9 @@ def test_undelete_service_flattened_error(): @pytest.mark.asyncio async def test_undelete_service_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undelete_service), "__call__") as call: @@ -1400,13 +1398,14 @@ async def test_undelete_service_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" @pytest.mark.asyncio async def test_undelete_service_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1420,7 +1419,7 @@ def test_list_service_configs( transport: str = "grpc", request_type=servicemanager.ListServiceConfigsRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1435,19 +1434,15 @@ def test_list_service_configs( call.return_value = servicemanager.ListServiceConfigsResponse( next_page_token="next_page_token_value", ) - response = client.list_service_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServiceConfigsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListServiceConfigsPager) - assert response.next_page_token == "next_page_token_value" @@ -1459,7 +1454,7 @@ def test_list_service_configs_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1469,7 +1464,6 @@ def test_list_service_configs_empty_call(): client.list_service_configs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServiceConfigsRequest() @@ -1479,7 +1473,7 @@ async def test_list_service_configs_async( request_type=servicemanager.ListServiceConfigsRequest, ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1496,18 +1490,15 @@ async def test_list_service_configs_async( next_page_token="next_page_token_value", ) ) - response = await client.list_service_configs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServiceConfigsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListServiceConfigsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -1517,7 +1508,7 @@ async def test_list_service_configs_async_from_dict(): def test_list_service_configs_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1525,7 +1516,6 @@ def test_list_service_configs_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = servicemanager.ListServiceConfigsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_service_configs(service_name="service_name_value",) @@ -1534,12 +1524,11 @@ def test_list_service_configs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" def test_list_service_configs_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1552,7 +1541,9 @@ def test_list_service_configs_flattened_error(): @pytest.mark.asyncio async def test_list_service_configs_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1572,13 +1563,14 @@ async def test_list_service_configs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" @pytest.mark.asyncio async def test_list_service_configs_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1590,7 +1582,7 @@ async def test_list_service_configs_flattened_error_async(): def test_list_service_configs_pager(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1600,9 +1592,9 @@ def test_list_service_configs_pager(): call.side_effect = ( servicemanager.ListServiceConfigsResponse( service_configs=[ - service.Service(), - service.Service(), - service.Service(), + service_pb2.Service(), + service_pb2.Service(), + service_pb2.Service(), ], next_page_token="abc", ), @@ -1610,10 +1602,10 @@ def test_list_service_configs_pager(): service_configs=[], next_page_token="def", ), servicemanager.ListServiceConfigsResponse( - service_configs=[service.Service(),], next_page_token="ghi", + service_configs=[service_pb2.Service(),], next_page_token="ghi", ), servicemanager.ListServiceConfigsResponse( - service_configs=[service.Service(), service.Service(),], + service_configs=[service_pb2.Service(), service_pb2.Service(),], ), RuntimeError, ) @@ -1625,11 +1617,11 @@ def test_list_service_configs_pager(): results = [i for i in pager] assert len(results) == 6 - assert all(isinstance(i, service.Service) for i in results) + assert all(isinstance(i, service_pb2.Service) for i in results) def test_list_service_configs_pages(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1639,9 +1631,9 @@ def test_list_service_configs_pages(): call.side_effect = ( servicemanager.ListServiceConfigsResponse( service_configs=[ - service.Service(), - service.Service(), - service.Service(), + service_pb2.Service(), + service_pb2.Service(), + service_pb2.Service(), ], next_page_token="abc", ), @@ -1649,10 +1641,10 @@ def test_list_service_configs_pages(): service_configs=[], next_page_token="def", ), servicemanager.ListServiceConfigsResponse( - service_configs=[service.Service(),], next_page_token="ghi", + service_configs=[service_pb2.Service(),], next_page_token="ghi", ), servicemanager.ListServiceConfigsResponse( - service_configs=[service.Service(), service.Service(),], + service_configs=[service_pb2.Service(), service_pb2.Service(),], ), RuntimeError, ) @@ -1663,7 +1655,7 @@ def test_list_service_configs_pages(): @pytest.mark.asyncio async def test_list_service_configs_async_pager(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1675,9 +1667,9 @@ async def test_list_service_configs_async_pager(): call.side_effect = ( servicemanager.ListServiceConfigsResponse( service_configs=[ - service.Service(), - service.Service(), - service.Service(), + service_pb2.Service(), + service_pb2.Service(), + service_pb2.Service(), ], next_page_token="abc", ), @@ -1685,10 +1677,10 @@ async def test_list_service_configs_async_pager(): service_configs=[], next_page_token="def", ), servicemanager.ListServiceConfigsResponse( - service_configs=[service.Service(),], next_page_token="ghi", + service_configs=[service_pb2.Service(),], next_page_token="ghi", ), servicemanager.ListServiceConfigsResponse( - service_configs=[service.Service(), service.Service(),], + service_configs=[service_pb2.Service(), service_pb2.Service(),], ), RuntimeError, ) @@ -1699,12 +1691,12 @@ async def test_list_service_configs_async_pager(): responses.append(response) assert len(responses) == 6 - assert all(isinstance(i, service.Service) for i in responses) + assert all(isinstance(i, service_pb2.Service) for i in responses) @pytest.mark.asyncio async def test_list_service_configs_async_pages(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1716,9 +1708,9 @@ async def test_list_service_configs_async_pages(): call.side_effect = ( servicemanager.ListServiceConfigsResponse( service_configs=[ - service.Service(), - service.Service(), - service.Service(), + service_pb2.Service(), + service_pb2.Service(), + service_pb2.Service(), ], next_page_token="abc", ), @@ -1726,10 +1718,10 @@ async def test_list_service_configs_async_pages(): service_configs=[], next_page_token="def", ), servicemanager.ListServiceConfigsResponse( - service_configs=[service.Service(),], next_page_token="ghi", + service_configs=[service_pb2.Service(),], next_page_token="ghi", ), servicemanager.ListServiceConfigsResponse( - service_configs=[service.Service(), service.Service(),], + service_configs=[service_pb2.Service(), service_pb2.Service(),], ), RuntimeError, ) @@ -1744,7 +1736,7 @@ def test_get_service_config( transport: str = "grpc", request_type=servicemanager.GetServiceConfigRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1756,31 +1748,24 @@ def test_get_service_config( type(client.transport.get_service_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.Service( + call.return_value = service_pb2.Service( name="name_value", title="title_value", producer_project_id="producer_project_id_value", id="id_value", ) - response = client.get_service_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceConfigRequest() # Establish that the response is the type that we expect. - - assert isinstance(response, service.Service) - + assert isinstance(response, service_pb2.Service) assert response.name == "name_value" - assert response.title == "title_value" - assert response.producer_project_id == "producer_project_id_value" - assert response.id == "id_value" @@ -1792,7 +1777,7 @@ def test_get_service_config_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1802,7 +1787,6 @@ def test_get_service_config_empty_call(): client.get_service_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceConfigRequest() @@ -1811,7 +1795,7 @@ async def test_get_service_config_async( transport: str = "grpc_asyncio", request_type=servicemanager.GetServiceConfigRequest ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1824,31 +1808,25 @@ async def test_get_service_config_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.Service( + service_pb2.Service( name="name_value", title="title_value", producer_project_id="producer_project_id_value", id="id_value", ) ) - response = await client.get_service_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, service.Service) - + assert isinstance(response, service_pb2.Service) assert response.name == "name_value" - assert response.title == "title_value" - assert response.producer_project_id == "producer_project_id_value" - assert response.id == "id_value" @@ -1858,15 +1836,14 @@ async def test_get_service_config_async_from_dict(): def test_get_service_config_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.get_service_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.Service() - + call.return_value = service_pb2.Service() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_service_config( @@ -1879,16 +1856,13 @@ def test_get_service_config_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].config_id == "config_id_value" - assert args[0].view == servicemanager.GetServiceConfigRequest.ConfigView.FULL def test_get_service_config_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1903,16 +1877,18 @@ def test_get_service_config_flattened_error(): @pytest.mark.asyncio async def test_get_service_config_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.get_service_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.Service() + call.return_value = service_pb2.Service() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(service.Service()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(service_pb2.Service()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.get_service_config( @@ -1925,17 +1901,16 @@ async def test_get_service_config_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].config_id == "config_id_value" - assert args[0].view == servicemanager.GetServiceConfigRequest.ConfigView.FULL @pytest.mark.asyncio async def test_get_service_config_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1952,7 +1927,7 @@ def test_create_service_config( transport: str = "grpc", request_type=servicemanager.CreateServiceConfigRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1964,31 +1939,24 @@ def test_create_service_config( type(client.transport.create_service_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.Service( + call.return_value = service_pb2.Service( name="name_value", title="title_value", producer_project_id="producer_project_id_value", id="id_value", ) - response = client.create_service_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceConfigRequest() # Establish that the response is the type that we expect. - - assert isinstance(response, service.Service) - + assert isinstance(response, service_pb2.Service) assert response.name == "name_value" - assert response.title == "title_value" - assert response.producer_project_id == "producer_project_id_value" - assert response.id == "id_value" @@ -2000,7 +1968,7 @@ def test_create_service_config_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2010,7 +1978,6 @@ def test_create_service_config_empty_call(): client.create_service_config() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceConfigRequest() @@ -2020,7 +1987,7 @@ async def test_create_service_config_async( request_type=servicemanager.CreateServiceConfigRequest, ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2033,31 +2000,25 @@ async def test_create_service_config_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.Service( + service_pb2.Service( name="name_value", title="title_value", producer_project_id="producer_project_id_value", id="id_value", ) ) - response = await client.create_service_config(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceConfigRequest() # Establish that the response is the type that we expect. - assert isinstance(response, service.Service) - + assert isinstance(response, service_pb2.Service) assert response.name == "name_value" - assert response.title == "title_value" - assert response.producer_project_id == "producer_project_id_value" - assert response.id == "id_value" @@ -2067,34 +2028,31 @@ async def test_create_service_config_async_from_dict(): def test_create_service_config_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.create_service_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.Service() - + call.return_value = service_pb2.Service() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_service_config( service_name="service_name_value", - service_config=service.Service(name="name_value"), + service_config=service_pb2.Service(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - - assert args[0].service_config == service.Service(name="name_value") + assert args[0].service_config == service_pb2.Service(name="name_value") def test_create_service_config_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2102,42 +2060,44 @@ def test_create_service_config_flattened_error(): client.create_service_config( servicemanager.CreateServiceConfigRequest(), service_name="service_name_value", - service_config=service.Service(name="name_value"), + service_config=service_pb2.Service(name="name_value"), ) @pytest.mark.asyncio async def test_create_service_config_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.create_service_config), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = service.Service() + call.return_value = service_pb2.Service() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(service.Service()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(service_pb2.Service()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_service_config( service_name="service_name_value", - service_config=service.Service(name="name_value"), + service_config=service_pb2.Service(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - - assert args[0].service_config == service.Service(name="name_value") + assert args[0].service_config == service_pb2.Service(name="name_value") @pytest.mark.asyncio async def test_create_service_config_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2145,7 +2105,7 @@ async def test_create_service_config_flattened_error_async(): await client.create_service_config( servicemanager.CreateServiceConfigRequest(), service_name="service_name_value", - service_config=service.Service(name="name_value"), + service_config=service_pb2.Service(name="name_value"), ) @@ -2153,7 +2113,7 @@ def test_submit_config_source( transport: str = "grpc", request_type=servicemanager.SubmitConfigSourceRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2166,13 +2126,11 @@ def test_submit_config_source( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.submit_config_source(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.SubmitConfigSourceRequest() # Establish that the response is the type that we expect. @@ -2187,7 +2145,7 @@ def test_submit_config_source_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2197,7 +2155,6 @@ def test_submit_config_source_empty_call(): client.submit_config_source() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.SubmitConfigSourceRequest() @@ -2207,7 +2164,7 @@ async def test_submit_config_source_async( request_type=servicemanager.SubmitConfigSourceRequest, ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2222,13 +2179,11 @@ async def test_submit_config_source_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.submit_config_source(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.SubmitConfigSourceRequest() # Establish that the response is the type that we expect. @@ -2241,7 +2196,7 @@ async def test_submit_config_source_async_from_dict(): def test_submit_config_source_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2249,7 +2204,6 @@ def test_submit_config_source_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.submit_config_source( @@ -2262,16 +2216,13 @@ def test_submit_config_source_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].config_source == resources.ConfigSource(id="id_value") - assert args[0].validate_only == True def test_submit_config_source_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2286,7 +2237,9 @@ def test_submit_config_source_flattened_error(): @pytest.mark.asyncio async def test_submit_config_source_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2310,17 +2263,16 @@ async def test_submit_config_source_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].config_source == resources.ConfigSource(id="id_value") - assert args[0].validate_only == True @pytest.mark.asyncio async def test_submit_config_source_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2337,7 +2289,7 @@ def test_list_service_rollouts( transport: str = "grpc", request_type=servicemanager.ListServiceRolloutsRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2352,19 +2304,15 @@ def test_list_service_rollouts( call.return_value = servicemanager.ListServiceRolloutsResponse( next_page_token="next_page_token_value", ) - response = client.list_service_rollouts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServiceRolloutsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListServiceRolloutsPager) - assert response.next_page_token == "next_page_token_value" @@ -2376,7 +2324,7 @@ def test_list_service_rollouts_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2386,7 +2334,6 @@ def test_list_service_rollouts_empty_call(): client.list_service_rollouts() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServiceRolloutsRequest() @@ -2396,7 +2343,7 @@ async def test_list_service_rollouts_async( request_type=servicemanager.ListServiceRolloutsRequest, ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2413,18 +2360,15 @@ async def test_list_service_rollouts_async( next_page_token="next_page_token_value", ) ) - response = await client.list_service_rollouts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.ListServiceRolloutsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListServiceRolloutsAsyncPager) - assert response.next_page_token == "next_page_token_value" @@ -2434,7 +2378,7 @@ async def test_list_service_rollouts_async_from_dict(): def test_list_service_rollouts_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2442,7 +2386,6 @@ def test_list_service_rollouts_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = servicemanager.ListServiceRolloutsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_service_rollouts( @@ -2453,14 +2396,12 @@ def test_list_service_rollouts_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].filter == "filter_value" def test_list_service_rollouts_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2474,7 +2415,9 @@ def test_list_service_rollouts_flattened_error(): @pytest.mark.asyncio async def test_list_service_rollouts_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2496,15 +2439,15 @@ async def test_list_service_rollouts_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].filter == "filter_value" @pytest.mark.asyncio async def test_list_service_rollouts_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2517,7 +2460,7 @@ async def test_list_service_rollouts_flattened_error_async(): def test_list_service_rollouts_pager(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2556,7 +2499,7 @@ def test_list_service_rollouts_pager(): def test_list_service_rollouts_pages(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2590,7 +2533,7 @@ def test_list_service_rollouts_pages(): @pytest.mark.asyncio async def test_list_service_rollouts_async_pager(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2631,7 +2574,7 @@ async def test_list_service_rollouts_async_pager(): @pytest.mark.asyncio async def test_list_service_rollouts_async_pages(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials,) + client = ServiceManagerAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2671,7 +2614,7 @@ def test_get_service_rollout( transport: str = "grpc", request_type=servicemanager.GetServiceRolloutRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2692,25 +2635,18 @@ def test_get_service_rollout( percentages={"key_value": 0.541} ), ) - response = client.get_service_rollout(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceRolloutRequest() # Establish that the response is the type that we expect. - assert isinstance(response, resources.Rollout) - assert response.rollout_id == "rollout_id_value" - assert response.created_by == "created_by_value" - assert response.status == resources.Rollout.RolloutStatus.IN_PROGRESS - assert response.service_name == "service_name_value" @@ -2722,7 +2658,7 @@ def test_get_service_rollout_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2732,7 +2668,6 @@ def test_get_service_rollout_empty_call(): client.get_service_rollout() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceRolloutRequest() @@ -2742,7 +2677,7 @@ async def test_get_service_rollout_async( request_type=servicemanager.GetServiceRolloutRequest, ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2762,24 +2697,18 @@ async def test_get_service_rollout_async( service_name="service_name_value", ) ) - response = await client.get_service_rollout(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GetServiceRolloutRequest() # Establish that the response is the type that we expect. assert isinstance(response, resources.Rollout) - assert response.rollout_id == "rollout_id_value" - assert response.created_by == "created_by_value" - assert response.status == resources.Rollout.RolloutStatus.IN_PROGRESS - assert response.service_name == "service_name_value" @@ -2789,7 +2718,7 @@ async def test_get_service_rollout_async_from_dict(): def test_get_service_rollout_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2797,7 +2726,6 @@ def test_get_service_rollout_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = resources.Rollout() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_service_rollout( @@ -2808,14 +2736,12 @@ def test_get_service_rollout_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].rollout_id == "rollout_id_value" def test_get_service_rollout_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2829,7 +2755,9 @@ def test_get_service_rollout_flattened_error(): @pytest.mark.asyncio async def test_get_service_rollout_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2849,15 +2777,15 @@ async def test_get_service_rollout_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].rollout_id == "rollout_id_value" @pytest.mark.asyncio async def test_get_service_rollout_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2873,7 +2801,7 @@ def test_create_service_rollout( transport: str = "grpc", request_type=servicemanager.CreateServiceRolloutRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2886,13 +2814,11 @@ def test_create_service_rollout( ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_service_rollout(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceRolloutRequest() # Establish that the response is the type that we expect. @@ -2907,7 +2833,7 @@ def test_create_service_rollout_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2917,7 +2843,6 @@ def test_create_service_rollout_empty_call(): client.create_service_rollout() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceRolloutRequest() @@ -2927,7 +2852,7 @@ async def test_create_service_rollout_async( request_type=servicemanager.CreateServiceRolloutRequest, ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2942,13 +2867,11 @@ async def test_create_service_rollout_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_service_rollout(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.CreateServiceRolloutRequest() # Establish that the response is the type that we expect. @@ -2961,7 +2884,7 @@ async def test_create_service_rollout_async_from_dict(): def test_create_service_rollout_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2969,7 +2892,6 @@ def test_create_service_rollout_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_service_rollout( @@ -2981,14 +2903,12 @@ def test_create_service_rollout_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].rollout == resources.Rollout(rollout_id="rollout_id_value") def test_create_service_rollout_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3002,7 +2922,9 @@ def test_create_service_rollout_flattened_error(): @pytest.mark.asyncio async def test_create_service_rollout_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3025,15 +2947,15 @@ async def test_create_service_rollout_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].rollout == resources.Rollout(rollout_id="rollout_id_value") @pytest.mark.asyncio async def test_create_service_rollout_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3049,7 +2971,7 @@ def test_generate_config_report( transport: str = "grpc", request_type=servicemanager.GenerateConfigReportRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3064,21 +2986,16 @@ def test_generate_config_report( call.return_value = servicemanager.GenerateConfigReportResponse( service_name="service_name_value", id="id_value", ) - response = client.generate_config_report(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GenerateConfigReportRequest() # Establish that the response is the type that we expect. - assert isinstance(response, servicemanager.GenerateConfigReportResponse) - assert response.service_name == "service_name_value" - assert response.id == "id_value" @@ -3090,7 +3007,7 @@ def test_generate_config_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3100,7 +3017,6 @@ def test_generate_config_report_empty_call(): client.generate_config_report() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GenerateConfigReportRequest() @@ -3110,7 +3026,7 @@ async def test_generate_config_report_async( request_type=servicemanager.GenerateConfigReportRequest, ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3127,20 +3043,16 @@ async def test_generate_config_report_async( service_name="service_name_value", id="id_value", ) ) - response = await client.generate_config_report(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.GenerateConfigReportRequest() # Establish that the response is the type that we expect. assert isinstance(response, servicemanager.GenerateConfigReportResponse) - assert response.service_name == "service_name_value" - assert response.id == "id_value" @@ -3150,7 +3062,7 @@ async def test_generate_config_report_async_from_dict(): def test_generate_config_report_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3158,40 +3070,39 @@ def test_generate_config_report_flattened(): ) as call: # Designate an appropriate return value for the call. call.return_value = servicemanager.GenerateConfigReportResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.generate_config_report( - new_config=gp_any.Any(type_url="type_url_value"), - old_config=gp_any.Any(type_url="type_url_value"), + new_config=any_pb2.Any(type_url="type_url_value"), + old_config=any_pb2.Any(type_url="type_url_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - - assert args[0].new_config == gp_any.Any(type_url="type_url_value") - - assert args[0].old_config == gp_any.Any(type_url="type_url_value") + assert args[0].new_config == any_pb2.Any(type_url="type_url_value") + assert args[0].old_config == any_pb2.Any(type_url="type_url_value") def test_generate_config_report_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.generate_config_report( servicemanager.GenerateConfigReportRequest(), - new_config=gp_any.Any(type_url="type_url_value"), - old_config=gp_any.Any(type_url="type_url_value"), + new_config=any_pb2.Any(type_url="type_url_value"), + old_config=any_pb2.Any(type_url="type_url_value"), ) @pytest.mark.asyncio async def test_generate_config_report_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3206,31 +3117,31 @@ async def test_generate_config_report_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.generate_config_report( - new_config=gp_any.Any(type_url="type_url_value"), - old_config=gp_any.Any(type_url="type_url_value"), + new_config=any_pb2.Any(type_url="type_url_value"), + old_config=any_pb2.Any(type_url="type_url_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - - assert args[0].new_config == gp_any.Any(type_url="type_url_value") - - assert args[0].old_config == gp_any.Any(type_url="type_url_value") + assert args[0].new_config == any_pb2.Any(type_url="type_url_value") + assert args[0].old_config == any_pb2.Any(type_url="type_url_value") @pytest.mark.asyncio async def test_generate_config_report_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.generate_config_report( servicemanager.GenerateConfigReportRequest(), - new_config=gp_any.Any(type_url="type_url_value"), - old_config=gp_any.Any(type_url="type_url_value"), + new_config=any_pb2.Any(type_url="type_url_value"), + old_config=any_pb2.Any(type_url="type_url_value"), ) @@ -3238,7 +3149,7 @@ def test_enable_service( transport: str = "grpc", request_type=servicemanager.EnableServiceRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3249,13 +3160,11 @@ def test_enable_service( with mock.patch.object(type(client.transport.enable_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.enable_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.EnableServiceRequest() # Establish that the response is the type that we expect. @@ -3270,7 +3179,7 @@ def test_enable_service_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3278,7 +3187,6 @@ def test_enable_service_empty_call(): client.enable_service() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.EnableServiceRequest() @@ -3287,7 +3195,7 @@ async def test_enable_service_async( transport: str = "grpc_asyncio", request_type=servicemanager.EnableServiceRequest ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3300,13 +3208,11 @@ async def test_enable_service_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.enable_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.EnableServiceRequest() # Establish that the response is the type that we expect. @@ -3319,13 +3225,12 @@ async def test_enable_service_async_from_dict(): def test_enable_service_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.enable_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.enable_service( @@ -3336,14 +3241,12 @@ def test_enable_service_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].consumer_id == "consumer_id_value" def test_enable_service_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3357,7 +3260,9 @@ def test_enable_service_flattened_error(): @pytest.mark.asyncio async def test_enable_service_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.enable_service), "__call__") as call: @@ -3377,15 +3282,15 @@ async def test_enable_service_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].consumer_id == "consumer_id_value" @pytest.mark.asyncio async def test_enable_service_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3401,7 +3306,7 @@ def test_disable_service( transport: str = "grpc", request_type=servicemanager.DisableServiceRequest ): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3412,13 +3317,11 @@ def test_disable_service( with mock.patch.object(type(client.transport.disable_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.disable_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.DisableServiceRequest() # Establish that the response is the type that we expect. @@ -3433,7 +3336,7 @@ def test_disable_service_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. client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3441,7 +3344,6 @@ def test_disable_service_empty_call(): client.disable_service() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.DisableServiceRequest() @@ -3450,7 +3352,7 @@ async def test_disable_service_async( transport: str = "grpc_asyncio", request_type=servicemanager.DisableServiceRequest ): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3463,13 +3365,11 @@ async def test_disable_service_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.disable_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == servicemanager.DisableServiceRequest() # Establish that the response is the type that we expect. @@ -3482,13 +3382,12 @@ async def test_disable_service_async_from_dict(): def test_disable_service_flattened(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.disable_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.disable_service( @@ -3499,14 +3398,12 @@ def test_disable_service_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].consumer_id == "consumer_id_value" def test_disable_service_flattened_error(): - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3520,7 +3417,9 @@ def test_disable_service_flattened_error(): @pytest.mark.asyncio async def test_disable_service_flattened_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.disable_service), "__call__") as call: @@ -3540,15 +3439,15 @@ async def test_disable_service_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].service_name == "service_name_value" - assert args[0].consumer_id == "consumer_id_value" @pytest.mark.asyncio async def test_disable_service_flattened_error_async(): - client = ServiceManagerAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3563,16 +3462,16 @@ async def test_disable_service_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ServiceManagerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ServiceManagerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ServiceManagerClient( @@ -3582,7 +3481,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.ServiceManagerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = ServiceManagerClient( @@ -3593,7 +3492,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ServiceManagerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = ServiceManagerClient(transport=transport) assert client.transport is transport @@ -3602,13 +3501,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ServiceManagerGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.ServiceManagerGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -3623,23 +3522,23 @@ def test_transport_get_channel(): ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = ServiceManagerClient(credentials=credentials.AnonymousCredentials(),) + client = ServiceManagerClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.ServiceManagerGrpcTransport,) def test_service_manager_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(exceptions.DuplicateCredentialArgs): + with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ServiceManagerTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -3651,7 +3550,7 @@ def test_service_manager_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ServiceManagerTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -3683,15 +3582,42 @@ def test_service_manager_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_service_manager_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( - auth, "load_credentials_from_file" + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.servicemanagement_v1.services.service_manager.transports.ServiceManagerTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ServiceManagerTransport( + credentials_file="credentials.json", quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + "https://www.googleapis.com/auth/service.management", + "https://www.googleapis.com/auth/service.management.readonly", + ), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_service_manager_base_transport_with_credentials_file_old_google_auth(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True ) as load_creds, mock.patch( "google.cloud.servicemanagement_v1.services.service_manager.transports.ServiceManagerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (credentials.AnonymousCredentials(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServiceManagerTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -3709,19 +3635,38 @@ def test_service_manager_base_transport_with_credentials_file(): def test_service_manager_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.servicemanagement_v1.services.service_manager.transports.ServiceManagerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ServiceManagerTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_service_manager_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + ServiceManagerClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + "https://www.googleapis.com/auth/service.management", + "https://www.googleapis.com/auth/service.management.readonly", + ), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_service_manager_auth_adc_old_google_auth(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) ServiceManagerClient() adc.assert_called_once_with( scopes=( @@ -3734,14 +3679,46 @@ def test_service_manager_auth_adc(): ) -def test_service_manager_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [ + transports.ServiceManagerGrpcTransport, + transports.ServiceManagerGrpcAsyncIOTransport, + ], +) +@requires_google_auth_gte_1_25_0 +def test_service_manager_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(auth, "default") as adc: - adc.return_value = (credentials.AnonymousCredentials(), None) - transports.ServiceManagerGrpcTransport( - host="squid.clam.whelk", quota_project_id="octopus" + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + "https://www.googleapis.com/auth/service.management", + "https://www.googleapis.com/auth/service.management.readonly", + ), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ServiceManagerGrpcTransport, + transports.ServiceManagerGrpcAsyncIOTransport, + ], +) +@requires_google_auth_lt_1_25_0 +def test_service_manager_transport_auth_adc_old_google_auth(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus") adc.assert_called_once_with( scopes=( "https://www.googleapis.com/auth/cloud-platform", @@ -3753,6 +3730,125 @@ def test_service_manager_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ServiceManagerGrpcTransport, grpc_helpers), + (transports.ServiceManagerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_service_manager_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "servicemanagement.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + "https://www.googleapis.com/auth/service.management", + "https://www.googleapis.com/auth/service.management.readonly", + ), + scopes=["1", "2"], + default_host="servicemanagement.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ServiceManagerGrpcTransport, grpc_helpers), + (transports.ServiceManagerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_service_manager_transport_create_channel_old_api_core( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus") + + create_channel.assert_called_with( + "servicemanagement.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + "https://www.googleapis.com/auth/service.management", + "https://www.googleapis.com/auth/service.management.readonly", + ), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ServiceManagerGrpcTransport, grpc_helpers), + (transports.ServiceManagerGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_service_manager_transport_create_channel_user_scopes( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "servicemanagement.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=["1", "2"], + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "transport_class", [ @@ -3761,7 +3857,7 @@ def test_service_manager_transport_auth_adc(): ], ) def test_service_manager_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3805,7 +3901,7 @@ def test_service_manager_grpc_transport_client_cert_source_for_mtls(transport_cl def test_service_manager_host_no_port(): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="servicemanagement.googleapis.com" ), @@ -3815,7 +3911,7 @@ def test_service_manager_host_no_port(): def test_service_manager_host_with_port(): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="servicemanagement.googleapis.com:8000" ), @@ -3871,9 +3967,9 @@ def test_service_manager_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(auth, "default") as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -3959,7 +4055,7 @@ def test_service_manager_transport_channel_mtls_with_adc(transport_class): def test_service_manager_grpc_lro_client(): client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -3972,7 +4068,7 @@ def test_service_manager_grpc_lro_client(): def test_service_manager_grpc_lro_async_client(): client = ServiceManagerAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -3985,7 +4081,6 @@ def test_service_manager_grpc_lro_async_client(): def test_common_billing_account_path(): billing_account = "squid" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -4006,7 +4101,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) actual = ServiceManagerClient.common_folder_path(folder) assert expected == actual @@ -4025,7 +4119,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) actual = ServiceManagerClient.common_organization_path(organization) assert expected == actual @@ -4044,7 +4137,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "cuttlefish" - expected = "projects/{project}".format(project=project,) actual = ServiceManagerClient.common_project_path(project) assert expected == actual @@ -4064,7 +4156,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "winkle" location = "nautilus" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -4091,7 +4182,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.ServiceManagerTransport, "_prep_wrapped_messages" ) as prep: client = ServiceManagerClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4100,6 +4191,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = ServiceManagerClient.get_transport_class() transport = transport_class( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info)