From 013202c7af491384b01f7f8a070d755ea277e4ae Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 14 May 2021 15:10:05 +0000 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.46.3 (#36) PiperOrigin-RevId: 373649163 Source-Link: https://github.com/googleapis/googleapis/commit/7e1b14e6c7a9ab96d2db7e4a131981f162446d34 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0a3c7d272d697796db75857bac73905c68e498c3 fix: add async client to %name_%version/init.py 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 chore: sort subpackages in %namespace/%name/init.py --- .../hub_service.rst | 1 - google/cloud/networkconnectivity/__init__.py | 18 +- .../networkconnectivity_v1alpha1/__init__.py | 9 +- .../gapic_metadata.json | 123 ++++ .../services/__init__.py | 1 - .../services/hub_service/__init__.py | 2 - .../services/hub_service/async_client.py | 58 +- .../services/hub_service/client.py | 121 ++-- .../services/hub_service/pagers.py | 6 +- .../hub_service/transports/__init__.py | 2 - .../services/hub_service/transports/base.py | 140 ++-- .../services/hub_service/transports/grpc.py | 58 +- .../hub_service/transports/grpc_asyncio.py | 49 +- .../types/__init__.py | 2 - .../types/common.py | 26 +- .../networkconnectivity_v1alpha1/types/hub.py | 152 ++-- ...p_networkconnectivity_v1alpha1_keywords.py | 25 +- tests/__init__.py | 15 + tests/unit/__init__.py | 15 + tests/unit/gapic/__init__.py | 15 + .../networkconnectivity_v1alpha1/__init__.py | 1 - .../test_hub_service.py | 679 ++++++++++-------- 22 files changed, 844 insertions(+), 674 deletions(-) create mode 100644 google/cloud/networkconnectivity_v1alpha1/gapic_metadata.json create mode 100644 tests/__init__.py create mode 100644 tests/unit/__init__.py create mode 100644 tests/unit/gapic/__init__.py diff --git a/docs/networkconnectivity_v1alpha1/hub_service.rst b/docs/networkconnectivity_v1alpha1/hub_service.rst index 1117cfa..f07f3fe 100644 --- a/docs/networkconnectivity_v1alpha1/hub_service.rst +++ b/docs/networkconnectivity_v1alpha1/hub_service.rst @@ -5,7 +5,6 @@ HubService :members: :inherited-members: - .. automodule:: google.cloud.networkconnectivity_v1alpha1.services.hub_service.pagers :members: :inherited-members: diff --git a/google/cloud/networkconnectivity/__init__.py b/google/cloud/networkconnectivity/__init__.py index 880b58d..7bef408 100644 --- a/google/cloud/networkconnectivity/__init__.py +++ b/google/cloud/networkconnectivity/__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.networkconnectivity_v1alpha1.services.hub_service.async_client import ( - HubServiceAsyncClient, -) from google.cloud.networkconnectivity_v1alpha1.services.hub_service.client import ( HubServiceClient, ) +from google.cloud.networkconnectivity_v1alpha1.services.hub_service.async_client import ( + HubServiceAsyncClient, +) + from google.cloud.networkconnectivity_v1alpha1.types.common import OperationMetadata from google.cloud.networkconnectivity_v1alpha1.types.hub import CreateHubRequest from google.cloud.networkconnectivity_v1alpha1.types.hub import CreateSpokeRequest @@ -35,11 +35,14 @@ from google.cloud.networkconnectivity_v1alpha1.types.hub import ListSpokesResponse from google.cloud.networkconnectivity_v1alpha1.types.hub import RouterApplianceInstance from google.cloud.networkconnectivity_v1alpha1.types.hub import Spoke -from google.cloud.networkconnectivity_v1alpha1.types.hub import State from google.cloud.networkconnectivity_v1alpha1.types.hub import UpdateHubRequest from google.cloud.networkconnectivity_v1alpha1.types.hub import UpdateSpokeRequest +from google.cloud.networkconnectivity_v1alpha1.types.hub import State __all__ = ( + "HubServiceClient", + "HubServiceAsyncClient", + "OperationMetadata", "CreateHubRequest", "CreateSpokeRequest", "DeleteHubRequest", @@ -47,16 +50,13 @@ "GetHubRequest", "GetSpokeRequest", "Hub", - "HubServiceAsyncClient", - "HubServiceClient", "ListHubsRequest", "ListHubsResponse", "ListSpokesRequest", "ListSpokesResponse", - "OperationMetadata", "RouterApplianceInstance", "Spoke", - "State", "UpdateHubRequest", "UpdateSpokeRequest", + "State", ) diff --git a/google/cloud/networkconnectivity_v1alpha1/__init__.py b/google/cloud/networkconnectivity_v1alpha1/__init__.py index 6bcd64d..8bc5cdc 100644 --- a/google/cloud/networkconnectivity_v1alpha1/__init__.py +++ b/google/cloud/networkconnectivity_v1alpha1/__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.hub_service import HubServiceClient +from .services.hub_service import HubServiceAsyncClient + from .types.common import OperationMetadata from .types.hub import CreateHubRequest from .types.hub import CreateSpokeRequest @@ -30,12 +31,12 @@ from .types.hub import ListSpokesResponse from .types.hub import RouterApplianceInstance from .types.hub import Spoke -from .types.hub import State from .types.hub import UpdateHubRequest from .types.hub import UpdateSpokeRequest - +from .types.hub import State __all__ = ( + "HubServiceAsyncClient", "CreateHubRequest", "CreateSpokeRequest", "DeleteHubRequest", @@ -43,6 +44,7 @@ "GetHubRequest", "GetSpokeRequest", "Hub", + "HubServiceClient", "ListHubsRequest", "ListHubsResponse", "ListSpokesRequest", @@ -53,5 +55,4 @@ "State", "UpdateHubRequest", "UpdateSpokeRequest", - "HubServiceClient", ) diff --git a/google/cloud/networkconnectivity_v1alpha1/gapic_metadata.json b/google/cloud/networkconnectivity_v1alpha1/gapic_metadata.json new file mode 100644 index 0000000..d6600f0 --- /dev/null +++ b/google/cloud/networkconnectivity_v1alpha1/gapic_metadata.json @@ -0,0 +1,123 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.networkconnectivity_v1alpha1", + "protoPackage": "google.cloud.networkconnectivity.v1alpha1", + "schema": "1.0", + "services": { + "HubService": { + "clients": { + "grpc": { + "libraryClient": "HubServiceClient", + "rpcs": { + "CreateHub": { + "methods": [ + "create_hub" + ] + }, + "CreateSpoke": { + "methods": [ + "create_spoke" + ] + }, + "DeleteHub": { + "methods": [ + "delete_hub" + ] + }, + "DeleteSpoke": { + "methods": [ + "delete_spoke" + ] + }, + "GetHub": { + "methods": [ + "get_hub" + ] + }, + "GetSpoke": { + "methods": [ + "get_spoke" + ] + }, + "ListHubs": { + "methods": [ + "list_hubs" + ] + }, + "ListSpokes": { + "methods": [ + "list_spokes" + ] + }, + "UpdateHub": { + "methods": [ + "update_hub" + ] + }, + "UpdateSpoke": { + "methods": [ + "update_spoke" + ] + } + } + }, + "grpc-async": { + "libraryClient": "HubServiceAsyncClient", + "rpcs": { + "CreateHub": { + "methods": [ + "create_hub" + ] + }, + "CreateSpoke": { + "methods": [ + "create_spoke" + ] + }, + "DeleteHub": { + "methods": [ + "delete_hub" + ] + }, + "DeleteSpoke": { + "methods": [ + "delete_spoke" + ] + }, + "GetHub": { + "methods": [ + "get_hub" + ] + }, + "GetSpoke": { + "methods": [ + "get_spoke" + ] + }, + "ListHubs": { + "methods": [ + "list_hubs" + ] + }, + "ListSpokes": { + "methods": [ + "list_spokes" + ] + }, + "UpdateHub": { + "methods": [ + "update_hub" + ] + }, + "UpdateSpoke": { + "methods": [ + "update_spoke" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/networkconnectivity_v1alpha1/services/__init__.py b/google/cloud/networkconnectivity_v1alpha1/services/__init__.py index 42ffdf2..4de6597 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/__init__.py +++ b/google/cloud/networkconnectivity_v1alpha1/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/networkconnectivity_v1alpha1/services/hub_service/__init__.py b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/__init__.py index 51a8326..b464df6 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/__init__.py +++ b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/__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 HubServiceClient from .async_client import HubServiceAsyncClient diff --git a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/async_client.py b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/async_client.py index d245f24..d39460f 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/async_client.py +++ b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/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,10 +20,10 @@ 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_core import operation # type: ignore @@ -34,10 +32,9 @@ from google.cloud.networkconnectivity_v1alpha1.types import common from google.cloud.networkconnectivity_v1alpha1.types import hub from google.cloud.networkconnectivity_v1alpha1.types import hub as gcn_hub -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import HubServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import HubServiceGrpcAsyncIOTransport from .client import HubServiceClient @@ -69,25 +66,20 @@ class HubServiceAsyncClient: parse_spoke_path = staticmethod(HubServiceClient.parse_spoke_path) vpn_tunnel_path = staticmethod(HubServiceClient.vpn_tunnel_path) parse_vpn_tunnel_path = staticmethod(HubServiceClient.parse_vpn_tunnel_path) - common_billing_account_path = staticmethod( HubServiceClient.common_billing_account_path ) parse_common_billing_account_path = staticmethod( HubServiceClient.parse_common_billing_account_path ) - common_folder_path = staticmethod(HubServiceClient.common_folder_path) parse_common_folder_path = staticmethod(HubServiceClient.parse_common_folder_path) - common_organization_path = staticmethod(HubServiceClient.common_organization_path) parse_common_organization_path = staticmethod( HubServiceClient.parse_common_organization_path ) - common_project_path = staticmethod(HubServiceClient.common_project_path) parse_common_project_path = staticmethod(HubServiceClient.parse_common_project_path) - common_location_path = staticmethod(HubServiceClient.common_location_path) parse_common_location_path = staticmethod( HubServiceClient.parse_common_location_path @@ -95,7 +87,8 @@ class HubServiceAsyncClient: @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. @@ -110,7 +103,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 @@ -127,7 +120,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> HubServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: HubServiceTransport: The transport used by the client instance. @@ -141,12 +134,12 @@ def transport(self) -> HubServiceTransport: def __init__( self, *, - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, transport: Union[str, HubServiceTransport] = "grpc_asyncio", client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the hub service client. + """Instantiates the hub service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -178,7 +171,6 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ - self._client = HubServiceClient( credentials=credentials, transport=transport, @@ -207,7 +199,6 @@ async def list_hubs( This corresponds to the ``parent`` 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. @@ -238,7 +229,6 @@ async def list_hubs( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -291,7 +281,6 @@ async def get_hub( This corresponds to the ``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. @@ -323,7 +312,6 @@ async def get_hub( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -386,7 +374,6 @@ async def create_hub( This corresponds to the ``hub_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. @@ -418,7 +405,6 @@ async def create_hub( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if hub is not None: @@ -459,7 +445,7 @@ async def update_hub( request: gcn_hub.UpdateHubRequest = None, *, hub: gcn_hub.Hub = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -489,7 +475,6 @@ async def update_hub( This corresponds to the ``update_mask`` 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. @@ -521,7 +506,6 @@ async def update_hub( # If we have keyword arguments corresponding to fields on the # request, apply these. - if hub is not None: request.hub = hub if update_mask is not None: @@ -577,7 +561,6 @@ async def delete_hub( This corresponds to the ``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. @@ -617,7 +600,6 @@ async def delete_hub( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -642,7 +624,7 @@ async def delete_hub( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=common.OperationMetadata, ) @@ -669,7 +651,6 @@ async def list_spokes( This corresponds to the ``parent`` 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. @@ -699,7 +680,6 @@ async def list_spokes( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -749,7 +729,6 @@ async def get_spoke( This corresponds to the ``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. @@ -779,7 +758,6 @@ async def get_spoke( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -841,7 +819,6 @@ async def create_spoke( This corresponds to the ``spoke_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. @@ -872,7 +849,6 @@ async def create_spoke( # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if spoke is not None: @@ -913,7 +889,7 @@ async def update_spoke( request: hub.UpdateSpokeRequest = None, *, spoke: hub.Spoke = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -943,7 +919,6 @@ async def update_spoke( This corresponds to the ``update_mask`` 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. @@ -974,7 +949,6 @@ async def update_spoke( # If we have keyword arguments corresponding to fields on the # request, apply these. - if spoke is not None: request.spoke = spoke if update_mask is not None: @@ -1032,7 +1006,6 @@ async def delete_spoke( This corresponds to the ``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. @@ -1072,7 +1045,6 @@ async def delete_spoke( # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1097,7 +1069,7 @@ async def delete_spoke( response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=common.OperationMetadata, ) diff --git a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/client.py b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/client.py index 9233ee5..1f68a74 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/client.py +++ b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/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,10 +21,10 @@ 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 @@ -38,10 +36,9 @@ from google.cloud.networkconnectivity_v1alpha1.types import common from google.cloud.networkconnectivity_v1alpha1.types import hub from google.cloud.networkconnectivity_v1alpha1.types import hub as gcn_hub -from google.protobuf import empty_pb2 as empty # type: ignore -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore - +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import HubServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import HubServiceGrpcTransport from .transports.grpc_asyncio import HubServiceGrpcAsyncIOTransport @@ -60,7 +57,7 @@ class HubServiceClientMeta(type): _transport_registry["grpc_asyncio"] = HubServiceGrpcAsyncIOTransport def get_transport_class(cls, label: str = None,) -> Type[HubServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -87,7 +84,8 @@ class HubServiceClient(metaclass=HubServiceClientMeta): @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: @@ -121,7 +119,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. @@ -138,7 +137,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 @@ -157,23 +156,24 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> HubServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - HubServiceTransport: The transport used by the client instance. + HubServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def hub_path(project: str, hub: str,) -> str: - """Return a fully-qualified hub string.""" + """Returns a fully-qualified hub string.""" return "projects/{project}/locations/global/hubs/{hub}".format( project=project, hub=hub, ) @staticmethod def parse_hub_path(path: str) -> Dict[str, str]: - """Parse a hub path into its component segments.""" + """Parses a hub path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/global/hubs/(?P.+?)$", path ) @@ -181,14 +181,14 @@ def parse_hub_path(path: str) -> Dict[str, str]: @staticmethod def instance_path(project: str, zone: str, instance: str,) -> str: - """Return a fully-qualified instance string.""" + """Returns a fully-qualified instance string.""" return "projects/{project}/zones/{zone}/instances/{instance}".format( project=project, zone=zone, instance=instance, ) @staticmethod def parse_instance_path(path: str) -> Dict[str, str]: - """Parse a instance path into its component segments.""" + """Parses a instance path into its component segments.""" m = re.match( r"^projects/(?P.+?)/zones/(?P.+?)/instances/(?P.+?)$", path, @@ -199,14 +199,14 @@ def parse_instance_path(path: str) -> Dict[str, str]: def interconnect_attachment_path( project: str, region: str, resource_id: str, ) -> str: - """Return a fully-qualified interconnect_attachment string.""" + """Returns a fully-qualified interconnect_attachment string.""" return "projects/{project}/regions/{region}/interconnectAttachments/{resource_id}".format( project=project, region=region, resource_id=resource_id, ) @staticmethod def parse_interconnect_attachment_path(path: str) -> Dict[str, str]: - """Parse a interconnect_attachment path into its component segments.""" + """Parses a interconnect_attachment path into its component segments.""" m = re.match( r"^projects/(?P.+?)/regions/(?P.+?)/interconnectAttachments/(?P.+?)$", path, @@ -215,14 +215,14 @@ def parse_interconnect_attachment_path(path: str) -> Dict[str, str]: @staticmethod def spoke_path(project: str, location: str, spoke: str,) -> str: - """Return a fully-qualified spoke string.""" + """Returns a fully-qualified spoke string.""" return "projects/{project}/locations/{location}/spokes/{spoke}".format( project=project, location=location, spoke=spoke, ) @staticmethod def parse_spoke_path(path: str) -> Dict[str, str]: - """Parse a spoke path into its component segments.""" + """Parses a spoke path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/spokes/(?P.+?)$", path, @@ -231,14 +231,14 @@ def parse_spoke_path(path: str) -> Dict[str, str]: @staticmethod def vpn_tunnel_path(project: str, region: str, resource_id: str,) -> str: - """Return a fully-qualified vpn_tunnel string.""" + """Returns a fully-qualified vpn_tunnel string.""" return "projects/{project}/regions/{region}/vpnTunnels/{resource_id}".format( project=project, region=region, resource_id=resource_id, ) @staticmethod def parse_vpn_tunnel_path(path: str) -> Dict[str, str]: - """Parse a vpn_tunnel path into its component segments.""" + """Parses a vpn_tunnel path into its component segments.""" m = re.match( r"^projects/(?P.+?)/regions/(?P.+?)/vpnTunnels/(?P.+?)$", path, @@ -247,7 +247,7 @@ def parse_vpn_tunnel_path(path: str) -> Dict[str, str]: @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, ) @@ -260,7 +260,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 @@ -271,7 +271,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 @@ -282,7 +282,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 @@ -293,7 +293,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, ) @@ -307,12 +307,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, HubServiceTransport, None] = None, client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the hub service client. + """Instantiates the hub service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -367,9 +367,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: @@ -381,12 +382,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. @@ -401,8 +404,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: @@ -438,7 +441,6 @@ def list_hubs( This corresponds to the ``parent`` 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. @@ -471,10 +473,8 @@ def list_hubs( # there are no flattened fields. if not isinstance(request, hub.ListHubsRequest): request = hub.ListHubsRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -523,7 +523,6 @@ def get_hub( This corresponds to the ``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. @@ -557,10 +556,8 @@ def get_hub( # there are no flattened fields. if not isinstance(request, hub.GetHubRequest): request = hub.GetHubRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -619,7 +616,6 @@ def create_hub( This corresponds to the ``hub_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. @@ -653,10 +649,8 @@ def create_hub( # there are no flattened fields. if not isinstance(request, gcn_hub.CreateHubRequest): request = gcn_hub.CreateHubRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if hub is not None: @@ -693,7 +687,7 @@ def update_hub( request: gcn_hub.UpdateHubRequest = None, *, hub: gcn_hub.Hub = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -723,7 +717,6 @@ def update_hub( This corresponds to the ``update_mask`` 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. @@ -757,10 +750,8 @@ def update_hub( # there are no flattened fields. if not isinstance(request, gcn_hub.UpdateHubRequest): request = gcn_hub.UpdateHubRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if hub is not None: request.hub = hub if update_mask is not None: @@ -812,7 +803,6 @@ def delete_hub( This corresponds to the ``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. @@ -854,10 +844,8 @@ def delete_hub( # there are no flattened fields. if not isinstance(request, hub.DeleteHubRequest): request = hub.DeleteHubRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -878,7 +866,7 @@ def delete_hub( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=common.OperationMetadata, ) @@ -905,7 +893,6 @@ def list_spokes( This corresponds to the ``parent`` 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. @@ -937,10 +924,8 @@ def list_spokes( # there are no flattened fields. if not isinstance(request, hub.ListSpokesRequest): request = hub.ListSpokesRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent @@ -986,7 +971,6 @@ def get_spoke( This corresponds to the ``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. @@ -1018,10 +1002,8 @@ def get_spoke( # there are no flattened fields. if not isinstance(request, hub.GetSpokeRequest): request = hub.GetSpokeRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1079,7 +1061,6 @@ def create_spoke( This corresponds to the ``spoke_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. @@ -1112,10 +1093,8 @@ def create_spoke( # there are no flattened fields. if not isinstance(request, hub.CreateSpokeRequest): request = hub.CreateSpokeRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: request.parent = parent if spoke is not None: @@ -1152,7 +1131,7 @@ def update_spoke( request: hub.UpdateSpokeRequest = None, *, spoke: hub.Spoke = None, - update_mask: field_mask.FieldMask = None, + update_mask: field_mask_pb2.FieldMask = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -1182,7 +1161,6 @@ def update_spoke( This corresponds to the ``update_mask`` 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. @@ -1215,10 +1193,8 @@ def update_spoke( # there are no flattened fields. if not isinstance(request, hub.UpdateSpokeRequest): request = hub.UpdateSpokeRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if spoke is not None: request.spoke = spoke if update_mask is not None: @@ -1272,7 +1248,6 @@ def delete_spoke( This corresponds to the ``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. @@ -1314,10 +1289,8 @@ def delete_spoke( # there are no flattened fields. if not isinstance(request, hub.DeleteSpokeRequest): request = hub.DeleteSpokeRequest(request) - # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: request.name = name @@ -1338,7 +1311,7 @@ def delete_spoke( response = operation.from_gapic( response, self._transport.operations_client, - empty.Empty, + empty_pb2.Empty, metadata_type=common.OperationMetadata, ) diff --git a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/pagers.py b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/pagers.py index 1e1f1ae..ce63e7b 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/pagers.py +++ b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/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, @@ -117,7 +115,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -245,7 +243,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/networkconnectivity_v1alpha1/services/hub_service/transports/__init__.py b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/__init__.py index b9080e4..a384768 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/__init__.py +++ b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/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/networkconnectivity_v1alpha1/services/hub_service/transports/base.py b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/base.py index 5644d0f..3ccf6c6 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/base.py +++ b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/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,22 +13,22 @@ # 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.cloud.networkconnectivity_v1alpha1.types import hub from google.cloud.networkconnectivity_v1alpha1.types import hub as gcn_hub -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( @@ -40,27 +39,41 @@ 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 HubServiceTransport(abc.ABC): """Abstract transport class for HubService.""" AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + DEFAULT_HOST: str = "networkconnectivity.googleapis.com" + def __init__( self, *, - host: str = "networkconnectivity.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 @@ -69,7 +82,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): @@ -83,29 +96,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 = { @@ -149,88 +209,84 @@ def operations_client(self) -> operations_v1.OperationsClient: @property def list_hubs( self, - ) -> typing.Callable[ + ) -> Callable[ [hub.ListHubsRequest], - typing.Union[hub.ListHubsResponse, typing.Awaitable[hub.ListHubsResponse]], + Union[hub.ListHubsResponse, Awaitable[hub.ListHubsResponse]], ]: raise NotImplementedError() @property def get_hub( self, - ) -> typing.Callable[ - [hub.GetHubRequest], typing.Union[hub.Hub, typing.Awaitable[hub.Hub]] - ]: + ) -> Callable[[hub.GetHubRequest], Union[hub.Hub, Awaitable[hub.Hub]]]: raise NotImplementedError() @property def create_hub( self, - ) -> typing.Callable[ + ) -> Callable[ [gcn_hub.CreateHubRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_hub( self, - ) -> typing.Callable[ + ) -> Callable[ [gcn_hub.UpdateHubRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_hub( self, - ) -> typing.Callable[ + ) -> Callable[ [hub.DeleteHubRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def list_spokes( self, - ) -> typing.Callable[ + ) -> Callable[ [hub.ListSpokesRequest], - typing.Union[hub.ListSpokesResponse, typing.Awaitable[hub.ListSpokesResponse]], + Union[hub.ListSpokesResponse, Awaitable[hub.ListSpokesResponse]], ]: raise NotImplementedError() @property def get_spoke( self, - ) -> typing.Callable[ - [hub.GetSpokeRequest], typing.Union[hub.Spoke, typing.Awaitable[hub.Spoke]] - ]: + ) -> Callable[[hub.GetSpokeRequest], Union[hub.Spoke, Awaitable[hub.Spoke]]]: raise NotImplementedError() @property def create_spoke( self, - ) -> typing.Callable[ + ) -> Callable[ [hub.CreateSpokeRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def update_spoke( self, - ) -> typing.Callable[ + ) -> Callable[ [hub.UpdateSpokeRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() @property def delete_spoke( self, - ) -> typing.Callable[ + ) -> Callable[ [hub.DeleteSpokeRequest], - typing.Union[operations.Operation, typing.Awaitable[operations.Operation]], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], ]: raise NotImplementedError() diff --git a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc.py b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc.py index e0c8aad..4e763e1 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc.py +++ b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/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,23 +13,21 @@ # 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.cloud.networkconnectivity_v1alpha1.types import hub from google.cloud.networkconnectivity_v1alpha1.types import hub as gcn_hub -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import HubServiceTransport, DEFAULT_CLIENT_INFO @@ -56,7 +53,7 @@ def __init__( self, *, host: str = "networkconnectivity.googleapis.com", - credentials: credentials.Credentials = None, + credentials: ga_credentials.Credentials = None, credentials_file: str = None, scopes: Sequence[str] = None, channel: grpc.Channel = None, @@ -70,7 +67,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 @@ -181,7 +179,7 @@ def __init__( def create_channel( cls, host: str = "networkconnectivity.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, @@ -212,13 +210,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, ) @@ -291,7 +291,9 @@ def get_hub(self) -> Callable[[hub.GetHubRequest], hub.Hub]: return self._stubs["get_hub"] @property - def create_hub(self) -> Callable[[gcn_hub.CreateHubRequest], operations.Operation]: + def create_hub( + self, + ) -> Callable[[gcn_hub.CreateHubRequest], operations_pb2.Operation]: r"""Return a callable for the create hub method over gRPC. Creates a new Hub in a given project and location. @@ -310,12 +312,14 @@ def create_hub(self) -> Callable[[gcn_hub.CreateHubRequest], operations.Operatio self._stubs["create_hub"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/CreateHub", request_serializer=gcn_hub.CreateHubRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_hub"] @property - def update_hub(self) -> Callable[[gcn_hub.UpdateHubRequest], operations.Operation]: + def update_hub( + self, + ) -> Callable[[gcn_hub.UpdateHubRequest], operations_pb2.Operation]: r"""Return a callable for the update hub method over gRPC. Updates the parameters of a single Hub. @@ -334,12 +338,12 @@ def update_hub(self) -> Callable[[gcn_hub.UpdateHubRequest], operations.Operatio self._stubs["update_hub"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/UpdateHub", request_serializer=gcn_hub.UpdateHubRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_hub"] @property - def delete_hub(self) -> Callable[[hub.DeleteHubRequest], operations.Operation]: + def delete_hub(self) -> Callable[[hub.DeleteHubRequest], operations_pb2.Operation]: r"""Return a callable for the delete hub method over gRPC. Deletes a single Hub. @@ -358,7 +362,7 @@ def delete_hub(self) -> Callable[[hub.DeleteHubRequest], operations.Operation]: self._stubs["delete_hub"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/DeleteHub", request_serializer=hub.DeleteHubRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_hub"] @@ -411,7 +415,9 @@ def get_spoke(self) -> Callable[[hub.GetSpokeRequest], hub.Spoke]: return self._stubs["get_spoke"] @property - def create_spoke(self) -> Callable[[hub.CreateSpokeRequest], operations.Operation]: + def create_spoke( + self, + ) -> Callable[[hub.CreateSpokeRequest], operations_pb2.Operation]: r"""Return a callable for the create spoke method over gRPC. Creates a new Spoke in a given project and location. @@ -430,12 +436,14 @@ def create_spoke(self) -> Callable[[hub.CreateSpokeRequest], operations.Operatio self._stubs["create_spoke"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/CreateSpoke", request_serializer=hub.CreateSpokeRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_spoke"] @property - def update_spoke(self) -> Callable[[hub.UpdateSpokeRequest], operations.Operation]: + def update_spoke( + self, + ) -> Callable[[hub.UpdateSpokeRequest], operations_pb2.Operation]: r"""Return a callable for the update spoke method over gRPC. Updates the parameters of a single Spoke. @@ -454,12 +462,14 @@ def update_spoke(self) -> Callable[[hub.UpdateSpokeRequest], operations.Operatio self._stubs["update_spoke"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/UpdateSpoke", request_serializer=hub.UpdateSpokeRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_spoke"] @property - def delete_spoke(self) -> Callable[[hub.DeleteSpokeRequest], operations.Operation]: + def delete_spoke( + self, + ) -> Callable[[hub.DeleteSpokeRequest], operations_pb2.Operation]: r"""Return a callable for the delete spoke method over gRPC. Deletes a single Spoke. @@ -478,7 +488,7 @@ def delete_spoke(self) -> Callable[[hub.DeleteSpokeRequest], operations.Operatio self._stubs["delete_spoke"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/DeleteSpoke", request_serializer=hub.DeleteSpokeRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_spoke"] diff --git a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc_asyncio.py b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc_asyncio.py index 71a7e81..70865c7 100644 --- a/google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc_asyncio.py +++ b/google/cloud/networkconnectivity_v1alpha1/services/hub_service/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,24 +13,22 @@ # 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.cloud.networkconnectivity_v1alpha1.types import hub from google.cloud.networkconnectivity_v1alpha1.types import hub as gcn_hub -from google.longrunning import operations_pb2 as operations # type: ignore - +from google.longrunning import operations_pb2 # type: ignore from .base import HubServiceTransport, DEFAULT_CLIENT_INFO from .grpc import HubServiceGrpcTransport @@ -59,7 +56,7 @@ class HubServiceGrpcAsyncIOTransport(HubServiceTransport): def create_channel( cls, host: str = "networkconnectivity.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, @@ -86,13 +83,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, ) @@ -100,7 +99,7 @@ def __init__( self, *, host: str = "networkconnectivity.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, @@ -114,7 +113,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 @@ -173,7 +173,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 @@ -301,7 +300,7 @@ def get_hub(self) -> Callable[[hub.GetHubRequest], Awaitable[hub.Hub]]: @property def create_hub( self, - ) -> Callable[[gcn_hub.CreateHubRequest], Awaitable[operations.Operation]]: + ) -> Callable[[gcn_hub.CreateHubRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the create hub method over gRPC. Creates a new Hub in a given project and location. @@ -320,14 +319,14 @@ def create_hub( self._stubs["create_hub"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/CreateHub", request_serializer=gcn_hub.CreateHubRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_hub"] @property def update_hub( self, - ) -> Callable[[gcn_hub.UpdateHubRequest], Awaitable[operations.Operation]]: + ) -> Callable[[gcn_hub.UpdateHubRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the update hub method over gRPC. Updates the parameters of a single Hub. @@ -346,14 +345,14 @@ def update_hub( self._stubs["update_hub"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/UpdateHub", request_serializer=gcn_hub.UpdateHubRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_hub"] @property def delete_hub( self, - ) -> Callable[[hub.DeleteHubRequest], Awaitable[operations.Operation]]: + ) -> Callable[[hub.DeleteHubRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the delete hub method over gRPC. Deletes a single Hub. @@ -372,7 +371,7 @@ def delete_hub( self._stubs["delete_hub"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/DeleteHub", request_serializer=hub.DeleteHubRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_hub"] @@ -429,7 +428,7 @@ def get_spoke(self) -> Callable[[hub.GetSpokeRequest], Awaitable[hub.Spoke]]: @property def create_spoke( self, - ) -> Callable[[hub.CreateSpokeRequest], Awaitable[operations.Operation]]: + ) -> Callable[[hub.CreateSpokeRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the create spoke method over gRPC. Creates a new Spoke in a given project and location. @@ -448,14 +447,14 @@ def create_spoke( self._stubs["create_spoke"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/CreateSpoke", request_serializer=hub.CreateSpokeRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["create_spoke"] @property def update_spoke( self, - ) -> Callable[[hub.UpdateSpokeRequest], Awaitable[operations.Operation]]: + ) -> Callable[[hub.UpdateSpokeRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the update spoke method over gRPC. Updates the parameters of a single Spoke. @@ -474,14 +473,14 @@ def update_spoke( self._stubs["update_spoke"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/UpdateSpoke", request_serializer=hub.UpdateSpokeRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["update_spoke"] @property def delete_spoke( self, - ) -> Callable[[hub.DeleteSpokeRequest], Awaitable[operations.Operation]]: + ) -> Callable[[hub.DeleteSpokeRequest], Awaitable[operations_pb2.Operation]]: r"""Return a callable for the delete spoke method over gRPC. Deletes a single Spoke. @@ -500,7 +499,7 @@ def delete_spoke( self._stubs["delete_spoke"] = self.grpc_channel.unary_unary( "/google.cloud.networkconnectivity.v1alpha1.HubService/DeleteSpoke", request_serializer=hub.DeleteSpokeRequest.serialize, - response_deserializer=operations.Operation.FromString, + response_deserializer=operations_pb2.Operation.FromString, ) return self._stubs["delete_spoke"] diff --git a/google/cloud/networkconnectivity_v1alpha1/types/__init__.py b/google/cloud/networkconnectivity_v1alpha1/types/__init__.py index c14fdb5..384c991 100644 --- a/google/cloud/networkconnectivity_v1alpha1/types/__init__.py +++ b/google/cloud/networkconnectivity_v1alpha1/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 .common import OperationMetadata from .hub import ( CreateHubRequest, diff --git a/google/cloud/networkconnectivity_v1alpha1/types/common.py b/google/cloud/networkconnectivity_v1alpha1/types/common.py index 396145c..ba7dac9 100644 --- a/google/cloud/networkconnectivity_v1alpha1/types/common.py +++ b/google/cloud/networkconnectivity_v1alpha1/types/common.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore - -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -29,7 +26,6 @@ class OperationMetadata(proto.Message): r"""Represents the metadata of the long-running operation. - Attributes: create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time the operation was @@ -57,19 +53,13 @@ class OperationMetadata(proto.Message): operation. """ - create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp.Timestamp,) - - end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - target = proto.Field(proto.STRING, number=3) - - verb = proto.Field(proto.STRING, number=4) - - status_message = proto.Field(proto.STRING, number=5) - - requested_cancellation = proto.Field(proto.BOOL, number=6) - - api_version = proto.Field(proto.STRING, number=7) + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + target = proto.Field(proto.STRING, number=3,) + verb = proto.Field(proto.STRING, number=4,) + status_message = proto.Field(proto.STRING, number=5,) + requested_cancellation = proto.Field(proto.BOOL, number=6,) + api_version = proto.Field(proto.STRING, number=7,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/networkconnectivity_v1alpha1/types/hub.py b/google/cloud/networkconnectivity_v1alpha1/types/hub.py index f82d977..9e408f8 100644 --- a/google/cloud/networkconnectivity_v1alpha1/types/hub.py +++ b/google/cloud/networkconnectivity_v1alpha1/types/hub.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.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -86,20 +83,13 @@ class Hub(proto.Message): this Hub. """ - name = proto.Field(proto.STRING, number=1) - - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) - - labels = proto.MapField(proto.STRING, proto.STRING, number=4) - - description = proto.Field(proto.STRING, number=5) - - spokes = proto.RepeatedField(proto.STRING, number=6) - - unique_id = proto.Field(proto.STRING, number=8) - + name = proto.Field(proto.STRING, number=1,) + create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + labels = proto.MapField(proto.STRING, proto.STRING, number=4,) + description = proto.Field(proto.STRING, number=5,) + spokes = proto.RepeatedField(proto.STRING, number=6,) + unique_id = proto.Field(proto.STRING, number=8,) state = proto.Field(proto.ENUM, number=9, enum="State",) @@ -139,28 +129,18 @@ class Spoke(proto.Message): this Hub. """ - name = proto.Field(proto.STRING, number=1) - - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp.Timestamp,) - - update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp.Timestamp,) - - labels = proto.MapField(proto.STRING, proto.STRING, number=4) - - description = proto.Field(proto.STRING, number=5) - - hub = proto.Field(proto.STRING, number=6) - - linked_vpn_tunnels = proto.RepeatedField(proto.STRING, number=12) - - linked_interconnect_attachments = proto.RepeatedField(proto.STRING, number=13) - + name = proto.Field(proto.STRING, number=1,) + create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + labels = proto.MapField(proto.STRING, proto.STRING, number=4,) + description = proto.Field(proto.STRING, number=5,) + hub = proto.Field(proto.STRING, number=6,) + linked_vpn_tunnels = proto.RepeatedField(proto.STRING, number=12,) + linked_interconnect_attachments = proto.RepeatedField(proto.STRING, number=13,) linked_router_appliance_instances = proto.RepeatedField( proto.MESSAGE, number=14, message="RouterApplianceInstance", ) - - unique_id = proto.Field(proto.STRING, number=11) - + unique_id = proto.Field(proto.STRING, number=11,) state = proto.Field(proto.ENUM, number=15, enum="State",) @@ -184,15 +164,11 @@ class ListHubsRequest(proto.Message): Sort the results by a certain order. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - filter = proto.Field(proto.STRING, number=4) - - order_by = proto.Field(proto.STRING, number=5) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) class ListHubsResponse(proto.Message): @@ -216,10 +192,8 @@ def raw_page(self): return self hubs = proto.RepeatedField(proto.MESSAGE, number=1, message="Hub",) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class GetHubRequest(proto.Message): @@ -232,7 +206,7 @@ class GetHubRequest(proto.Message): Required. Name of the Hub resource to get. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateHubRequest(proto.Message): @@ -268,13 +242,10 @@ class CreateHubRequest(proto.Message): (00000000-0000-0000-0000-000000000000). """ - parent = proto.Field(proto.STRING, number=1) - - hub_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + hub_id = proto.Field(proto.STRING, number=2,) hub = proto.Field(proto.MESSAGE, number=3, message="Hub",) - - request_id = proto.Field(proto.STRING, number=4) + request_id = proto.Field(proto.STRING, number=4,) class UpdateHubRequest(proto.Message): @@ -313,11 +284,11 @@ class UpdateHubRequest(proto.Message): (00000000-0000-0000-0000-000000000000). """ - update_mask = proto.Field(proto.MESSAGE, number=1, message=field_mask.FieldMask,) - + update_mask = proto.Field( + proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + ) hub = proto.Field(proto.MESSAGE, number=2, message="Hub",) - - request_id = proto.Field(proto.STRING, number=3) + request_id = proto.Field(proto.STRING, number=3,) class DeleteHubRequest(proto.Message): @@ -347,9 +318,8 @@ class DeleteHubRequest(proto.Message): (00000000-0000-0000-0000-000000000000). """ - name = proto.Field(proto.STRING, number=1) - - request_id = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + request_id = proto.Field(proto.STRING, number=2,) class ListSpokesRequest(proto.Message): @@ -371,15 +341,11 @@ class ListSpokesRequest(proto.Message): Sort the results by a certain order. """ - parent = proto.Field(proto.STRING, number=1) - - page_size = proto.Field(proto.INT32, number=2) - - page_token = proto.Field(proto.STRING, number=3) - - filter = proto.Field(proto.STRING, number=4) - - order_by = proto.Field(proto.STRING, number=5) + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) class ListSpokesResponse(proto.Message): @@ -402,10 +368,8 @@ def raw_page(self): return self spokes = proto.RepeatedField(proto.MESSAGE, number=1, message="Spoke",) - - next_page_token = proto.Field(proto.STRING, number=2) - - unreachable = proto.RepeatedField(proto.STRING, number=3) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) class GetSpokeRequest(proto.Message): @@ -417,7 +381,7 @@ class GetSpokeRequest(proto.Message): Required. The name of Spoke resource. """ - name = proto.Field(proto.STRING, number=1) + name = proto.Field(proto.STRING, number=1,) class CreateSpokeRequest(proto.Message): @@ -452,13 +416,10 @@ class CreateSpokeRequest(proto.Message): (00000000-0000-0000-0000-000000000000). """ - parent = proto.Field(proto.STRING, number=1) - - spoke_id = proto.Field(proto.STRING, number=2) - + parent = proto.Field(proto.STRING, number=1,) + spoke_id = proto.Field(proto.STRING, number=2,) spoke = proto.Field(proto.MESSAGE, number=3, message="Spoke",) - - request_id = proto.Field(proto.STRING, number=4) + request_id = proto.Field(proto.STRING, number=4,) class UpdateSpokeRequest(proto.Message): @@ -497,11 +458,11 @@ class UpdateSpokeRequest(proto.Message): (00000000-0000-0000-0000-000000000000). """ - update_mask = proto.Field(proto.MESSAGE, number=1, message=field_mask.FieldMask,) - + update_mask = proto.Field( + proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + ) spoke = proto.Field(proto.MESSAGE, number=2, message="Spoke",) - - request_id = proto.Field(proto.STRING, number=3) + request_id = proto.Field(proto.STRING, number=3,) class DeleteSpokeRequest(proto.Message): @@ -531,9 +492,8 @@ class DeleteSpokeRequest(proto.Message): (00000000-0000-0000-0000-000000000000). """ - name = proto.Field(proto.STRING, number=1) - - request_id = proto.Field(proto.STRING, number=2) + name = proto.Field(proto.STRING, number=1,) + request_id = proto.Field(proto.STRING, number=2,) class RouterApplianceInstance(proto.Message): @@ -550,11 +510,9 @@ class RouterApplianceInstance(proto.Message): """ - virtual_machine = proto.Field(proto.STRING, number=1) - - ip_address = proto.Field(proto.STRING, number=3) - - network_interface = proto.Field(proto.STRING, number=2) + virtual_machine = proto.Field(proto.STRING, number=1,) + ip_address = proto.Field(proto.STRING, number=3,) + network_interface = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/scripts/fixup_networkconnectivity_v1alpha1_keywords.py b/scripts/fixup_networkconnectivity_v1alpha1_keywords.py index ce4332b..2c61070 100644 --- a/scripts/fixup_networkconnectivity_v1alpha1_keywords.py +++ b/scripts/fixup_networkconnectivity_v1alpha1_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,17 +39,16 @@ def partition( class networkconnectivityCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_hub': ('parent', 'hub', 'hub_id', 'request_id', ), - 'create_spoke': ('parent', 'spoke', 'spoke_id', 'request_id', ), - 'delete_hub': ('name', 'request_id', ), - 'delete_spoke': ('name', 'request_id', ), - 'get_hub': ('name', ), - 'get_spoke': ('name', ), - 'list_hubs': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), - 'list_spokes': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), - 'update_hub': ('hub', 'update_mask', 'request_id', ), - 'update_spoke': ('spoke', 'update_mask', 'request_id', ), - + 'create_hub': ('parent', 'hub', 'hub_id', 'request_id', ), + 'create_spoke': ('parent', 'spoke', 'spoke_id', 'request_id', ), + 'delete_hub': ('name', 'request_id', ), + 'delete_spoke': ('name', 'request_id', ), + 'get_hub': ('name', ), + 'get_spoke': ('name', ), + 'list_hubs': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'list_spokes': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'update_hub': ('hub', 'update_mask', 'request_id', ), + 'update_spoke': ('spoke', 'update_mask', 'request_id', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: @@ -82,7 +79,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/networkconnectivity_v1alpha1/__init__.py b/tests/unit/gapic/networkconnectivity_v1alpha1/__init__.py index 42ffdf2..4de6597 100644 --- a/tests/unit/gapic/networkconnectivity_v1alpha1/__init__.py +++ b/tests/unit/gapic/networkconnectivity_v1alpha1/__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/networkconnectivity_v1alpha1/test_hub_service.py b/tests/unit/gapic/networkconnectivity_v1alpha1/test_hub_service.py index 55e48dc..907d23a 100644 --- a/tests/unit/gapic/networkconnectivity_v1alpha1/test_hub_service.py +++ b/tests/unit/gapic/networkconnectivity_v1alpha1/test_hub_service.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,16 +23,16 @@ import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule -from google import auth + 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.networkconnectivity_v1alpha1.services.hub_service import ( HubServiceAsyncClient, @@ -43,13 +42,43 @@ ) from google.cloud.networkconnectivity_v1alpha1.services.hub_service import pagers from google.cloud.networkconnectivity_v1alpha1.services.hub_service import transports +from google.cloud.networkconnectivity_v1alpha1.services.hub_service.transports.base import ( + _API_CORE_VERSION, +) +from google.cloud.networkconnectivity_v1alpha1.services.hub_service.transports.base import ( + _GOOGLE_AUTH_VERSION, +) from google.cloud.networkconnectivity_v1alpha1.types import common from google.cloud.networkconnectivity_v1alpha1.types import hub from google.cloud.networkconnectivity_v1alpha1.types import hub as gcn_hub from google.longrunning import operations_pb2 from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 as field_mask # type: ignore -from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_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(): @@ -95,7 +124,7 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize("client_class", [HubServiceClient, HubServiceAsyncClient,]) def test_hub_service_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: @@ -110,7 +139,7 @@ def test_hub_service_client_from_service_account_info(client_class): @pytest.mark.parametrize("client_class", [HubServiceClient, HubServiceAsyncClient,]) def test_hub_service_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: @@ -161,7 +190,7 @@ def test_hub_service_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(HubServiceClient, "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() @@ -443,7 +472,7 @@ def test_hub_service_client_client_options_from_dict(): def test_list_hubs(transport: str = "grpc", request_type=hub.ListHubsRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -456,21 +485,16 @@ def test_list_hubs(transport: str = "grpc", request_type=hub.ListHubsRequest): call.return_value = hub.ListHubsResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_hubs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == hub.ListHubsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListHubsPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -482,7 +506,7 @@ def test_list_hubs_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -490,7 +514,6 @@ def test_list_hubs_empty_call(): client.list_hubs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == hub.ListHubsRequest() @@ -499,7 +522,7 @@ async def test_list_hubs_async( transport: str = "grpc_asyncio", request_type=hub.ListHubsRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -515,20 +538,16 @@ async def test_list_hubs_async( unreachable=["unreachable_value"], ) ) - response = await client.list_hubs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == hub.ListHubsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListHubsAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -538,17 +557,17 @@ async def test_list_hubs_async_from_dict(): def test_list_hubs_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.ListHubsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_hubs), "__call__") as call: call.return_value = hub.ListHubsResponse() - client.list_hubs(request) # Establish that the underlying gRPC stub method was called. @@ -563,11 +582,12 @@ def test_list_hubs_field_headers(): @pytest.mark.asyncio async def test_list_hubs_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.ListHubsRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -575,7 +595,6 @@ async def test_list_hubs_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( hub.ListHubsResponse() ) - await client.list_hubs(request) # Establish that the underlying gRPC stub method was called. @@ -589,13 +608,12 @@ async def test_list_hubs_field_headers_async(): def test_list_hubs_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_hubs), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = hub.ListHubsResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_hubs(parent="parent_value",) @@ -604,12 +622,11 @@ def test_list_hubs_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_hubs_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -621,7 +638,7 @@ def test_list_hubs_flattened_error(): @pytest.mark.asyncio async def test_list_hubs_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_hubs), "__call__") as call: @@ -639,13 +656,12 @@ async def test_list_hubs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_hubs_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -656,7 +672,7 @@ async def test_list_hubs_flattened_error_async(): def test_list_hubs_pager(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials,) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_hubs), "__call__") as call: @@ -685,7 +701,7 @@ def test_list_hubs_pager(): def test_list_hubs_pages(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials,) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_hubs), "__call__") as call: @@ -706,7 +722,7 @@ def test_list_hubs_pages(): @pytest.mark.asyncio async def test_list_hubs_async_pager(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -734,7 +750,7 @@ async def test_list_hubs_async_pager(): @pytest.mark.asyncio async def test_list_hubs_async_pages(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -759,7 +775,7 @@ async def test_list_hubs_async_pages(): def test_get_hub(transport: str = "grpc", request_type=hub.GetHubRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -776,27 +792,19 @@ def test_get_hub(transport: str = "grpc", request_type=hub.GetHubRequest): unique_id="unique_id_value", state=hub.State.CREATING, ) - response = client.get_hub(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == hub.GetHubRequest() # Establish that the response is the type that we expect. - assert isinstance(response, hub.Hub) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.spokes == ["spokes_value"] - assert response.unique_id == "unique_id_value" - assert response.state == hub.State.CREATING @@ -808,7 +816,7 @@ def test_get_hub_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -816,7 +824,6 @@ def test_get_hub_empty_call(): client.get_hub() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == hub.GetHubRequest() @@ -825,7 +832,7 @@ async def test_get_hub_async( transport: str = "grpc_asyncio", request_type=hub.GetHubRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -844,26 +851,19 @@ async def test_get_hub_async( state=hub.State.CREATING, ) ) - response = await client.get_hub(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == hub.GetHubRequest() # Establish that the response is the type that we expect. assert isinstance(response, hub.Hub) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.spokes == ["spokes_value"] - assert response.unique_id == "unique_id_value" - assert response.state == hub.State.CREATING @@ -873,17 +873,17 @@ async def test_get_hub_async_from_dict(): def test_get_hub_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.GetHubRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_hub), "__call__") as call: call.return_value = hub.Hub() - client.get_hub(request) # Establish that the underlying gRPC stub method was called. @@ -898,17 +898,17 @@ def test_get_hub_field_headers(): @pytest.mark.asyncio async def test_get_hub_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.GetHubRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_hub), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(hub.Hub()) - await client.get_hub(request) # Establish that the underlying gRPC stub method was called. @@ -922,13 +922,12 @@ async def test_get_hub_field_headers_async(): def test_get_hub_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_hub), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = hub.Hub() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_hub(name="name_value",) @@ -937,12 +936,11 @@ def test_get_hub_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_hub_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -954,7 +952,7 @@ def test_get_hub_flattened_error(): @pytest.mark.asyncio async def test_get_hub_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_hub), "__call__") as call: @@ -970,13 +968,12 @@ async def test_get_hub_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_hub_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -988,7 +985,7 @@ async def test_get_hub_flattened_error_async(): def test_create_hub(transport: str = "grpc", request_type=gcn_hub.CreateHubRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -999,13 +996,11 @@ def test_create_hub(transport: str = "grpc", request_type=gcn_hub.CreateHubReque with mock.patch.object(type(client.transport.create_hub), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_hub(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == gcn_hub.CreateHubRequest() # Establish that the response is the type that we expect. @@ -1020,7 +1015,7 @@ def test_create_hub_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1028,7 +1023,6 @@ def test_create_hub_empty_call(): client.create_hub() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == gcn_hub.CreateHubRequest() @@ -1037,7 +1031,7 @@ async def test_create_hub_async( transport: str = "grpc_asyncio", request_type=gcn_hub.CreateHubRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1050,13 +1044,11 @@ async def test_create_hub_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_hub(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == gcn_hub.CreateHubRequest() # Establish that the response is the type that we expect. @@ -1069,17 +1061,17 @@ async def test_create_hub_async_from_dict(): def test_create_hub_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = gcn_hub.CreateHubRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_hub), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_hub(request) # Establish that the underlying gRPC stub method was called. @@ -1094,11 +1086,12 @@ def test_create_hub_field_headers(): @pytest.mark.asyncio async def test_create_hub_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = gcn_hub.CreateHubRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1099,6 @@ async def test_create_hub_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_hub(request) # Establish that the underlying gRPC stub method was called. @@ -1120,13 +1112,12 @@ async def test_create_hub_field_headers_async(): def test_create_hub_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_hub), "__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_hub( @@ -1139,16 +1130,13 @@ def test_create_hub_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].hub == gcn_hub.Hub(name="name_value") - assert args[0].hub_id == "hub_id_value" def test_create_hub_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1163,7 +1151,7 @@ def test_create_hub_flattened_error(): @pytest.mark.asyncio async def test_create_hub_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_hub), "__call__") as call: @@ -1185,17 +1173,14 @@ async def test_create_hub_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].hub == gcn_hub.Hub(name="name_value") - assert args[0].hub_id == "hub_id_value" @pytest.mark.asyncio async def test_create_hub_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1210,7 +1195,7 @@ async def test_create_hub_flattened_error_async(): def test_update_hub(transport: str = "grpc", request_type=gcn_hub.UpdateHubRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1221,13 +1206,11 @@ def test_update_hub(transport: str = "grpc", request_type=gcn_hub.UpdateHubReque with mock.patch.object(type(client.transport.update_hub), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_hub(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == gcn_hub.UpdateHubRequest() # Establish that the response is the type that we expect. @@ -1242,7 +1225,7 @@ def test_update_hub_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1250,7 +1233,6 @@ def test_update_hub_empty_call(): client.update_hub() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == gcn_hub.UpdateHubRequest() @@ -1259,7 +1241,7 @@ async def test_update_hub_async( transport: str = "grpc_asyncio", request_type=gcn_hub.UpdateHubRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1272,13 +1254,11 @@ async def test_update_hub_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_hub(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == gcn_hub.UpdateHubRequest() # Establish that the response is the type that we expect. @@ -1291,17 +1271,17 @@ async def test_update_hub_async_from_dict(): def test_update_hub_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = gcn_hub.UpdateHubRequest() + request.hub.name = "hub.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_hub), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_hub(request) # Establish that the underlying gRPC stub method was called. @@ -1316,11 +1296,12 @@ def test_update_hub_field_headers(): @pytest.mark.asyncio async def test_update_hub_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = gcn_hub.UpdateHubRequest() + request.hub.name = "hub.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1328,7 +1309,6 @@ async def test_update_hub_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_hub(request) # Establish that the underlying gRPC stub method was called. @@ -1342,32 +1322,29 @@ async def test_update_hub_field_headers_async(): def test_update_hub_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_hub), "__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.update_hub( hub=gcn_hub.Hub(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_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].hub == gcn_hub.Hub(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_hub_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1375,13 +1352,13 @@ def test_update_hub_flattened_error(): client.update_hub( gcn_hub.UpdateHubRequest(), hub=gcn_hub.Hub(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_hub_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_hub), "__call__") as call: @@ -1395,22 +1372,20 @@ async def test_update_hub_flattened_async(): # using the keyword arguments to the method. response = await client.update_hub( hub=gcn_hub.Hub(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_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].hub == gcn_hub.Hub(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_hub_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1418,13 +1393,13 @@ async def test_update_hub_flattened_error_async(): await client.update_hub( gcn_hub.UpdateHubRequest(), hub=gcn_hub.Hub(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) def test_delete_hub(transport: str = "grpc", request_type=hub.DeleteHubRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1435,13 +1410,11 @@ def test_delete_hub(transport: str = "grpc", request_type=hub.DeleteHubRequest): with mock.patch.object(type(client.transport.delete_hub), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_hub(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == hub.DeleteHubRequest() # Establish that the response is the type that we expect. @@ -1456,7 +1429,7 @@ def test_delete_hub_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1464,7 +1437,6 @@ def test_delete_hub_empty_call(): client.delete_hub() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == hub.DeleteHubRequest() @@ -1473,7 +1445,7 @@ async def test_delete_hub_async( transport: str = "grpc_asyncio", request_type=hub.DeleteHubRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1486,13 +1458,11 @@ async def test_delete_hub_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_hub(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == hub.DeleteHubRequest() # Establish that the response is the type that we expect. @@ -1505,17 +1475,17 @@ async def test_delete_hub_async_from_dict(): def test_delete_hub_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.DeleteHubRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_hub), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_hub(request) # Establish that the underlying gRPC stub method was called. @@ -1530,11 +1500,12 @@ def test_delete_hub_field_headers(): @pytest.mark.asyncio async def test_delete_hub_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.DeleteHubRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1542,7 +1513,6 @@ async def test_delete_hub_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_hub(request) # Establish that the underlying gRPC stub method was called. @@ -1556,13 +1526,12 @@ async def test_delete_hub_field_headers_async(): def test_delete_hub_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_hub), "__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_hub(name="name_value",) @@ -1571,12 +1540,11 @@ def test_delete_hub_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_hub_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1588,7 +1556,7 @@ def test_delete_hub_flattened_error(): @pytest.mark.asyncio async def test_delete_hub_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_hub), "__call__") as call: @@ -1606,13 +1574,12 @@ async def test_delete_hub_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_hub_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1624,7 +1591,7 @@ async def test_delete_hub_flattened_error_async(): def test_list_spokes(transport: str = "grpc", request_type=hub.ListSpokesRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1637,21 +1604,16 @@ def test_list_spokes(transport: str = "grpc", request_type=hub.ListSpokesRequest call.return_value = hub.ListSpokesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], ) - response = client.list_spokes(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == hub.ListSpokesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSpokesPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -1663,7 +1625,7 @@ def test_list_spokes_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1671,7 +1633,6 @@ def test_list_spokes_empty_call(): client.list_spokes() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == hub.ListSpokesRequest() @@ -1680,7 +1641,7 @@ async def test_list_spokes_async( transport: str = "grpc_asyncio", request_type=hub.ListSpokesRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1696,20 +1657,16 @@ async def test_list_spokes_async( unreachable=["unreachable_value"], ) ) - response = await client.list_spokes(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == hub.ListSpokesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListSpokesAsyncPager) - assert response.next_page_token == "next_page_token_value" - assert response.unreachable == ["unreachable_value"] @@ -1719,17 +1676,17 @@ async def test_list_spokes_async_from_dict(): def test_list_spokes_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.ListSpokesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_spokes), "__call__") as call: call.return_value = hub.ListSpokesResponse() - client.list_spokes(request) # Establish that the underlying gRPC stub method was called. @@ -1744,11 +1701,12 @@ def test_list_spokes_field_headers(): @pytest.mark.asyncio async def test_list_spokes_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.ListSpokesRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -1756,7 +1714,6 @@ async def test_list_spokes_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( hub.ListSpokesResponse() ) - await client.list_spokes(request) # Establish that the underlying gRPC stub method was called. @@ -1770,13 +1727,12 @@ async def test_list_spokes_field_headers_async(): def test_list_spokes_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_spokes), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = hub.ListSpokesResponse() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_spokes(parent="parent_value",) @@ -1785,12 +1741,11 @@ def test_list_spokes_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" def test_list_spokes_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1802,7 +1757,7 @@ def test_list_spokes_flattened_error(): @pytest.mark.asyncio async def test_list_spokes_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_spokes), "__call__") as call: @@ -1820,13 +1775,12 @@ async def test_list_spokes_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" @pytest.mark.asyncio async def test_list_spokes_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1837,7 +1791,7 @@ async def test_list_spokes_flattened_error_async(): def test_list_spokes_pager(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials,) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_spokes), "__call__") as call: @@ -1866,7 +1820,7 @@ def test_list_spokes_pager(): def test_list_spokes_pages(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials,) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_spokes), "__call__") as call: @@ -1887,7 +1841,7 @@ def test_list_spokes_pages(): @pytest.mark.asyncio async def test_list_spokes_async_pager(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1915,7 +1869,7 @@ async def test_list_spokes_async_pager(): @pytest.mark.asyncio async def test_list_spokes_async_pages(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials,) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1940,7 +1894,7 @@ async def test_list_spokes_async_pages(): def test_get_spoke(transport: str = "grpc", request_type=hub.GetSpokeRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1959,33 +1913,23 @@ def test_get_spoke(transport: str = "grpc", request_type=hub.GetSpokeRequest): unique_id="unique_id_value", state=hub.State.CREATING, ) - response = client.get_spoke(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == hub.GetSpokeRequest() # Establish that the response is the type that we expect. - assert isinstance(response, hub.Spoke) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.hub == "hub_value" - assert response.linked_vpn_tunnels == ["linked_vpn_tunnels_value"] - assert response.linked_interconnect_attachments == [ "linked_interconnect_attachments_value" ] - assert response.unique_id == "unique_id_value" - assert response.state == hub.State.CREATING @@ -1997,7 +1941,7 @@ def test_get_spoke_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2005,7 +1949,6 @@ def test_get_spoke_empty_call(): client.get_spoke() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == hub.GetSpokeRequest() @@ -2014,7 +1957,7 @@ async def test_get_spoke_async( transport: str = "grpc_asyncio", request_type=hub.GetSpokeRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2037,32 +1980,23 @@ async def test_get_spoke_async( state=hub.State.CREATING, ) ) - response = await client.get_spoke(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == hub.GetSpokeRequest() # Establish that the response is the type that we expect. assert isinstance(response, hub.Spoke) - assert response.name == "name_value" - assert response.description == "description_value" - assert response.hub == "hub_value" - assert response.linked_vpn_tunnels == ["linked_vpn_tunnels_value"] - assert response.linked_interconnect_attachments == [ "linked_interconnect_attachments_value" ] - assert response.unique_id == "unique_id_value" - assert response.state == hub.State.CREATING @@ -2072,17 +2006,17 @@ async def test_get_spoke_async_from_dict(): def test_get_spoke_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.GetSpokeRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_spoke), "__call__") as call: call.return_value = hub.Spoke() - client.get_spoke(request) # Establish that the underlying gRPC stub method was called. @@ -2097,17 +2031,17 @@ def test_get_spoke_field_headers(): @pytest.mark.asyncio async def test_get_spoke_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.GetSpokeRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_spoke), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(hub.Spoke()) - await client.get_spoke(request) # Establish that the underlying gRPC stub method was called. @@ -2121,13 +2055,12 @@ async def test_get_spoke_field_headers_async(): def test_get_spoke_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_spoke), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = hub.Spoke() - # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_spoke(name="name_value",) @@ -2136,12 +2069,11 @@ def test_get_spoke_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_get_spoke_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2153,7 +2085,7 @@ def test_get_spoke_flattened_error(): @pytest.mark.asyncio async def test_get_spoke_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_spoke), "__call__") as call: @@ -2169,13 +2101,12 @@ async def test_get_spoke_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_get_spoke_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2187,7 +2118,7 @@ async def test_get_spoke_flattened_error_async(): def test_create_spoke(transport: str = "grpc", request_type=hub.CreateSpokeRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2198,13 +2129,11 @@ def test_create_spoke(transport: str = "grpc", request_type=hub.CreateSpokeReque with mock.patch.object(type(client.transport.create_spoke), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.create_spoke(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == hub.CreateSpokeRequest() # Establish that the response is the type that we expect. @@ -2219,7 +2148,7 @@ def test_create_spoke_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2227,7 +2156,6 @@ def test_create_spoke_empty_call(): client.create_spoke() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == hub.CreateSpokeRequest() @@ -2236,7 +2164,7 @@ async def test_create_spoke_async( transport: str = "grpc_asyncio", request_type=hub.CreateSpokeRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2249,13 +2177,11 @@ async def test_create_spoke_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.create_spoke(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == hub.CreateSpokeRequest() # Establish that the response is the type that we expect. @@ -2268,17 +2194,17 @@ async def test_create_spoke_async_from_dict(): def test_create_spoke_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.CreateSpokeRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_spoke), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.create_spoke(request) # Establish that the underlying gRPC stub method was called. @@ -2293,11 +2219,12 @@ def test_create_spoke_field_headers(): @pytest.mark.asyncio async def test_create_spoke_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.CreateSpokeRequest() + request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2305,7 +2232,6 @@ async def test_create_spoke_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.create_spoke(request) # Establish that the underlying gRPC stub method was called. @@ -2319,13 +2245,12 @@ async def test_create_spoke_field_headers_async(): def test_create_spoke_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_spoke), "__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_spoke( @@ -2338,16 +2263,13 @@ def test_create_spoke_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].spoke == hub.Spoke(name="name_value") - assert args[0].spoke_id == "spoke_id_value" def test_create_spoke_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2362,7 +2284,7 @@ def test_create_spoke_flattened_error(): @pytest.mark.asyncio async def test_create_spoke_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_spoke), "__call__") as call: @@ -2384,17 +2306,14 @@ async def test_create_spoke_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].spoke == hub.Spoke(name="name_value") - assert args[0].spoke_id == "spoke_id_value" @pytest.mark.asyncio async def test_create_spoke_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2409,7 +2328,7 @@ async def test_create_spoke_flattened_error_async(): def test_update_spoke(transport: str = "grpc", request_type=hub.UpdateSpokeRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2420,13 +2339,11 @@ def test_update_spoke(transport: str = "grpc", request_type=hub.UpdateSpokeReque with mock.patch.object(type(client.transport.update_spoke), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.update_spoke(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == hub.UpdateSpokeRequest() # Establish that the response is the type that we expect. @@ -2441,7 +2358,7 @@ def test_update_spoke_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2449,7 +2366,6 @@ def test_update_spoke_empty_call(): client.update_spoke() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == hub.UpdateSpokeRequest() @@ -2458,7 +2374,7 @@ async def test_update_spoke_async( transport: str = "grpc_asyncio", request_type=hub.UpdateSpokeRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2471,13 +2387,11 @@ async def test_update_spoke_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.update_spoke(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == hub.UpdateSpokeRequest() # Establish that the response is the type that we expect. @@ -2490,17 +2404,17 @@ async def test_update_spoke_async_from_dict(): def test_update_spoke_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.UpdateSpokeRequest() + request.spoke.name = "spoke.name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_spoke), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.update_spoke(request) # Establish that the underlying gRPC stub method was called. @@ -2515,11 +2429,12 @@ def test_update_spoke_field_headers(): @pytest.mark.asyncio async def test_update_spoke_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.UpdateSpokeRequest() + request.spoke.name = "spoke.name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2527,7 +2442,6 @@ async def test_update_spoke_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.update_spoke(request) # Establish that the underlying gRPC stub method was called. @@ -2541,32 +2455,29 @@ async def test_update_spoke_field_headers_async(): def test_update_spoke_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_spoke), "__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.update_spoke( spoke=hub.Spoke(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_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].spoke == hub.Spoke(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) def test_update_spoke_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2574,13 +2485,13 @@ def test_update_spoke_flattened_error(): client.update_spoke( hub.UpdateSpokeRequest(), spoke=hub.Spoke(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio async def test_update_spoke_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_spoke), "__call__") as call: @@ -2594,22 +2505,20 @@ async def test_update_spoke_flattened_async(): # using the keyword arguments to the method. response = await client.update_spoke( spoke=hub.Spoke(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_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].spoke == hub.Spoke(name="name_value") - - assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) + assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) @pytest.mark.asyncio async def test_update_spoke_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2617,13 +2526,13 @@ async def test_update_spoke_flattened_error_async(): await client.update_spoke( hub.UpdateSpokeRequest(), spoke=hub.Spoke(name="name_value"), - update_mask=field_mask.FieldMask(paths=["paths_value"]), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) def test_delete_spoke(transport: str = "grpc", request_type=hub.DeleteSpokeRequest): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2634,13 +2543,11 @@ def test_delete_spoke(transport: str = "grpc", request_type=hub.DeleteSpokeReque with mock.patch.object(type(client.transport.delete_spoke), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_spoke(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == hub.DeleteSpokeRequest() # Establish that the response is the type that we expect. @@ -2655,7 +2562,7 @@ def test_delete_spoke_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 = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2663,7 +2570,6 @@ def test_delete_spoke_empty_call(): client.delete_spoke() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == hub.DeleteSpokeRequest() @@ -2672,7 +2578,7 @@ async def test_delete_spoke_async( transport: str = "grpc_asyncio", request_type=hub.DeleteSpokeRequest ): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2685,13 +2591,11 @@ async def test_delete_spoke_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.delete_spoke(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == hub.DeleteSpokeRequest() # Establish that the response is the type that we expect. @@ -2704,17 +2608,17 @@ async def test_delete_spoke_async_from_dict(): def test_delete_spoke_field_headers(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.DeleteSpokeRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_spoke), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_spoke(request) # Establish that the underlying gRPC stub method was called. @@ -2729,11 +2633,12 @@ def test_delete_spoke_field_headers(): @pytest.mark.asyncio async def test_delete_spoke_field_headers_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = hub.DeleteSpokeRequest() + request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. @@ -2741,7 +2646,6 @@ async def test_delete_spoke_field_headers_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.delete_spoke(request) # Establish that the underlying gRPC stub method was called. @@ -2755,13 +2659,12 @@ async def test_delete_spoke_field_headers_async(): def test_delete_spoke_flattened(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_spoke), "__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_spoke(name="name_value",) @@ -2770,12 +2673,11 @@ def test_delete_spoke_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" def test_delete_spoke_flattened_error(): - client = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2787,7 +2689,7 @@ def test_delete_spoke_flattened_error(): @pytest.mark.asyncio async def test_delete_spoke_flattened_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_spoke), "__call__") as call: @@ -2805,13 +2707,12 @@ async def test_delete_spoke_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" @pytest.mark.asyncio async def test_delete_spoke_flattened_error_async(): - client = HubServiceAsyncClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2824,16 +2725,16 @@ async def test_delete_spoke_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.HubServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = HubServiceClient( - 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.HubServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = HubServiceClient( @@ -2843,7 +2744,7 @@ def test_credentials_transport_error(): # It is an error to provide scopes and a transport instance. transport = transports.HubServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = HubServiceClient( @@ -2854,7 +2755,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.HubServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) client = HubServiceClient(transport=transport) assert client.transport is transport @@ -2863,13 +2764,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.HubServiceGrpcTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.HubServiceGrpcAsyncIOTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2881,23 +2782,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 = HubServiceClient(credentials=credentials.AnonymousCredentials(),) + client = HubServiceClient(credentials=ga_credentials.AnonymousCredentials(),) assert isinstance(client.transport, transports.HubServiceGrpcTransport,) def test_hub_service_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.HubServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2909,7 +2810,7 @@ def test_hub_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.HubServiceTransport( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2936,15 +2837,37 @@ def test_hub_service_base_transport(): transport.operations_client +@requires_google_auth_gte_1_25_0 def test_hub_service_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.networkconnectivity_v1alpha1.services.hub_service.transports.HubServiceTransport._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.HubServiceTransport( + 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",), + quota_project_id="octopus", + ) + + +@requires_google_auth_lt_1_25_0 +def test_hub_service_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.networkconnectivity_v1alpha1.services.hub_service.transports.HubServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HubServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) @@ -2957,19 +2880,33 @@ def test_hub_service_base_transport_with_credentials_file(): def test_hub_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(auth, "default") as adc, mock.patch( + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( "google.cloud.networkconnectivity_v1alpha1.services.hub_service.transports.HubServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (credentials.AnonymousCredentials(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.HubServiceTransport() adc.assert_called_once() +@requires_google_auth_gte_1_25_0 def test_hub_service_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) + HubServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@requires_google_auth_lt_1_25_0 +def test_hub_service_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) HubServiceClient() adc.assert_called_once_with( scopes=("https://www.googleapis.com/auth/cloud-platform",), @@ -2977,26 +2914,156 @@ def test_hub_service_auth_adc(): ) -def test_hub_service_transport_auth_adc(): +@pytest.mark.parametrize( + "transport_class", + [transports.HubServiceGrpcTransport, transports.HubServiceGrpcAsyncIOTransport,], +) +@requires_google_auth_gte_1_25_0 +def test_hub_service_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.HubServiceGrpcTransport( - 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",), + quota_project_id="octopus", ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.HubServiceGrpcTransport, transports.HubServiceGrpcAsyncIOTransport,], +) +@requires_google_auth_lt_1_25_0 +def test_hub_service_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",), quota_project_id="octopus", ) +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.HubServiceGrpcTransport, grpc_helpers), + (transports.HubServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_gte_1_26_0 +def test_hub_service_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( + "networkconnectivity.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="networkconnectivity.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.HubServiceGrpcTransport, grpc_helpers), + (transports.HubServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_hub_service_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( + "networkconnectivity.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.HubServiceGrpcTransport, grpc_helpers), + (transports.HubServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +@requires_api_core_lt_1_26_0 +def test_hub_service_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( + "networkconnectivity.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", [transports.HubServiceGrpcTransport, transports.HubServiceGrpcAsyncIOTransport], ) def test_hub_service_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: @@ -3035,7 +3102,7 @@ def test_hub_service_grpc_transport_client_cert_source_for_mtls(transport_class) def test_hub_service_host_no_port(): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="networkconnectivity.googleapis.com" ), @@ -3045,7 +3112,7 @@ def test_hub_service_host_no_port(): def test_hub_service_host_with_port(): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="networkconnectivity.googleapis.com:8000" ), @@ -3096,9 +3163,9 @@ def test_hub_service_transport_channel_mtls_with_client_cert_source(transport_cl 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", @@ -3171,7 +3238,7 @@ def test_hub_service_transport_channel_mtls_with_adc(transport_class): def test_hub_service_grpc_lro_client(): client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) transport = client.transport @@ -3184,7 +3251,7 @@ def test_hub_service_grpc_lro_client(): def test_hub_service_grpc_lro_async_client(): client = HubServiceAsyncClient( - credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) transport = client.transport @@ -3198,7 +3265,6 @@ def test_hub_service_grpc_lro_async_client(): def test_hub_path(): project = "squid" hub = "clam" - expected = "projects/{project}/locations/global/hubs/{hub}".format( project=project, hub=hub, ) @@ -3222,7 +3288,6 @@ def test_instance_path(): project = "oyster" zone = "nudibranch" instance = "cuttlefish" - expected = "projects/{project}/zones/{zone}/instances/{instance}".format( project=project, zone=zone, instance=instance, ) @@ -3247,7 +3312,6 @@ def test_interconnect_attachment_path(): project = "scallop" region = "abalone" resource_id = "squid" - expected = "projects/{project}/regions/{region}/interconnectAttachments/{resource_id}".format( project=project, region=region, resource_id=resource_id, ) @@ -3272,7 +3336,6 @@ def test_spoke_path(): project = "oyster" location = "nudibranch" spoke = "cuttlefish" - expected = "projects/{project}/locations/{location}/spokes/{spoke}".format( project=project, location=location, spoke=spoke, ) @@ -3297,7 +3360,6 @@ def test_vpn_tunnel_path(): project = "scallop" region = "abalone" resource_id = "squid" - expected = "projects/{project}/regions/{region}/vpnTunnels/{resource_id}".format( project=project, region=region, resource_id=resource_id, ) @@ -3320,7 +3382,6 @@ def test_parse_vpn_tunnel_path(): def test_common_billing_account_path(): billing_account = "oyster" - expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -3341,7 +3402,6 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder,) actual = HubServiceClient.common_folder_path(folder) assert expected == actual @@ -3360,7 +3420,6 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "winkle" - expected = "organizations/{organization}".format(organization=organization,) actual = HubServiceClient.common_organization_path(organization) assert expected == actual @@ -3379,7 +3438,6 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "scallop" - expected = "projects/{project}".format(project=project,) actual = HubServiceClient.common_project_path(project) assert expected == actual @@ -3399,7 +3457,6 @@ def test_parse_common_project_path(): def test_common_location_path(): project = "squid" location = "clam" - expected = "projects/{project}/locations/{location}".format( project=project, location=location, ) @@ -3426,7 +3483,7 @@ def test_client_withDEFAULT_CLIENT_INFO(): transports.HubServiceTransport, "_prep_wrapped_messages" ) as prep: client = HubServiceClient( - credentials=credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3435,6 +3492,6 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = HubServiceClient.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)