diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py index d5bf0f8d1fd3..385d19cbec82 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py @@ -17,6 +17,7 @@ import functools import re from typing import ( + Callable, Dict, Mapping, MutableMapping, @@ -216,7 +217,11 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, AttachedClustersTransport] = "grpc_asyncio", + transport: Optional[ + Union[ + str, AttachedClustersTransport, Callable[..., AttachedClustersTransport] + ] + ] = "grpc_asyncio", client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -228,9 +233,11 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.AttachedClustersTransport]): The - transport to use. If set to None, a transport is chosen - automatically. + transport (Optional[Union[str,AttachedClustersTransport,Callable[..., AttachedClustersTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport to use. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the AttachedClustersTransport constructor. + If set to None, a transport is chosen automatically. NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. @@ -394,8 +401,8 @@ async def sample_create_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, attached_cluster, attached_cluster_id]) if request is not None and has_flattened_params: raise ValueError( @@ -403,7 +410,10 @@ async def sample_create_attached_cluster(): "the individual field arguments should be set." ) - request = attached_service.CreateAttachedClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, attached_service.CreateAttachedClusterRequest): + request = attached_service.CreateAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -416,11 +426,9 @@ async def sample_create_attached_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_attached_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.create_attached_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -549,8 +557,8 @@ async def sample_update_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([attached_cluster, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -558,7 +566,10 @@ async def sample_update_attached_cluster(): "the individual field arguments should be set." ) - request = attached_service.UpdateAttachedClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, attached_service.UpdateAttachedClusterRequest): + request = attached_service.UpdateAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -569,11 +580,9 @@ async def sample_update_attached_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_attached_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.update_attached_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -704,8 +713,8 @@ async def sample_import_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, fleet_membership]) if request is not None and has_flattened_params: raise ValueError( @@ -713,7 +722,10 @@ async def sample_import_attached_cluster(): "the individual field arguments should be set." ) - request = attached_service.ImportAttachedClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, attached_service.ImportAttachedClusterRequest): + request = attached_service.ImportAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -724,11 +736,9 @@ async def sample_import_attached_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.import_attached_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.import_attached_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -832,8 +842,8 @@ async def sample_get_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -841,7 +851,10 @@ async def sample_get_attached_cluster(): "the individual field arguments should be set." ) - request = attached_service.GetAttachedClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, attached_service.GetAttachedClusterRequest): + request = attached_service.GetAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -850,20 +863,9 @@ async def sample_get_attached_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_attached_cluster, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_attached_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -964,8 +966,8 @@ async def sample_list_attached_clusters(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -973,7 +975,10 @@ async def sample_list_attached_clusters(): "the individual field arguments should be set." ) - request = attached_service.ListAttachedClustersRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, attached_service.ListAttachedClustersRequest): + request = attached_service.ListAttachedClustersRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -982,20 +987,9 @@ async def sample_list_attached_clusters(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_attached_clusters, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_attached_clusters + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1118,8 +1112,8 @@ async def sample_delete_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1127,7 +1121,10 @@ async def sample_delete_attached_cluster(): "the individual field arguments should be set." ) - request = attached_service.DeleteAttachedClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, attached_service.DeleteAttachedClusterRequest): + request = attached_service.DeleteAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1136,11 +1133,9 @@ async def sample_delete_attached_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_attached_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.delete_attached_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1243,8 +1238,8 @@ async def sample_get_attached_server_config(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1252,7 +1247,10 @@ async def sample_get_attached_server_config(): "the individual field arguments should be set." ) - request = attached_service.GetAttachedServerConfigRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, attached_service.GetAttachedServerConfigRequest): + request = attached_service.GetAttachedServerConfigRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1261,20 +1259,9 @@ async def sample_get_attached_server_config(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_attached_server_config, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_attached_server_config + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1395,8 +1382,8 @@ async def sample_generate_attached_cluster_install_manifest(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, attached_cluster_id]) if request is not None and has_flattened_params: raise ValueError( @@ -1404,9 +1391,14 @@ async def sample_generate_attached_cluster_install_manifest(): "the individual field arguments should be set." ) - request = attached_service.GenerateAttachedClusterInstallManifestRequest( - request - ) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance( + request, attached_service.GenerateAttachedClusterInstallManifestRequest + ): + request = attached_service.GenerateAttachedClusterInstallManifestRequest( + request + ) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1417,20 +1409,9 @@ async def sample_generate_attached_cluster_install_manifest(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.generate_attached_cluster_install_manifest, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.generate_attached_cluster_install_manifest + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1507,24 +1488,18 @@ async def sample_generate_attached_cluster_agent_token(): """ # Create or coerce a protobuf request object. - request = attached_service.GenerateAttachedClusterAgentTokenRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance( + request, attached_service.GenerateAttachedClusterAgentTokenRequest + ): + request = attached_service.GenerateAttachedClusterAgentTokenRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.generate_attached_cluster_agent_token, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.generate_attached_cluster_agent_token + ] # Certain fields should be provided within the metadata header; # add these here. diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py index 3054df6bdcff..4a5cb3726aec 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py @@ -17,6 +17,7 @@ import os import re from typing import ( + Callable, Dict, Mapping, MutableMapping, @@ -563,7 +564,11 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, AttachedClustersTransport]] = None, + transport: Optional[ + Union[ + str, AttachedClustersTransport, Callable[..., AttachedClustersTransport] + ] + ] = None, client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -575,9 +580,11 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, AttachedClustersTransport]): The - transport to use. If set to None, a transport is chosen - automatically. + transport (Optional[Union[str,AttachedClustersTransport,Callable[..., AttachedClustersTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the AttachedClustersTransport constructor. + If set to None, a transport is chosen automatically. NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. @@ -689,8 +696,16 @@ def __init__( api_key_value ) - Transport = type(self).get_transport_class(cast(str, transport)) - self._transport = Transport( + transport_init: Union[ + Type[AttachedClustersTransport], + Callable[..., AttachedClustersTransport], + ] = ( + type(self).get_transport_class(transport) + if isinstance(transport, str) or transport is None + else cast(Callable[..., AttachedClustersTransport], transport) + ) + # initialize with the provided callable or the passed in class + self._transport = transport_init( credentials=credentials, credentials_file=self._client_options.credentials_file, host=self._api_endpoint, @@ -819,8 +834,8 @@ def sample_create_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, attached_cluster, attached_cluster_id]) if request is not None and has_flattened_params: raise ValueError( @@ -828,10 +843,8 @@ def sample_create_attached_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.CreateAttachedClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, attached_service.CreateAttachedClusterRequest): request = attached_service.CreateAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -974,8 +987,8 @@ def sample_update_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([attached_cluster, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -983,10 +996,8 @@ def sample_update_attached_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.UpdateAttachedClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, attached_service.UpdateAttachedClusterRequest): request = attached_service.UpdateAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1129,8 +1140,8 @@ def sample_import_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, fleet_membership]) if request is not None and has_flattened_params: raise ValueError( @@ -1138,10 +1149,8 @@ def sample_import_attached_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.ImportAttachedClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, attached_service.ImportAttachedClusterRequest): request = attached_service.ImportAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1257,8 +1266,8 @@ def sample_get_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1266,10 +1275,8 @@ def sample_get_attached_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.GetAttachedClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, attached_service.GetAttachedClusterRequest): request = attached_service.GetAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1380,8 +1387,8 @@ def sample_list_attached_clusters(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -1389,10 +1396,8 @@ def sample_list_attached_clusters(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.ListAttachedClustersRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, attached_service.ListAttachedClustersRequest): request = attached_service.ListAttachedClustersRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1525,8 +1530,8 @@ def sample_delete_attached_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1534,10 +1539,8 @@ def sample_delete_attached_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.DeleteAttachedClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, attached_service.DeleteAttachedClusterRequest): request = attached_service.DeleteAttachedClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1650,8 +1653,8 @@ def sample_get_attached_server_config(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1659,10 +1662,8 @@ def sample_get_attached_server_config(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.GetAttachedServerConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, attached_service.GetAttachedServerConfigRequest): request = attached_service.GetAttachedServerConfigRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1795,8 +1796,8 @@ def sample_generate_attached_cluster_install_manifest(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, attached_cluster_id]) if request is not None and has_flattened_params: raise ValueError( @@ -1804,10 +1805,8 @@ def sample_generate_attached_cluster_install_manifest(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.GenerateAttachedClusterInstallManifestRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance( request, attached_service.GenerateAttachedClusterInstallManifestRequest ): @@ -1902,10 +1901,8 @@ def sample_generate_attached_cluster_agent_token(): """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a attached_service.GenerateAttachedClusterAgentTokenRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance( request, attached_service.GenerateAttachedClusterAgentTokenRequest ): diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py index d07fb2305fe7..a371160edef6 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py @@ -52,7 +52,7 @@ def __init__( credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: Optional[grpc.Channel] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, api_mtls_endpoint: Optional[str] = None, client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, @@ -72,14 +72,17 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. + ignored if a ``channel`` instance is provided. + channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from @@ -89,11 +92,11 @@ def __init__( private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if a ``channel`` instance is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -120,7 +123,7 @@ def __init__( if client_cert_source: warnings.warn("client_cert_source is deprecated", DeprecationWarning) - if channel: + if isinstance(channel, grpc.Channel): # Ignore credentials if a channel was passed. credentials = False # If a channel was explicitly provided, set it. @@ -161,7 +164,9 @@ def __init__( ) if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( self._host, # use the credentials which are saved credentials=self._credentials, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py index 61a185b9f8f2..ec90e9781e76 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py @@ -16,7 +16,9 @@ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 +from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,7 +69,6 @@ def create_channel( the credentials from the environment. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. scopes (Optional[Sequence[str]]): A optional list of scopes needed for this service. These are only used when credentials are not specified and are passed to :func:`google.auth.default`. @@ -97,7 +98,7 @@ def __init__( credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: Optional[aio.Channel] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, api_mtls_endpoint: Optional[str] = None, client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, @@ -117,15 +118,18 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. scopes (Optional[Sequence[str]]): A optional list of scopes needed for this service. These are only used when credentials are not specified and are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. + channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from @@ -135,11 +139,11 @@ def __init__( private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if a ``channel`` instance is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -166,7 +170,7 @@ def __init__( if client_cert_source: warnings.warn("client_cert_source is deprecated", DeprecationWarning) - if channel: + if isinstance(channel, aio.Channel): # Ignore credentials if a channel was passed. credentials = False # If a channel was explicitly provided, set it. @@ -206,7 +210,9 @@ def __init__( ) if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( self._host, # use the credentials which are saved credentials=self._credentials, @@ -546,6 +552,101 @@ def generate_attached_cluster_agent_token( ) return self._stubs["generate_attached_cluster_agent_token"] + def _prep_wrapped_messages(self, client_info): + """Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + self._wrapped_methods = { + self.create_attached_cluster: gapic_v1.method_async.wrap_method( + self.create_attached_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.update_attached_cluster: gapic_v1.method_async.wrap_method( + self.update_attached_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.import_attached_cluster: gapic_v1.method_async.wrap_method( + self.import_attached_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.get_attached_cluster: gapic_v1.method_async.wrap_method( + self.get_attached_cluster, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.list_attached_clusters: gapic_v1.method_async.wrap_method( + self.list_attached_clusters, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.delete_attached_cluster: gapic_v1.method_async.wrap_method( + self.delete_attached_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.get_attached_server_config: gapic_v1.method_async.wrap_method( + self.get_attached_server_config, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.generate_attached_cluster_install_manifest: gapic_v1.method_async.wrap_method( + self.generate_attached_cluster_install_manifest, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.generate_attached_cluster_agent_token: gapic_v1.method_async.wrap_method( + self.generate_attached_cluster_agent_token, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + } + def close(self): return self.grpc_channel.close() diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py index 21b2367f011b..4fe8faa418af 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py @@ -17,6 +17,7 @@ import functools import re from typing import ( + Callable, Dict, Mapping, MutableMapping, @@ -210,7 +211,9 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, AwsClustersTransport] = "grpc_asyncio", + transport: Optional[ + Union[str, AwsClustersTransport, Callable[..., AwsClustersTransport]] + ] = "grpc_asyncio", client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -222,9 +225,11 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.AwsClustersTransport]): The - transport to use. If set to None, a transport is chosen - automatically. + transport (Optional[Union[str,AwsClustersTransport,Callable[..., AwsClustersTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport to use. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the AwsClustersTransport constructor. + If set to None, a transport is chosen automatically. NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. @@ -393,8 +398,8 @@ async def sample_create_aws_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, aws_cluster, aws_cluster_id]) if request is not None and has_flattened_params: raise ValueError( @@ -402,7 +407,10 @@ async def sample_create_aws_cluster(): "the individual field arguments should be set." ) - request = aws_service.CreateAwsClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.CreateAwsClusterRequest): + request = aws_service.CreateAwsClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -415,11 +423,9 @@ async def sample_create_aws_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_aws_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.create_aws_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -570,8 +576,8 @@ async def sample_update_aws_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([aws_cluster, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -579,7 +585,10 @@ async def sample_update_aws_cluster(): "the individual field arguments should be set." ) - request = aws_service.UpdateAwsClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.UpdateAwsClusterRequest): + request = aws_service.UpdateAwsClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -590,11 +599,9 @@ async def sample_update_aws_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_aws_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.update_aws_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -695,8 +702,8 @@ async def sample_get_aws_cluster(): An Anthos cluster running on AWS. """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -704,7 +711,10 @@ async def sample_get_aws_cluster(): "the individual field arguments should be set." ) - request = aws_service.GetAwsClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.GetAwsClusterRequest): + request = aws_service.GetAwsClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -713,20 +723,9 @@ async def sample_get_aws_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_aws_cluster, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_aws_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -823,8 +822,8 @@ async def sample_list_aws_clusters(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -832,7 +831,10 @@ async def sample_list_aws_clusters(): "the individual field arguments should be set." ) - request = aws_service.ListAwsClustersRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.ListAwsClustersRequest): + request = aws_service.ListAwsClustersRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -841,20 +843,9 @@ async def sample_list_aws_clusters(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_aws_clusters, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_aws_clusters + ] # Certain fields should be provided within the metadata header; # add these here. @@ -978,8 +969,8 @@ async def sample_delete_aws_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -987,7 +978,10 @@ async def sample_delete_aws_cluster(): "the individual field arguments should be set." ) - request = aws_service.DeleteAwsClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.DeleteAwsClusterRequest): + request = aws_service.DeleteAwsClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -996,11 +990,9 @@ async def sample_delete_aws_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_aws_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.delete_aws_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1085,24 +1077,16 @@ async def sample_generate_aws_cluster_agent_token(): """ # Create or coerce a protobuf request object. - request = aws_service.GenerateAwsClusterAgentTokenRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.GenerateAwsClusterAgentTokenRequest): + request = aws_service.GenerateAwsClusterAgentTokenRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.generate_aws_cluster_agent_token, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.generate_aws_cluster_agent_token + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1182,24 +1166,16 @@ async def sample_generate_aws_access_token(): """ # Create or coerce a protobuf request object. - request = aws_service.GenerateAwsAccessTokenRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.GenerateAwsAccessTokenRequest): + request = aws_service.GenerateAwsAccessTokenRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.generate_aws_access_token, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.generate_aws_access_token + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1342,8 +1318,8 @@ async def sample_create_aws_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, aws_node_pool, aws_node_pool_id]) if request is not None and has_flattened_params: raise ValueError( @@ -1351,7 +1327,10 @@ async def sample_create_aws_node_pool(): "the individual field arguments should be set." ) - request = aws_service.CreateAwsNodePoolRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.CreateAwsNodePoolRequest): + request = aws_service.CreateAwsNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1364,11 +1343,9 @@ async def sample_create_aws_node_pool(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_aws_node_pool, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.create_aws_node_pool + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1518,8 +1495,8 @@ async def sample_update_aws_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([aws_node_pool, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -1527,7 +1504,10 @@ async def sample_update_aws_node_pool(): "the individual field arguments should be set." ) - request = aws_service.UpdateAwsNodePoolRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.UpdateAwsNodePoolRequest): + request = aws_service.UpdateAwsNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1538,11 +1518,9 @@ async def sample_update_aws_node_pool(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_aws_node_pool, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.update_aws_node_pool + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1657,8 +1635,8 @@ async def sample_rollback_aws_node_pool_update(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1666,7 +1644,10 @@ async def sample_rollback_aws_node_pool_update(): "the individual field arguments should be set." ) - request = aws_service.RollbackAwsNodePoolUpdateRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.RollbackAwsNodePoolUpdateRequest): + request = aws_service.RollbackAwsNodePoolUpdateRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1675,11 +1656,9 @@ async def sample_rollback_aws_node_pool_update(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.rollback_aws_node_pool_update, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.rollback_aws_node_pool_update + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1778,8 +1757,8 @@ async def sample_get_aws_node_pool(): An Anthos node pool running on AWS. """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1787,7 +1766,10 @@ async def sample_get_aws_node_pool(): "the individual field arguments should be set." ) - request = aws_service.GetAwsNodePoolRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.GetAwsNodePoolRequest): + request = aws_service.GetAwsNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1796,20 +1778,9 @@ async def sample_get_aws_node_pool(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_aws_node_pool, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_aws_node_pool + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1908,8 +1879,8 @@ async def sample_list_aws_node_pools(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -1917,7 +1888,10 @@ async def sample_list_aws_node_pools(): "the individual field arguments should be set." ) - request = aws_service.ListAwsNodePoolsRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.ListAwsNodePoolsRequest): + request = aws_service.ListAwsNodePoolsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1926,20 +1900,9 @@ async def sample_list_aws_node_pools(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_aws_node_pools, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_aws_node_pools + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2059,8 +2022,8 @@ async def sample_delete_aws_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2068,7 +2031,10 @@ async def sample_delete_aws_node_pool(): "the individual field arguments should be set." ) - request = aws_service.DeleteAwsNodePoolRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.DeleteAwsNodePoolRequest): + request = aws_service.DeleteAwsNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2077,11 +2043,9 @@ async def sample_delete_aws_node_pool(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_aws_node_pool, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.delete_aws_node_pool + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2171,24 +2135,16 @@ async def sample_get_aws_open_id_config(): """ # Create or coerce a protobuf request object. - request = aws_service.GetAwsOpenIdConfigRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.GetAwsOpenIdConfigRequest): + request = aws_service.GetAwsOpenIdConfigRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_aws_open_id_config, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_aws_open_id_config + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2269,24 +2225,16 @@ async def sample_get_aws_json_web_keys(): """ # Create or coerce a protobuf request object. - request = aws_service.GetAwsJsonWebKeysRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.GetAwsJsonWebKeysRequest): + request = aws_service.GetAwsJsonWebKeysRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_aws_json_web_keys, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_aws_json_web_keys + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2381,8 +2329,8 @@ async def sample_get_aws_server_config(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2390,7 +2338,10 @@ async def sample_get_aws_server_config(): "the individual field arguments should be set." ) - request = aws_service.GetAwsServerConfigRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, aws_service.GetAwsServerConfigRequest): + request = aws_service.GetAwsServerConfigRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2399,20 +2350,9 @@ async def sample_get_aws_server_config(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_aws_server_config, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_aws_server_config + ] # Certain fields should be provided within the metadata header; # add these here. diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py index 82e323f06f8f..befc2f2994d6 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py @@ -17,6 +17,7 @@ import os import re from typing import ( + Callable, Dict, Mapping, MutableMapping, @@ -587,7 +588,9 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, AwsClustersTransport]] = None, + transport: Optional[ + Union[str, AwsClustersTransport, Callable[..., AwsClustersTransport]] + ] = None, client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -599,9 +602,11 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, AwsClustersTransport]): The - transport to use. If set to None, a transport is chosen - automatically. + transport (Optional[Union[str,AwsClustersTransport,Callable[..., AwsClustersTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the AwsClustersTransport constructor. + If set to None, a transport is chosen automatically. NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. @@ -710,8 +715,15 @@ def __init__( api_key_value ) - Transport = type(self).get_transport_class(cast(str, transport)) - self._transport = Transport( + transport_init: Union[ + Type[AwsClustersTransport], Callable[..., AwsClustersTransport] + ] = ( + type(self).get_transport_class(transport) + if isinstance(transport, str) or transport is None + else cast(Callable[..., AwsClustersTransport], transport) + ) + # initialize with the provided callable or the passed in class + self._transport = transport_init( credentials=credentials, credentials_file=self._client_options.credentials_file, host=self._api_endpoint, @@ -845,8 +857,8 @@ def sample_create_aws_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, aws_cluster, aws_cluster_id]) if request is not None and has_flattened_params: raise ValueError( @@ -854,10 +866,8 @@ def sample_create_aws_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.CreateAwsClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.CreateAwsClusterRequest): request = aws_service.CreateAwsClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1022,8 +1032,8 @@ def sample_update_aws_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([aws_cluster, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -1031,10 +1041,8 @@ def sample_update_aws_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.UpdateAwsClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.UpdateAwsClusterRequest): request = aws_service.UpdateAwsClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1147,8 +1155,8 @@ def sample_get_aws_cluster(): An Anthos cluster running on AWS. """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1156,10 +1164,8 @@ def sample_get_aws_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.GetAwsClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.GetAwsClusterRequest): request = aws_service.GetAwsClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1266,8 +1272,8 @@ def sample_list_aws_clusters(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -1275,10 +1281,8 @@ def sample_list_aws_clusters(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.ListAwsClustersRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.ListAwsClustersRequest): request = aws_service.ListAwsClustersRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1412,8 +1416,8 @@ def sample_delete_aws_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1421,10 +1425,8 @@ def sample_delete_aws_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.DeleteAwsClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.DeleteAwsClusterRequest): request = aws_service.DeleteAwsClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1519,10 +1521,8 @@ def sample_generate_aws_cluster_agent_token(): """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.GenerateAwsClusterAgentTokenRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.GenerateAwsClusterAgentTokenRequest): request = aws_service.GenerateAwsClusterAgentTokenRequest(request) @@ -1610,10 +1610,8 @@ def sample_generate_aws_access_token(): """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.GenerateAwsAccessTokenRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.GenerateAwsAccessTokenRequest): request = aws_service.GenerateAwsAccessTokenRequest(request) @@ -1764,8 +1762,8 @@ def sample_create_aws_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, aws_node_pool, aws_node_pool_id]) if request is not None and has_flattened_params: raise ValueError( @@ -1773,10 +1771,8 @@ def sample_create_aws_node_pool(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.CreateAwsNodePoolRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.CreateAwsNodePoolRequest): request = aws_service.CreateAwsNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1940,8 +1936,8 @@ def sample_update_aws_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([aws_node_pool, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -1949,10 +1945,8 @@ def sample_update_aws_node_pool(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.UpdateAwsNodePoolRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.UpdateAwsNodePoolRequest): request = aws_service.UpdateAwsNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2079,8 +2073,8 @@ def sample_rollback_aws_node_pool_update(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2088,10 +2082,8 @@ def sample_rollback_aws_node_pool_update(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.RollbackAwsNodePoolUpdateRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.RollbackAwsNodePoolUpdateRequest): request = aws_service.RollbackAwsNodePoolUpdateRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2202,8 +2194,8 @@ def sample_get_aws_node_pool(): An Anthos node pool running on AWS. """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2211,10 +2203,8 @@ def sample_get_aws_node_pool(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.GetAwsNodePoolRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.GetAwsNodePoolRequest): request = aws_service.GetAwsNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2323,8 +2313,8 @@ def sample_list_aws_node_pools(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -2332,10 +2322,8 @@ def sample_list_aws_node_pools(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.ListAwsNodePoolsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.ListAwsNodePoolsRequest): request = aws_service.ListAwsNodePoolsRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2465,8 +2453,8 @@ def sample_delete_aws_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2474,10 +2462,8 @@ def sample_delete_aws_node_pool(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.DeleteAwsNodePoolRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.DeleteAwsNodePoolRequest): request = aws_service.DeleteAwsNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2577,10 +2563,8 @@ def sample_get_aws_open_id_config(): """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.GetAwsOpenIdConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.GetAwsOpenIdConfigRequest): request = aws_service.GetAwsOpenIdConfigRequest(request) @@ -2667,10 +2651,8 @@ def sample_get_aws_json_web_keys(): """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.GetAwsJsonWebKeysRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.GetAwsJsonWebKeysRequest): request = aws_service.GetAwsJsonWebKeysRequest(request) @@ -2771,8 +2753,8 @@ def sample_get_aws_server_config(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2780,10 +2762,8 @@ def sample_get_aws_server_config(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a aws_service.GetAwsServerConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, aws_service.GetAwsServerConfigRequest): request = aws_service.GetAwsServerConfigRequest(request) # If we have keyword arguments corresponding to fields on the diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py index 5b7c037c54a9..57bf181d7ee0 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py @@ -52,7 +52,7 @@ def __init__( credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: Optional[grpc.Channel] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, api_mtls_endpoint: Optional[str] = None, client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, @@ -72,14 +72,17 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. + ignored if a ``channel`` instance is provided. + channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from @@ -89,11 +92,11 @@ def __init__( private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if a ``channel`` instance is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -120,7 +123,7 @@ def __init__( if client_cert_source: warnings.warn("client_cert_source is deprecated", DeprecationWarning) - if channel: + if isinstance(channel, grpc.Channel): # Ignore credentials if a channel was passed. credentials = False # If a channel was explicitly provided, set it. @@ -161,7 +164,9 @@ def __init__( ) if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( self._host, # use the credentials which are saved credentials=self._credentials, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py index a2befee675cf..8f8ba44d75a0 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py @@ -16,7 +16,9 @@ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 +from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,7 +69,6 @@ def create_channel( the credentials from the environment. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. scopes (Optional[Sequence[str]]): A optional list of scopes needed for this service. These are only used when credentials are not specified and are passed to :func:`google.auth.default`. @@ -97,7 +98,7 @@ def __init__( credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: Optional[aio.Channel] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, api_mtls_endpoint: Optional[str] = None, client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, @@ -117,15 +118,18 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. scopes (Optional[Sequence[str]]): A optional list of scopes needed for this service. These are only used when credentials are not specified and are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. + channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from @@ -135,11 +139,11 @@ def __init__( private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if a ``channel`` instance is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -166,7 +170,7 @@ def __init__( if client_cert_source: warnings.warn("client_cert_source is deprecated", DeprecationWarning) - if channel: + if isinstance(channel, aio.Channel): # Ignore credentials if a channel was passed. credentials = False # If a channel was explicitly provided, set it. @@ -206,7 +210,9 @@ def __init__( ) if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( self._host, # use the credentials which are saved credentials=self._credentials, @@ -760,6 +766,172 @@ def get_aws_server_config( ) return self._stubs["get_aws_server_config"] + def _prep_wrapped_messages(self, client_info): + """Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + self._wrapped_methods = { + self.create_aws_cluster: gapic_v1.method_async.wrap_method( + self.create_aws_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.update_aws_cluster: gapic_v1.method_async.wrap_method( + self.update_aws_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.get_aws_cluster: gapic_v1.method_async.wrap_method( + self.get_aws_cluster, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.list_aws_clusters: gapic_v1.method_async.wrap_method( + self.list_aws_clusters, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.delete_aws_cluster: gapic_v1.method_async.wrap_method( + self.delete_aws_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.generate_aws_cluster_agent_token: gapic_v1.method_async.wrap_method( + self.generate_aws_cluster_agent_token, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.generate_aws_access_token: gapic_v1.method_async.wrap_method( + self.generate_aws_access_token, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.create_aws_node_pool: gapic_v1.method_async.wrap_method( + self.create_aws_node_pool, + default_timeout=60.0, + client_info=client_info, + ), + self.update_aws_node_pool: gapic_v1.method_async.wrap_method( + self.update_aws_node_pool, + default_timeout=60.0, + client_info=client_info, + ), + self.rollback_aws_node_pool_update: gapic_v1.method_async.wrap_method( + self.rollback_aws_node_pool_update, + default_timeout=60.0, + client_info=client_info, + ), + self.get_aws_node_pool: gapic_v1.method_async.wrap_method( + self.get_aws_node_pool, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.list_aws_node_pools: gapic_v1.method_async.wrap_method( + self.list_aws_node_pools, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.delete_aws_node_pool: gapic_v1.method_async.wrap_method( + self.delete_aws_node_pool, + default_timeout=60.0, + client_info=client_info, + ), + self.get_aws_open_id_config: gapic_v1.method_async.wrap_method( + self.get_aws_open_id_config, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.get_aws_json_web_keys: gapic_v1.method_async.wrap_method( + self.get_aws_json_web_keys, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.get_aws_server_config: gapic_v1.method_async.wrap_method( + self.get_aws_server_config, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + } + def close(self): return self.grpc_channel.close() diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py index a3bfe0675ff3..2fc5861b4452 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py @@ -17,6 +17,7 @@ import functools import re from typing import ( + Callable, Dict, Mapping, MutableMapping, @@ -222,7 +223,9 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, AzureClustersTransport] = "grpc_asyncio", + transport: Optional[ + Union[str, AzureClustersTransport, Callable[..., AzureClustersTransport]] + ] = "grpc_asyncio", client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -234,9 +237,11 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.AzureClustersTransport]): The - transport to use. If set to None, a transport is chosen - automatically. + transport (Optional[Union[str,AzureClustersTransport,Callable[..., AzureClustersTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport to use. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the AzureClustersTransport constructor. + If set to None, a transport is chosen automatically. NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. @@ -413,8 +418,8 @@ async def sample_create_azure_client(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, azure_client, azure_client_id]) if request is not None and has_flattened_params: raise ValueError( @@ -422,7 +427,10 @@ async def sample_create_azure_client(): "the individual field arguments should be set." ) - request = azure_service.CreateAzureClientRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.CreateAzureClientRequest): + request = azure_service.CreateAzureClientRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -435,11 +443,9 @@ async def sample_create_azure_client(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_azure_client, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.create_azure_client + ] # Certain fields should be provided within the metadata header; # add these here. @@ -555,8 +561,8 @@ async def sample_get_azure_client(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -564,7 +570,10 @@ async def sample_get_azure_client(): "the individual field arguments should be set." ) - request = azure_service.GetAzureClientRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.GetAzureClientRequest): + request = azure_service.GetAzureClientRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -573,20 +582,9 @@ async def sample_get_azure_client(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_azure_client, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_azure_client + ] # Certain fields should be provided within the metadata header; # add these here. @@ -685,8 +683,8 @@ async def sample_list_azure_clients(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -694,7 +692,10 @@ async def sample_list_azure_clients(): "the individual field arguments should be set." ) - request = azure_service.ListAzureClientsRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.ListAzureClientsRequest): + request = azure_service.ListAzureClientsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -703,20 +704,9 @@ async def sample_list_azure_clients(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_azure_clients, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_azure_clients + ] # Certain fields should be provided within the metadata header; # add these here. @@ -840,8 +830,8 @@ async def sample_delete_azure_client(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -849,7 +839,10 @@ async def sample_delete_azure_client(): "the individual field arguments should be set." ) - request = azure_service.DeleteAzureClientRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.DeleteAzureClientRequest): + request = azure_service.DeleteAzureClientRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -858,11 +851,9 @@ async def sample_delete_azure_client(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_azure_client, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.delete_azure_client + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1011,8 +1002,8 @@ async def sample_create_azure_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, azure_cluster, azure_cluster_id]) if request is not None and has_flattened_params: raise ValueError( @@ -1020,7 +1011,10 @@ async def sample_create_azure_cluster(): "the individual field arguments should be set." ) - request = azure_service.CreateAzureClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.CreateAzureClusterRequest): + request = azure_service.CreateAzureClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1033,11 +1027,9 @@ async def sample_create_azure_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_azure_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.create_azure_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1175,8 +1167,8 @@ async def sample_update_azure_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([azure_cluster, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -1184,7 +1176,10 @@ async def sample_update_azure_cluster(): "the individual field arguments should be set." ) - request = azure_service.UpdateAzureClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.UpdateAzureClusterRequest): + request = azure_service.UpdateAzureClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1195,11 +1190,9 @@ async def sample_update_azure_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_azure_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.update_azure_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1301,8 +1294,8 @@ async def sample_get_azure_cluster(): An Anthos cluster running on Azure. """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1310,7 +1303,10 @@ async def sample_get_azure_cluster(): "the individual field arguments should be set." ) - request = azure_service.GetAzureClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.GetAzureClusterRequest): + request = azure_service.GetAzureClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1319,20 +1315,9 @@ async def sample_get_azure_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_azure_cluster, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_azure_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1431,8 +1416,8 @@ async def sample_list_azure_clusters(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -1440,7 +1425,10 @@ async def sample_list_azure_clusters(): "the individual field arguments should be set." ) - request = azure_service.ListAzureClustersRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.ListAzureClustersRequest): + request = azure_service.ListAzureClustersRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1449,20 +1437,9 @@ async def sample_list_azure_clusters(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_azure_clusters, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_azure_clusters + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1587,8 +1564,8 @@ async def sample_delete_azure_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1596,7 +1573,10 @@ async def sample_delete_azure_cluster(): "the individual field arguments should be set." ) - request = azure_service.DeleteAzureClusterRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.DeleteAzureClusterRequest): + request = azure_service.DeleteAzureClusterRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1605,11 +1585,9 @@ async def sample_delete_azure_cluster(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_azure_cluster, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.delete_azure_cluster + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1694,24 +1672,16 @@ async def sample_generate_azure_cluster_agent_token(): """ # Create or coerce a protobuf request object. - request = azure_service.GenerateAzureClusterAgentTokenRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.GenerateAzureClusterAgentTokenRequest): + request = azure_service.GenerateAzureClusterAgentTokenRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.generate_azure_cluster_agent_token, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.generate_azure_cluster_agent_token + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1792,24 +1762,16 @@ async def sample_generate_azure_access_token(): """ # Create or coerce a protobuf request object. - request = azure_service.GenerateAzureAccessTokenRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.GenerateAzureAccessTokenRequest): + request = azure_service.GenerateAzureAccessTokenRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.generate_azure_access_token, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.generate_azure_access_token + ] # Certain fields should be provided within the metadata header; # add these here. @@ -1951,8 +1913,8 @@ async def sample_create_azure_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, azure_node_pool, azure_node_pool_id]) if request is not None and has_flattened_params: raise ValueError( @@ -1960,7 +1922,10 @@ async def sample_create_azure_node_pool(): "the individual field arguments should be set." ) - request = azure_service.CreateAzureNodePoolRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.CreateAzureNodePoolRequest): + request = azure_service.CreateAzureNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -1973,11 +1938,9 @@ async def sample_create_azure_node_pool(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_azure_node_pool, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.create_azure_node_pool + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2104,8 +2067,8 @@ async def sample_update_azure_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([azure_node_pool, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -2113,7 +2076,10 @@ async def sample_update_azure_node_pool(): "the individual field arguments should be set." ) - request = azure_service.UpdateAzureNodePoolRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.UpdateAzureNodePoolRequest): + request = azure_service.UpdateAzureNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2124,11 +2090,9 @@ async def sample_update_azure_node_pool(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_azure_node_pool, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.update_azure_node_pool + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2229,8 +2193,8 @@ async def sample_get_azure_node_pool(): An Anthos node pool running on Azure. """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2238,7 +2202,10 @@ async def sample_get_azure_node_pool(): "the individual field arguments should be set." ) - request = azure_service.GetAzureNodePoolRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.GetAzureNodePoolRequest): + request = azure_service.GetAzureNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2247,20 +2214,9 @@ async def sample_get_azure_node_pool(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_azure_node_pool, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_azure_node_pool + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2359,8 +2315,8 @@ async def sample_list_azure_node_pools(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -2368,7 +2324,10 @@ async def sample_list_azure_node_pools(): "the individual field arguments should be set." ) - request = azure_service.ListAzureNodePoolsRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.ListAzureNodePoolsRequest): + request = azure_service.ListAzureNodePoolsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2377,20 +2336,9 @@ async def sample_list_azure_node_pools(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_azure_node_pools, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_azure_node_pools + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2510,8 +2458,8 @@ async def sample_delete_azure_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2519,7 +2467,10 @@ async def sample_delete_azure_node_pool(): "the individual field arguments should be set." ) - request = azure_service.DeleteAzureNodePoolRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.DeleteAzureNodePoolRequest): + request = azure_service.DeleteAzureNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2528,11 +2479,9 @@ async def sample_delete_azure_node_pool(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_azure_node_pool, - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.delete_azure_node_pool + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2635,8 +2584,8 @@ async def sample_get_azure_open_id_config(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([azure_cluster]) if request is not None and has_flattened_params: raise ValueError( @@ -2644,7 +2593,10 @@ async def sample_get_azure_open_id_config(): "the individual field arguments should be set." ) - request = azure_service.GetAzureOpenIdConfigRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.GetAzureOpenIdConfigRequest): + request = azure_service.GetAzureOpenIdConfigRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2653,20 +2605,9 @@ async def sample_get_azure_open_id_config(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_azure_open_id_config, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_azure_open_id_config + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2736,10 +2677,9 @@ async def sample_get_azure_json_web_keys(): returned by getOpenIDConfig. See the OpenID Connect Discovery 1.0 specification for details. azure_cluster (:class:`str`): - Required. The AzureCluster, which - owns the JsonWebKeys. Format: - - projects//locations//azureClusters/ + Required. The AzureCluster, which owns the JsonWebKeys. + Format: + ``projects//locations//azureClusters/`` This corresponds to the ``azure_cluster`` field on the ``request`` instance; if ``request`` is provided, this @@ -2757,8 +2697,8 @@ async def sample_get_azure_json_web_keys(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([azure_cluster]) if request is not None and has_flattened_params: raise ValueError( @@ -2766,7 +2706,10 @@ async def sample_get_azure_json_web_keys(): "the individual field arguments should be set." ) - request = azure_service.GetAzureJsonWebKeysRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.GetAzureJsonWebKeysRequest): + request = azure_service.GetAzureJsonWebKeysRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2775,20 +2718,9 @@ async def sample_get_azure_json_web_keys(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_azure_json_web_keys, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_azure_json_web_keys + ] # Certain fields should be provided within the metadata header; # add these here. @@ -2887,8 +2819,8 @@ async def sample_get_azure_server_config(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2896,7 +2828,10 @@ async def sample_get_azure_server_config(): "the individual field arguments should be set." ) - request = azure_service.GetAzureServerConfigRequest(request) + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, azure_service.GetAzureServerConfigRequest): + request = azure_service.GetAzureServerConfigRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -2905,20 +2840,9 @@ async def sample_get_azure_server_config(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_azure_server_config, - default_retry=retries.AsyncRetry( - initial=1.0, - maximum=10.0, - multiplier=1.3, - predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_azure_server_config + ] # Certain fields should be provided within the metadata header; # add these here. diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py index 9b16eb8bbe05..97ee27260492 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py @@ -17,6 +17,7 @@ import os import re from typing import ( + Callable, Dict, Mapping, MutableMapping, @@ -607,7 +608,9 @@ def __init__( self, *, credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, AzureClustersTransport]] = None, + transport: Optional[ + Union[str, AzureClustersTransport, Callable[..., AzureClustersTransport]] + ] = None, client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -619,9 +622,11 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, AzureClustersTransport]): The - transport to use. If set to None, a transport is chosen - automatically. + transport (Optional[Union[str,AzureClustersTransport,Callable[..., AzureClustersTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the AzureClustersTransport constructor. + If set to None, a transport is chosen automatically. NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. @@ -733,8 +738,15 @@ def __init__( api_key_value ) - Transport = type(self).get_transport_class(cast(str, transport)) - self._transport = Transport( + transport_init: Union[ + Type[AzureClustersTransport], Callable[..., AzureClustersTransport] + ] = ( + type(self).get_transport_class(transport) + if isinstance(transport, str) or transport is None + else cast(Callable[..., AzureClustersTransport], transport) + ) + # initialize with the provided callable or the passed in class + self._transport = transport_init( credentials=credentials, credentials_file=self._client_options.credentials_file, host=self._api_endpoint, @@ -876,8 +888,8 @@ def sample_create_azure_client(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, azure_client, azure_client_id]) if request is not None and has_flattened_params: raise ValueError( @@ -885,10 +897,8 @@ def sample_create_azure_client(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.CreateAzureClientRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.CreateAzureClientRequest): request = azure_service.CreateAzureClientRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1018,8 +1028,8 @@ def sample_get_azure_client(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1027,10 +1037,8 @@ def sample_get_azure_client(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.GetAzureClientRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.GetAzureClientRequest): request = azure_service.GetAzureClientRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1139,8 +1147,8 @@ def sample_list_azure_clients(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -1148,10 +1156,8 @@ def sample_list_azure_clients(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.ListAzureClientsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.ListAzureClientsRequest): request = azure_service.ListAzureClientsRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1285,8 +1291,8 @@ def sample_delete_azure_client(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1294,10 +1300,8 @@ def sample_delete_azure_client(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.DeleteAzureClientRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.DeleteAzureClientRequest): request = azure_service.DeleteAzureClientRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1456,8 +1460,8 @@ def sample_create_azure_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, azure_cluster, azure_cluster_id]) if request is not None and has_flattened_params: raise ValueError( @@ -1465,10 +1469,8 @@ def sample_create_azure_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.CreateAzureClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.CreateAzureClusterRequest): request = azure_service.CreateAzureClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1620,8 +1622,8 @@ def sample_update_azure_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([azure_cluster, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -1629,10 +1631,8 @@ def sample_update_azure_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.UpdateAzureClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.UpdateAzureClusterRequest): request = azure_service.UpdateAzureClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1746,8 +1746,8 @@ def sample_get_azure_cluster(): An Anthos cluster running on Azure. """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -1755,10 +1755,8 @@ def sample_get_azure_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.GetAzureClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.GetAzureClusterRequest): request = azure_service.GetAzureClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -1867,8 +1865,8 @@ def sample_list_azure_clusters(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -1876,10 +1874,8 @@ def sample_list_azure_clusters(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.ListAzureClustersRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.ListAzureClustersRequest): request = azure_service.ListAzureClustersRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2014,8 +2010,8 @@ def sample_delete_azure_cluster(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2023,10 +2019,8 @@ def sample_delete_azure_cluster(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.DeleteAzureClusterRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.DeleteAzureClusterRequest): request = azure_service.DeleteAzureClusterRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2121,10 +2115,8 @@ def sample_generate_azure_cluster_agent_token(): """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.GenerateAzureClusterAgentTokenRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.GenerateAzureClusterAgentTokenRequest): request = azure_service.GenerateAzureClusterAgentTokenRequest(request) @@ -2213,10 +2205,8 @@ def sample_generate_azure_access_token(): """ # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.GenerateAzureAccessTokenRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.GenerateAzureAccessTokenRequest): request = azure_service.GenerateAzureAccessTokenRequest(request) @@ -2366,8 +2356,8 @@ def sample_create_azure_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, azure_node_pool, azure_node_pool_id]) if request is not None and has_flattened_params: raise ValueError( @@ -2375,10 +2365,8 @@ def sample_create_azure_node_pool(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.CreateAzureNodePoolRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.CreateAzureNodePoolRequest): request = azure_service.CreateAzureNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2519,8 +2507,8 @@ def sample_update_azure_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([azure_node_pool, update_mask]) if request is not None and has_flattened_params: raise ValueError( @@ -2528,10 +2516,8 @@ def sample_update_azure_node_pool(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.UpdateAzureNodePoolRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.UpdateAzureNodePoolRequest): request = azure_service.UpdateAzureNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2644,8 +2630,8 @@ def sample_get_azure_node_pool(): An Anthos node pool running on Azure. """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2653,10 +2639,8 @@ def sample_get_azure_node_pool(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.GetAzureNodePoolRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.GetAzureNodePoolRequest): request = azure_service.GetAzureNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2765,8 +2749,8 @@ def sample_list_azure_node_pools(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: raise ValueError( @@ -2774,10 +2758,8 @@ def sample_list_azure_node_pools(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.ListAzureNodePoolsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.ListAzureNodePoolsRequest): request = azure_service.ListAzureNodePoolsRequest(request) # If we have keyword arguments corresponding to fields on the @@ -2907,8 +2889,8 @@ def sample_delete_azure_node_pool(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -2916,10 +2898,8 @@ def sample_delete_azure_node_pool(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.DeleteAzureNodePoolRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.DeleteAzureNodePoolRequest): request = azure_service.DeleteAzureNodePoolRequest(request) # If we have keyword arguments corresponding to fields on the @@ -3032,8 +3012,8 @@ def sample_get_azure_open_id_config(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([azure_cluster]) if request is not None and has_flattened_params: raise ValueError( @@ -3041,10 +3021,8 @@ def sample_get_azure_open_id_config(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.GetAzureOpenIdConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.GetAzureOpenIdConfigRequest): request = azure_service.GetAzureOpenIdConfigRequest(request) # If we have keyword arguments corresponding to fields on the @@ -3124,10 +3102,9 @@ def sample_get_azure_json_web_keys(): returned by getOpenIDConfig. See the OpenID Connect Discovery 1.0 specification for details. azure_cluster (str): - Required. The AzureCluster, which - owns the JsonWebKeys. Format: - - projects//locations//azureClusters/ + Required. The AzureCluster, which owns the JsonWebKeys. + Format: + ``projects//locations//azureClusters/`` This corresponds to the ``azure_cluster`` field on the ``request`` instance; if ``request`` is provided, this @@ -3145,8 +3122,8 @@ def sample_get_azure_json_web_keys(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([azure_cluster]) if request is not None and has_flattened_params: raise ValueError( @@ -3154,10 +3131,8 @@ def sample_get_azure_json_web_keys(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.GetAzureJsonWebKeysRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.GetAzureJsonWebKeysRequest): request = azure_service.GetAzureJsonWebKeysRequest(request) # If we have keyword arguments corresponding to fields on the @@ -3266,8 +3241,8 @@ def sample_get_azure_server_config(): """ # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: raise ValueError( @@ -3275,10 +3250,8 @@ def sample_get_azure_server_config(): "the individual field arguments should be set." ) - # Minor optimization to avoid making a copy if the user passes - # in a azure_service.GetAzureServerConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. if not isinstance(request, azure_service.GetAzureServerConfigRequest): request = azure_service.GetAzureServerConfigRequest(request) # If we have keyword arguments corresponding to fields on the diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py index 64b72cfe5685..173431e30073 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py @@ -52,7 +52,7 @@ def __init__( credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: Optional[grpc.Channel] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, api_mtls_endpoint: Optional[str] = None, client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, @@ -72,14 +72,17 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. + ignored if a ``channel`` instance is provided. + channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from @@ -89,11 +92,11 @@ def __init__( private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if a ``channel`` instance is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -120,7 +123,7 @@ def __init__( if client_cert_source: warnings.warn("client_cert_source is deprecated", DeprecationWarning) - if channel: + if isinstance(channel, grpc.Channel): # Ignore credentials if a channel was passed. credentials = False # If a channel was explicitly provided, set it. @@ -161,7 +164,9 @@ def __init__( ) if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( self._host, # use the credentials which are saved credentials=self._credentials, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py index d3a0062d7041..ba08251da373 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py @@ -16,7 +16,9 @@ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union import warnings +from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, grpc_helpers_async, operations_v1 +from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,7 +69,6 @@ def create_channel( the credentials from the environment. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. scopes (Optional[Sequence[str]]): A optional list of scopes needed for this service. These are only used when credentials are not specified and are passed to :func:`google.auth.default`. @@ -97,7 +98,7 @@ def __init__( credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, - channel: Optional[aio.Channel] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, api_mtls_endpoint: Optional[str] = None, client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, @@ -117,15 +118,18 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. credentials_file (Optional[str]): A file with credentials that can be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. + This argument is ignored if a ``channel`` instance is provided. scopes (Optional[Sequence[str]]): A optional list of scopes needed for this service. These are only used when credentials are not specified and are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. + channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from @@ -135,11 +139,11 @@ def __init__( private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if a ``channel`` instance is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -166,7 +170,7 @@ def __init__( if client_cert_source: warnings.warn("client_cert_source is deprecated", DeprecationWarning) - if channel: + if isinstance(channel, aio.Channel): # Ignore credentials if a channel was passed. credentials = False # If a channel was explicitly provided, set it. @@ -206,7 +210,9 @@ def __init__( ) if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( self._host, # use the credentials which are saved credentials=self._credentials, @@ -866,6 +872,205 @@ def get_azure_server_config( ) return self._stubs["get_azure_server_config"] + def _prep_wrapped_messages(self, client_info): + """Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + self._wrapped_methods = { + self.create_azure_client: gapic_v1.method_async.wrap_method( + self.create_azure_client, + default_timeout=60.0, + client_info=client_info, + ), + self.get_azure_client: gapic_v1.method_async.wrap_method( + self.get_azure_client, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.list_azure_clients: gapic_v1.method_async.wrap_method( + self.list_azure_clients, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.delete_azure_client: gapic_v1.method_async.wrap_method( + self.delete_azure_client, + default_timeout=60.0, + client_info=client_info, + ), + self.create_azure_cluster: gapic_v1.method_async.wrap_method( + self.create_azure_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.update_azure_cluster: gapic_v1.method_async.wrap_method( + self.update_azure_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.get_azure_cluster: gapic_v1.method_async.wrap_method( + self.get_azure_cluster, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.list_azure_clusters: gapic_v1.method_async.wrap_method( + self.list_azure_clusters, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.delete_azure_cluster: gapic_v1.method_async.wrap_method( + self.delete_azure_cluster, + default_timeout=60.0, + client_info=client_info, + ), + self.generate_azure_cluster_agent_token: gapic_v1.method_async.wrap_method( + self.generate_azure_cluster_agent_token, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.generate_azure_access_token: gapic_v1.method_async.wrap_method( + self.generate_azure_access_token, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.create_azure_node_pool: gapic_v1.method_async.wrap_method( + self.create_azure_node_pool, + default_timeout=60.0, + client_info=client_info, + ), + self.update_azure_node_pool: gapic_v1.method_async.wrap_method( + self.update_azure_node_pool, + default_timeout=60.0, + client_info=client_info, + ), + self.get_azure_node_pool: gapic_v1.method_async.wrap_method( + self.get_azure_node_pool, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.list_azure_node_pools: gapic_v1.method_async.wrap_method( + self.list_azure_node_pools, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.delete_azure_node_pool: gapic_v1.method_async.wrap_method( + self.delete_azure_node_pool, + default_timeout=60.0, + client_info=client_info, + ), + self.get_azure_open_id_config: gapic_v1.method_async.wrap_method( + self.get_azure_open_id_config, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.get_azure_json_web_keys: gapic_v1.method_async.wrap_method( + self.get_azure_json_web_keys, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.get_azure_server_config: gapic_v1.method_async.wrap_method( + self.get_azure_server_config, + default_retry=retries.AsyncRetry( + initial=1.0, + maximum=10.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + } + def close(self): return self.grpc_channel.close() diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/types/aws_resources.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/types/aws_resources.py index 05d444c06d2e..73fbfa3225ab 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/types/aws_resources.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/types/aws_resources.py @@ -967,8 +967,8 @@ class AwsNodeConfig(proto.Message): up to 127 Unicode characters. Values can be up to 255 Unicode characters. iam_instance_profile (str): - Required. The name or ARN of the AWS IAM role - assigned to nodes in the pool. + Required. The name or ARN of the AWS IAM + instance profile to assign to nodes in the pool. image_type (str): Optional. The OS image type to use on node pool instances. Can be unspecified, or have a value of ``ubuntu``. diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/types/azure_service.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/types/azure_service.py index 71f112985c9b..742d769ef6bb 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/types/azure_service.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/types/azure_service.py @@ -293,6 +293,12 @@ class DeleteAzureClusterRequest(proto.Message): If the provided etag does not match the current etag of the cluster, the request will fail and an ABORTED error will be returned. + ignore_errors (bool): + Optional. If set to true, the deletion of + [AzureCluster][google.cloud.gkemulticloud.v1.AzureCluster] + resource will succeed even if errors occur during deleting + in cluster resources. Using this parameter may result in + orphaned resources in the cluster. """ name: str = proto.Field( @@ -311,6 +317,10 @@ class DeleteAzureClusterRequest(proto.Message): proto.STRING, number=4, ) + ignore_errors: bool = proto.Field( + proto.BOOL, + number=5, + ) class CreateAzureNodePoolRequest(proto.Message): @@ -545,6 +555,12 @@ class DeleteAzureNodePoolRequest(proto.Message): If the provided ETag does not match the current etag of the node pool, the request will fail and an ABORTED error will be returned. + ignore_errors (bool): + Optional. If set to true, the deletion of + [AzureNodePool][google.cloud.gkemulticloud.v1.AzureNodePool] + resource will succeed even if errors occur during deleting + in node pool resources. Using this parameter may result in + orphaned resources in the node pool. """ name: str = proto.Field( @@ -563,6 +579,10 @@ class DeleteAzureNodePoolRequest(proto.Message): proto.STRING, number=4, ) + ignore_errors: bool = proto.Field( + proto.BOOL, + number=5, + ) class GetAzureOpenIdConfigRequest(proto.Message): @@ -592,10 +612,9 @@ class GetAzureJsonWebKeysRequest(proto.Message): Attributes: azure_cluster (str): - Required. The AzureCluster, which owns the - JsonWebKeys. Format: - - projects//locations//azureClusters/ + Required. The AzureCluster, which owns the JsonWebKeys. + Format: + ``projects//locations//azureClusters/`` """ azure_cluster: str = proto.Field( diff --git a/packages/google-cloud-gke-multicloud/scripts/fixup_gke_multicloud_v1_keywords.py b/packages/google-cloud-gke-multicloud/scripts/fixup_gke_multicloud_v1_keywords.py index 3b068902ab06..cd48868cf598 100644 --- a/packages/google-cloud-gke-multicloud/scripts/fixup_gke_multicloud_v1_keywords.py +++ b/packages/google-cloud-gke-multicloud/scripts/fixup_gke_multicloud_v1_keywords.py @@ -49,8 +49,8 @@ class gke_multicloudCallTransformer(cst.CSTTransformer): 'delete_aws_cluster': ('name', 'validate_only', 'allow_missing', 'ignore_errors', 'etag', ), 'delete_aws_node_pool': ('name', 'validate_only', 'allow_missing', 'ignore_errors', 'etag', ), 'delete_azure_client': ('name', 'allow_missing', 'validate_only', ), - 'delete_azure_cluster': ('name', 'allow_missing', 'validate_only', 'etag', ), - 'delete_azure_node_pool': ('name', 'validate_only', 'allow_missing', 'etag', ), + 'delete_azure_cluster': ('name', 'allow_missing', 'validate_only', 'etag', 'ignore_errors', ), + 'delete_azure_node_pool': ('name', 'validate_only', 'allow_missing', 'etag', 'ignore_errors', ), 'generate_attached_cluster_agent_token': ('attached_cluster', 'subject_token', 'subject_token_type', 'version', 'grant_type', 'audience', 'scope', 'requested_token_type', 'options', ), 'generate_attached_cluster_install_manifest': ('parent', 'attached_cluster_id', 'platform_version', 'proxy_config', ), 'generate_aws_access_token': ('aws_cluster', ), diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py index 1a7da720c2ab..07640bee8cb8 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py @@ -1210,6 +1210,9 @@ def test_create_attached_cluster_empty_call(): with mock.patch.object( type(client.transport.create_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_attached_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1236,6 +1239,9 @@ def test_create_attached_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.create_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_attached_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -1245,6 +1251,50 @@ def test_create_attached_cluster_non_empty_request_with_auto_populated_field(): ) +def test_create_attached_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_attached_cluster + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_attached_cluster + ] = mock_rpc + request = {} + client.create_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_create_attached_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1268,6 +1318,56 @@ async def test_create_attached_cluster_empty_call_async(): assert args[0] == attached_service.CreateAttachedClusterRequest() +@pytest.mark.asyncio +async def test_create_attached_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.create_attached_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.create_attached_cluster + ] = mock_object + + request = {} + await client.create_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.create_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_create_attached_cluster_async( transport: str = "grpc_asyncio", @@ -1525,6 +1625,9 @@ def test_update_attached_cluster_empty_call(): with mock.patch.object( type(client.transport.update_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_attached_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1548,12 +1651,59 @@ def test_update_attached_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.update_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_attached_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == attached_service.UpdateAttachedClusterRequest() +def test_update_attached_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_attached_cluster + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_attached_cluster + ] = mock_rpc + request = {} + client.update_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_update_attached_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1577,6 +1727,56 @@ async def test_update_attached_cluster_empty_call_async(): assert args[0] == attached_service.UpdateAttachedClusterRequest() +@pytest.mark.asyncio +async def test_update_attached_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.update_attached_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.update_attached_cluster + ] = mock_object + + request = {} + await client.update_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.update_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_update_attached_cluster_async( transport: str = "grpc_asyncio", @@ -1824,6 +2024,9 @@ def test_import_attached_cluster_empty_call(): with mock.patch.object( type(client.transport.import_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.import_attached_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1852,6 +2055,9 @@ def test_import_attached_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.import_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.import_attached_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -1863,6 +2069,50 @@ def test_import_attached_cluster_non_empty_request_with_auto_populated_field(): ) +def test_import_attached_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.import_attached_cluster + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.import_attached_cluster + ] = mock_rpc + request = {} + client.import_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.import_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_import_attached_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1886,6 +2136,56 @@ async def test_import_attached_cluster_empty_call_async(): assert args[0] == attached_service.ImportAttachedClusterRequest() +@pytest.mark.asyncio +async def test_import_attached_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.import_attached_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.import_attached_cluster + ] = mock_object + + request = {} + await client.import_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.import_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_import_attached_cluster_async( transport: str = "grpc_asyncio", @@ -2154,6 +2454,9 @@ def test_get_attached_cluster_empty_call(): with mock.patch.object( type(client.transport.get_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_attached_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -2179,6 +2482,9 @@ def test_get_attached_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_attached_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -2187,6 +2493,45 @@ def test_get_attached_cluster_non_empty_request_with_auto_populated_field(): ) +def test_get_attached_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_attached_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_attached_cluster + ] = mock_rpc + request = {} + client.get_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_attached_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -2221,6 +2566,52 @@ async def test_get_attached_cluster_empty_call_async(): assert args[0] == attached_service.GetAttachedClusterRequest() +@pytest.mark.asyncio +async def test_get_attached_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_attached_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_attached_cluster + ] = mock_object + + request = {} + await client.get_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_attached_cluster_async( transport: str = "grpc_asyncio", @@ -2482,6 +2873,9 @@ def test_list_attached_clusters_empty_call(): with mock.patch.object( type(client.transport.list_attached_clusters), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_attached_clusters() call.assert_called() _, args, _ = call.mock_calls[0] @@ -2508,6 +2902,9 @@ def test_list_attached_clusters_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.list_attached_clusters), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_attached_clusters(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -2517,6 +2914,46 @@ def test_list_attached_clusters_non_empty_request_with_auto_populated_field(): ) +def test_list_attached_clusters_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_attached_clusters + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_attached_clusters + ] = mock_rpc + request = {} + client.list_attached_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_attached_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_list_attached_clusters_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -2542,6 +2979,52 @@ async def test_list_attached_clusters_empty_call_async(): assert args[0] == attached_service.ListAttachedClustersRequest() +@pytest.mark.asyncio +async def test_list_attached_clusters_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.list_attached_clusters + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.list_attached_clusters + ] = mock_object + + request = {} + await client.list_attached_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.list_attached_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_list_attached_clusters_async( transport: str = "grpc_asyncio", @@ -2980,6 +3463,9 @@ def test_delete_attached_cluster_empty_call(): with mock.patch.object( type(client.transport.delete_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_attached_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3006,6 +3492,9 @@ def test_delete_attached_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.delete_attached_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_attached_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3015,6 +3504,50 @@ def test_delete_attached_cluster_non_empty_request_with_auto_populated_field(): ) +def test_delete_attached_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_attached_cluster + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_attached_cluster + ] = mock_rpc + request = {} + client.delete_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_delete_attached_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3038,6 +3571,56 @@ async def test_delete_attached_cluster_empty_call_async(): assert args[0] == attached_service.DeleteAttachedClusterRequest() +@pytest.mark.asyncio +async def test_delete_attached_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.delete_attached_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.delete_attached_cluster + ] = mock_object + + request = {} + await client.delete_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.delete_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_delete_attached_cluster_async( transport: str = "grpc_asyncio", @@ -3278,6 +3861,9 @@ def test_get_attached_server_config_empty_call(): with mock.patch.object( type(client.transport.get_attached_server_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_attached_server_config() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3303,6 +3889,9 @@ def test_get_attached_server_config_non_empty_request_with_auto_populated_field( with mock.patch.object( type(client.transport.get_attached_server_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_attached_server_config(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3311,6 +3900,46 @@ def test_get_attached_server_config_non_empty_request_with_auto_populated_field( ) +def test_get_attached_server_config_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_attached_server_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_attached_server_config + ] = mock_rpc + request = {} + client.get_attached_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_attached_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_attached_server_config_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3336,6 +3965,52 @@ async def test_get_attached_server_config_empty_call_async(): assert args[0] == attached_service.GetAttachedServerConfigRequest() +@pytest.mark.asyncio +async def test_get_attached_server_config_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_attached_server_config + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_attached_server_config + ] = mock_object + + request = {} + await client.get_attached_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_attached_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_attached_server_config_async( transport: str = "grpc_asyncio", @@ -3585,6 +4260,9 @@ def test_generate_attached_cluster_install_manifest_empty_call(): with mock.patch.object( type(client.transport.generate_attached_cluster_install_manifest), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_attached_cluster_install_manifest() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3614,6 +4292,9 @@ def test_generate_attached_cluster_install_manifest_non_empty_request_with_auto_ with mock.patch.object( type(client.transport.generate_attached_cluster_install_manifest), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_attached_cluster_install_manifest(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3626,6 +4307,46 @@ def test_generate_attached_cluster_install_manifest_non_empty_request_with_auto_ ) +def test_generate_attached_cluster_install_manifest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_attached_cluster_install_manifest + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_attached_cluster_install_manifest + ] = mock_rpc + request = {} + client.generate_attached_cluster_install_manifest(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_attached_cluster_install_manifest(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_generate_attached_cluster_install_manifest_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3653,6 +4374,52 @@ async def test_generate_attached_cluster_install_manifest_empty_call_async(): ) +@pytest.mark.asyncio +async def test_generate_attached_cluster_install_manifest_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.generate_attached_cluster_install_manifest + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.generate_attached_cluster_install_manifest + ] = mock_object + + request = {} + await client.generate_attached_cluster_install_manifest(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.generate_attached_cluster_install_manifest(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_generate_attached_cluster_install_manifest_async( transport: str = "grpc_asyncio", @@ -3920,6 +4687,9 @@ def test_generate_attached_cluster_agent_token_empty_call(): with mock.patch.object( type(client.transport.generate_attached_cluster_agent_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_attached_cluster_agent_token() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3953,6 +4723,9 @@ def test_generate_attached_cluster_agent_token_non_empty_request_with_auto_popul with mock.patch.object( type(client.transport.generate_attached_cluster_agent_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_attached_cluster_agent_token(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3969,6 +4742,46 @@ def test_generate_attached_cluster_agent_token_non_empty_request_with_auto_popul ) +def test_generate_attached_cluster_agent_token_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_attached_cluster_agent_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_attached_cluster_agent_token + ] = mock_rpc + request = {} + client.generate_attached_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_attached_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_generate_attached_cluster_agent_token_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3996,6 +4809,52 @@ async def test_generate_attached_cluster_agent_token_empty_call_async(): assert args[0] == attached_service.GenerateAttachedClusterAgentTokenRequest() +@pytest.mark.asyncio +async def test_generate_attached_cluster_agent_token_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AttachedClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.generate_attached_cluster_agent_token + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.generate_attached_cluster_agent_token + ] = mock_object + + request = {} + await client.generate_attached_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.generate_attached_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_generate_attached_cluster_agent_token_async( transport: str = "grpc_asyncio", @@ -4246,6 +5105,51 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_create_attached_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_attached_cluster + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_attached_cluster + ] = mock_rpc + + request = {} + client.create_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_create_attached_cluster_rest_required_fields( request_type=attached_service.CreateAttachedClusterRequest, ): @@ -4649,6 +5553,51 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_update_attached_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_attached_cluster + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_attached_cluster + ] = mock_rpc + + request = {} + client.update_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_update_attached_cluster_rest_required_fields( request_type=attached_service.UpdateAttachedClusterRequest, ): @@ -4934,6 +5883,51 @@ def test_import_attached_cluster_rest(request_type): assert response.operation.name == "operations/spam" +def test_import_attached_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.import_attached_cluster + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.import_attached_cluster + ] = mock_rpc + + request = {} + client.import_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.import_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_import_attached_cluster_rest_required_fields( request_type=attached_service.ImportAttachedClusterRequest, ): @@ -5243,6 +6237,46 @@ def test_get_attached_cluster_rest(request_type): assert response.kubernetes_version == "kubernetes_version_value" +def test_get_attached_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_attached_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_attached_cluster + ] = mock_rpc + + request = {} + client.get_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_attached_cluster_rest_required_fields( request_type=attached_service.GetAttachedClusterRequest, ): @@ -5514,6 +6548,47 @@ def test_list_attached_clusters_rest(request_type): assert response.next_page_token == "next_page_token_value" +def test_list_attached_clusters_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_attached_clusters + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_attached_clusters + ] = mock_rpc + + request = {} + client.list_attached_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_attached_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_list_attached_clusters_rest_required_fields( request_type=attached_service.ListAttachedClustersRequest, ): @@ -5854,6 +6929,51 @@ def test_delete_attached_cluster_rest(request_type): assert response.operation.name == "operations/spam" +def test_delete_attached_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_attached_cluster + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_attached_cluster + ] = mock_rpc + + request = {} + client.delete_attached_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_attached_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_delete_attached_cluster_rest_required_fields( request_type=attached_service.DeleteAttachedClusterRequest, ): @@ -6141,6 +7261,47 @@ def test_get_attached_server_config_rest(request_type): assert response.name == "name_value" +def test_get_attached_server_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_attached_server_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_attached_server_config + ] = mock_rpc + + request = {} + client.get_attached_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_attached_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_attached_server_config_rest_required_fields( request_type=attached_service.GetAttachedServerConfigRequest, ): @@ -6417,6 +7578,47 @@ def test_generate_attached_cluster_install_manifest_rest(request_type): assert response.manifest == "manifest_value" +def test_generate_attached_cluster_install_manifest_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_attached_cluster_install_manifest + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_attached_cluster_install_manifest + ] = mock_rpc + + request = {} + client.generate_attached_cluster_install_manifest(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_attached_cluster_install_manifest(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_generate_attached_cluster_install_manifest_rest_required_fields( request_type=attached_service.GenerateAttachedClusterInstallManifestRequest, ): @@ -6767,6 +7969,47 @@ def test_generate_attached_cluster_agent_token_rest(request_type): assert response.token_type == "token_type_value" +def test_generate_attached_cluster_agent_token_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AttachedClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_attached_cluster_agent_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_attached_cluster_agent_token + ] = mock_rpc + + request = {} + client.generate_attached_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_attached_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_generate_attached_cluster_agent_token_rest_required_fields( request_type=attached_service.GenerateAttachedClusterAgentTokenRequest, ): diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py index 021cb7ac8b22..ec766359ea21 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py @@ -1143,6 +1143,9 @@ def test_create_aws_cluster_empty_call(): with mock.patch.object( type(client.transport.create_aws_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_aws_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1169,6 +1172,9 @@ def test_create_aws_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.create_aws_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_aws_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -1178,6 +1184,49 @@ def test_create_aws_cluster_non_empty_request_with_auto_populated_field(): ) +def test_create_aws_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_aws_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_aws_cluster + ] = mock_rpc + request = {} + client.create_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_create_aws_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1201,6 +1250,56 @@ async def test_create_aws_cluster_empty_call_async(): assert args[0] == aws_service.CreateAwsClusterRequest() +@pytest.mark.asyncio +async def test_create_aws_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.create_aws_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.create_aws_cluster + ] = mock_object + + request = {} + await client.create_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.create_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_create_aws_cluster_async( transport: str = "grpc_asyncio", request_type=aws_service.CreateAwsClusterRequest @@ -1457,6 +1556,9 @@ def test_update_aws_cluster_empty_call(): with mock.patch.object( type(client.transport.update_aws_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_aws_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1480,12 +1582,58 @@ def test_update_aws_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.update_aws_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_aws_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == aws_service.UpdateAwsClusterRequest() +def test_update_aws_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_aws_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_aws_cluster + ] = mock_rpc + request = {} + client.update_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_update_aws_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1509,6 +1657,56 @@ async def test_update_aws_cluster_empty_call_async(): assert args[0] == aws_service.UpdateAwsClusterRequest() +@pytest.mark.asyncio +async def test_update_aws_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.update_aws_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.update_aws_cluster + ] = mock_object + + request = {} + await client.update_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.update_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_update_aws_cluster_async( transport: str = "grpc_asyncio", request_type=aws_service.UpdateAwsClusterRequest @@ -1770,6 +1968,9 @@ def test_get_aws_cluster_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_aws_cluster), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1793,6 +1994,9 @@ def test_get_aws_cluster_non_empty_request_with_auto_populated_field(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_aws_cluster), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -1801,6 +2005,41 @@ def test_get_aws_cluster_non_empty_request_with_auto_populated_field(): ) +def test_get_aws_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_aws_cluster in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_aws_cluster] = mock_rpc + request = {} + client.get_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1832,6 +2071,52 @@ async def test_get_aws_cluster_empty_call_async(): assert args[0] == aws_service.GetAwsClusterRequest() +@pytest.mark.asyncio +async def test_get_aws_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_aws_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_aws_cluster + ] = mock_object + + request = {} + await client.get_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_cluster_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsClusterRequest @@ -2080,6 +2365,9 @@ def test_list_aws_clusters_empty_call(): with mock.patch.object( type(client.transport.list_aws_clusters), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_aws_clusters() call.assert_called() _, args, _ = call.mock_calls[0] @@ -2106,6 +2394,9 @@ def test_list_aws_clusters_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.list_aws_clusters), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_aws_clusters(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -2115,6 +2406,43 @@ def test_list_aws_clusters_non_empty_request_with_auto_populated_field(): ) +def test_list_aws_clusters_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_aws_clusters in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_aws_clusters + ] = mock_rpc + request = {} + client.list_aws_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_aws_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_list_aws_clusters_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -2140,6 +2468,52 @@ async def test_list_aws_clusters_empty_call_async(): assert args[0] == aws_service.ListAwsClustersRequest() +@pytest.mark.asyncio +async def test_list_aws_clusters_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.list_aws_clusters + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.list_aws_clusters + ] = mock_object + + request = {} + await client.list_aws_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.list_aws_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_list_aws_clusters_async( transport: str = "grpc_asyncio", request_type=aws_service.ListAwsClustersRequest @@ -2577,6 +2951,9 @@ def test_delete_aws_cluster_empty_call(): with mock.patch.object( type(client.transport.delete_aws_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_aws_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -2603,6 +2980,9 @@ def test_delete_aws_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.delete_aws_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_aws_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -2612,6 +2992,49 @@ def test_delete_aws_cluster_non_empty_request_with_auto_populated_field(): ) +def test_delete_aws_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_aws_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_aws_cluster + ] = mock_rpc + request = {} + client.delete_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_delete_aws_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -2635,6 +3058,56 @@ async def test_delete_aws_cluster_empty_call_async(): assert args[0] == aws_service.DeleteAwsClusterRequest() +@pytest.mark.asyncio +async def test_delete_aws_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.delete_aws_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.delete_aws_cluster + ] = mock_object + + request = {} + await client.delete_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.delete_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_delete_aws_cluster_async( transport: str = "grpc_asyncio", request_type=aws_service.DeleteAwsClusterRequest @@ -2878,6 +3351,9 @@ def test_generate_aws_cluster_agent_token_empty_call(): with mock.patch.object( type(client.transport.generate_aws_cluster_agent_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_aws_cluster_agent_token() call.assert_called() _, args, _ = call.mock_calls[0] @@ -2912,6 +3388,9 @@ def test_generate_aws_cluster_agent_token_non_empty_request_with_auto_populated_ with mock.patch.object( type(client.transport.generate_aws_cluster_agent_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_aws_cluster_agent_token(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -2929,6 +3408,46 @@ def test_generate_aws_cluster_agent_token_non_empty_request_with_auto_populated_ ) +def test_generate_aws_cluster_agent_token_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_aws_cluster_agent_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_aws_cluster_agent_token + ] = mock_rpc + request = {} + client.generate_aws_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_aws_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_generate_aws_cluster_agent_token_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -2956,6 +3475,52 @@ async def test_generate_aws_cluster_agent_token_empty_call_async(): assert args[0] == aws_service.GenerateAwsClusterAgentTokenRequest() +@pytest.mark.asyncio +async def test_generate_aws_cluster_agent_token_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.generate_aws_cluster_agent_token + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.generate_aws_cluster_agent_token + ] = mock_object + + request = {} + await client.generate_aws_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.generate_aws_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_generate_aws_cluster_agent_token_async( transport: str = "grpc_asyncio", @@ -3117,6 +3682,9 @@ def test_generate_aws_access_token_empty_call(): with mock.patch.object( type(client.transport.generate_aws_access_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_aws_access_token() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3142,6 +3710,9 @@ def test_generate_aws_access_token_non_empty_request_with_auto_populated_field() with mock.patch.object( type(client.transport.generate_aws_access_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_aws_access_token(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3150,6 +3721,46 @@ def test_generate_aws_access_token_non_empty_request_with_auto_populated_field() ) +def test_generate_aws_access_token_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_aws_access_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_aws_access_token + ] = mock_rpc + request = {} + client.generate_aws_access_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_aws_access_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_generate_aws_access_token_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3175,6 +3786,52 @@ async def test_generate_aws_access_token_empty_call_async(): assert args[0] == aws_service.GenerateAwsAccessTokenRequest() +@pytest.mark.asyncio +async def test_generate_aws_access_token_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.generate_aws_access_token + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.generate_aws_access_token + ] = mock_object + + request = {} + await client.generate_aws_access_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.generate_aws_access_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_generate_aws_access_token_async( transport: str = "grpc_asyncio", @@ -3329,6 +3986,9 @@ def test_create_aws_node_pool_empty_call(): with mock.patch.object( type(client.transport.create_aws_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_aws_node_pool() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3355,6 +4015,9 @@ def test_create_aws_node_pool_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.create_aws_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_aws_node_pool(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3364,6 +4027,49 @@ def test_create_aws_node_pool_non_empty_request_with_auto_populated_field(): ) +def test_create_aws_node_pool_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_aws_node_pool in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_aws_node_pool + ] = mock_rpc + request = {} + client.create_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_create_aws_node_pool_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3387,6 +4093,56 @@ async def test_create_aws_node_pool_empty_call_async(): assert args[0] == aws_service.CreateAwsNodePoolRequest() +@pytest.mark.asyncio +async def test_create_aws_node_pool_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.create_aws_node_pool + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.create_aws_node_pool + ] = mock_object + + request = {} + await client.create_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.create_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_create_aws_node_pool_async( transport: str = "grpc_asyncio", request_type=aws_service.CreateAwsNodePoolRequest @@ -3643,6 +4399,9 @@ def test_update_aws_node_pool_empty_call(): with mock.patch.object( type(client.transport.update_aws_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_aws_node_pool() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3666,12 +4425,58 @@ def test_update_aws_node_pool_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.update_aws_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_aws_node_pool(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == aws_service.UpdateAwsNodePoolRequest() +def test_update_aws_node_pool_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_aws_node_pool in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_aws_node_pool + ] = mock_rpc + request = {} + client.update_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_update_aws_node_pool_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3695,6 +4500,56 @@ async def test_update_aws_node_pool_empty_call_async(): assert args[0] == aws_service.UpdateAwsNodePoolRequest() +@pytest.mark.asyncio +async def test_update_aws_node_pool_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.update_aws_node_pool + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.update_aws_node_pool + ] = mock_object + + request = {} + await client.update_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.update_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_update_aws_node_pool_async( transport: str = "grpc_asyncio", request_type=aws_service.UpdateAwsNodePoolRequest @@ -3941,6 +4796,9 @@ def test_rollback_aws_node_pool_update_empty_call(): with mock.patch.object( type(client.transport.rollback_aws_node_pool_update), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.rollback_aws_node_pool_update() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3966,6 +4824,9 @@ def test_rollback_aws_node_pool_update_non_empty_request_with_auto_populated_fie with mock.patch.object( type(client.transport.rollback_aws_node_pool_update), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.rollback_aws_node_pool_update(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3974,6 +4835,50 @@ def test_rollback_aws_node_pool_update_non_empty_request_with_auto_populated_fie ) +def test_rollback_aws_node_pool_update_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.rollback_aws_node_pool_update + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.rollback_aws_node_pool_update + ] = mock_rpc + request = {} + client.rollback_aws_node_pool_update(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.rollback_aws_node_pool_update(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_rollback_aws_node_pool_update_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3997,6 +4902,56 @@ async def test_rollback_aws_node_pool_update_empty_call_async(): assert args[0] == aws_service.RollbackAwsNodePoolUpdateRequest() +@pytest.mark.asyncio +async def test_rollback_aws_node_pool_update_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.rollback_aws_node_pool_update + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.rollback_aws_node_pool_update + ] = mock_object + + request = {} + await client.rollback_aws_node_pool_update(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.rollback_aws_node_pool_update(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_rollback_aws_node_pool_update_async( transport: str = "grpc_asyncio", @@ -4249,6 +5204,9 @@ def test_get_aws_node_pool_empty_call(): with mock.patch.object( type(client.transport.get_aws_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_node_pool() call.assert_called() _, args, _ = call.mock_calls[0] @@ -4274,6 +5232,9 @@ def test_get_aws_node_pool_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_aws_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_node_pool(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -4282,6 +5243,43 @@ def test_get_aws_node_pool_non_empty_request_with_auto_populated_field(): ) +def test_get_aws_node_pool_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_aws_node_pool in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_aws_node_pool + ] = mock_rpc + request = {} + client.get_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_node_pool_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -4307,10 +5305,56 @@ async def test_get_aws_node_pool_empty_call_async(): etag="etag_value", ) ) - response = await client.get_aws_node_pool() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == aws_service.GetAwsNodePoolRequest() + response = await client.get_aws_node_pool() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == aws_service.GetAwsNodePoolRequest() + + +@pytest.mark.asyncio +async def test_get_aws_node_pool_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_aws_node_pool + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_aws_node_pool + ] = mock_object + + request = {} + await client.get_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 @pytest.mark.asyncio @@ -4567,6 +5611,9 @@ def test_list_aws_node_pools_empty_call(): with mock.patch.object( type(client.transport.list_aws_node_pools), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_aws_node_pools() call.assert_called() _, args, _ = call.mock_calls[0] @@ -4593,6 +5640,9 @@ def test_list_aws_node_pools_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.list_aws_node_pools), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_aws_node_pools(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -4602,6 +5652,45 @@ def test_list_aws_node_pools_non_empty_request_with_auto_populated_field(): ) +def test_list_aws_node_pools_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_aws_node_pools in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_aws_node_pools + ] = mock_rpc + request = {} + client.list_aws_node_pools(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_aws_node_pools(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_list_aws_node_pools_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -4627,6 +5716,52 @@ async def test_list_aws_node_pools_empty_call_async(): assert args[0] == aws_service.ListAwsNodePoolsRequest() +@pytest.mark.asyncio +async def test_list_aws_node_pools_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.list_aws_node_pools + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.list_aws_node_pools + ] = mock_object + + request = {} + await client.list_aws_node_pools(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.list_aws_node_pools(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_list_aws_node_pools_async( transport: str = "grpc_asyncio", request_type=aws_service.ListAwsNodePoolsRequest @@ -5064,6 +6199,9 @@ def test_delete_aws_node_pool_empty_call(): with mock.patch.object( type(client.transport.delete_aws_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_aws_node_pool() call.assert_called() _, args, _ = call.mock_calls[0] @@ -5090,6 +6228,9 @@ def test_delete_aws_node_pool_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.delete_aws_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_aws_node_pool(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -5099,6 +6240,49 @@ def test_delete_aws_node_pool_non_empty_request_with_auto_populated_field(): ) +def test_delete_aws_node_pool_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_aws_node_pool in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_aws_node_pool + ] = mock_rpc + request = {} + client.delete_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_delete_aws_node_pool_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -5122,6 +6306,56 @@ async def test_delete_aws_node_pool_empty_call_async(): assert args[0] == aws_service.DeleteAwsNodePoolRequest() +@pytest.mark.asyncio +async def test_delete_aws_node_pool_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.delete_aws_node_pool + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.delete_aws_node_pool + ] = mock_object + + request = {} + await client.delete_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.delete_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_delete_aws_node_pool_async( transport: str = "grpc_asyncio", request_type=aws_service.DeleteAwsNodePoolRequest @@ -5377,6 +6611,9 @@ def test_get_aws_open_id_config_empty_call(): with mock.patch.object( type(client.transport.get_aws_open_id_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_open_id_config() call.assert_called() _, args, _ = call.mock_calls[0] @@ -5402,6 +6639,9 @@ def test_get_aws_open_id_config_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_aws_open_id_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_open_id_config(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -5410,6 +6650,46 @@ def test_get_aws_open_id_config_non_empty_request_with_auto_populated_field(): ) +def test_get_aws_open_id_config_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_aws_open_id_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_aws_open_id_config + ] = mock_rpc + request = {} + client.get_aws_open_id_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_open_id_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_open_id_config_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -5443,6 +6723,52 @@ async def test_get_aws_open_id_config_empty_call_async(): assert args[0] == aws_service.GetAwsOpenIdConfigRequest() +@pytest.mark.asyncio +async def test_get_aws_open_id_config_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_aws_open_id_config + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_aws_open_id_config + ] = mock_object + + request = {} + await client.get_aws_open_id_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_aws_open_id_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_open_id_config_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsOpenIdConfigRequest @@ -5612,6 +6938,9 @@ def test_get_aws_json_web_keys_empty_call(): with mock.patch.object( type(client.transport.get_aws_json_web_keys), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_json_web_keys() call.assert_called() _, args, _ = call.mock_calls[0] @@ -5637,6 +6966,9 @@ def test_get_aws_json_web_keys_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_aws_json_web_keys), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_json_web_keys(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -5645,6 +6977,46 @@ def test_get_aws_json_web_keys_non_empty_request_with_auto_populated_field(): ) +def test_get_aws_json_web_keys_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_aws_json_web_keys + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_aws_json_web_keys + ] = mock_rpc + request = {} + client.get_aws_json_web_keys(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_json_web_keys(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_json_web_keys_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -5668,6 +7040,52 @@ async def test_get_aws_json_web_keys_empty_call_async(): assert args[0] == aws_service.GetAwsJsonWebKeysRequest() +@pytest.mark.asyncio +async def test_get_aws_json_web_keys_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_aws_json_web_keys + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_aws_json_web_keys + ] = mock_object + + request = {} + await client.get_aws_json_web_keys(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_aws_json_web_keys(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_json_web_keys_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsJsonWebKeysRequest @@ -5823,6 +7241,9 @@ def test_get_aws_server_config_empty_call(): with mock.patch.object( type(client.transport.get_aws_server_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_server_config() call.assert_called() _, args, _ = call.mock_calls[0] @@ -5848,6 +7269,9 @@ def test_get_aws_server_config_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_aws_server_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_aws_server_config(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -5856,6 +7280,46 @@ def test_get_aws_server_config_non_empty_request_with_auto_populated_field(): ) +def test_get_aws_server_config_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_aws_server_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_aws_server_config + ] = mock_rpc + request = {} + client.get_aws_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_server_config_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -5882,6 +7346,52 @@ async def test_get_aws_server_config_empty_call_async(): assert args[0] == aws_service.GetAwsServerConfigRequest() +@pytest.mark.asyncio +async def test_get_aws_server_config_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AwsClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_aws_server_config + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_aws_server_config + ] = mock_object + + request = {} + await client.get_aws_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_aws_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_aws_server_config_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsServerConfigRequest @@ -6249,6 +7759,50 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_create_aws_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_aws_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_aws_cluster + ] = mock_rpc + + request = {} + client.create_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_create_aws_cluster_rest_required_fields( request_type=aws_service.CreateAwsClusterRequest, ): @@ -6684,8 +8238,52 @@ def get_message_fields(field): req.return_value = response_value response = client.update_aws_cluster(request) - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_update_aws_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_aws_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_aws_cluster + ] = mock_rpc + + request = {} + client.update_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 def test_update_aws_cluster_rest_required_fields( @@ -6994,6 +8592,42 @@ def test_get_aws_cluster_rest(request_type): assert response.cluster_ca_certificate == "cluster_ca_certificate_value" +def test_get_aws_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_aws_cluster in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_aws_cluster] = mock_rpc + + request = {} + client.get_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_aws_cluster_rest_required_fields( request_type=aws_service.GetAwsClusterRequest, ): @@ -7263,6 +8897,44 @@ def test_list_aws_clusters_rest(request_type): assert response.next_page_token == "next_page_token_value" +def test_list_aws_clusters_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_aws_clusters in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_aws_clusters + ] = mock_rpc + + request = {} + client.list_aws_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_aws_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_list_aws_clusters_rest_required_fields( request_type=aws_service.ListAwsClustersRequest, ): @@ -7597,6 +9269,50 @@ def test_delete_aws_cluster_rest(request_type): assert response.operation.name == "operations/spam" +def test_delete_aws_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_aws_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_aws_cluster + ] = mock_rpc + + request = {} + client.delete_aws_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_aws_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_delete_aws_cluster_rest_required_fields( request_type=aws_service.DeleteAwsClusterRequest, ): @@ -7888,6 +9604,47 @@ def test_generate_aws_cluster_agent_token_rest(request_type): assert response.token_type == "token_type_value" +def test_generate_aws_cluster_agent_token_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_aws_cluster_agent_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_aws_cluster_agent_token + ] = mock_rpc + + request = {} + client.generate_aws_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_aws_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_generate_aws_cluster_agent_token_rest_required_fields( request_type=aws_service.GenerateAwsClusterAgentTokenRequest, ): @@ -8132,6 +9889,47 @@ def test_generate_aws_access_token_rest(request_type): assert response.access_token == "access_token_value" +def test_generate_aws_access_token_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_aws_access_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_aws_access_token + ] = mock_rpc + + request = {} + client.generate_aws_access_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_aws_access_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_generate_aws_access_token_rest_required_fields( request_type=aws_service.GenerateAwsAccessTokenRequest, ): @@ -8458,6 +10256,50 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_create_aws_node_pool_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_aws_node_pool in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_aws_node_pool + ] = mock_rpc + + request = {} + client.create_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_create_aws_node_pool_rest_required_fields( request_type=aws_service.CreateAwsNodePoolRequest, ): @@ -8880,6 +10722,50 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_update_aws_node_pool_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_aws_node_pool in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_aws_node_pool + ] = mock_rpc + + request = {} + client.update_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_update_aws_node_pool_rest_required_fields( request_type=aws_service.UpdateAwsNodePoolRequest, ): @@ -9167,6 +11053,51 @@ def test_rollback_aws_node_pool_update_rest(request_type): assert response.operation.name == "operations/spam" +def test_rollback_aws_node_pool_update_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.rollback_aws_node_pool_update + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.rollback_aws_node_pool_update + ] = mock_rpc + + request = {} + client.rollback_aws_node_pool_update(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.rollback_aws_node_pool_update(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_rollback_aws_node_pool_update_rest_required_fields( request_type=aws_service.RollbackAwsNodePoolUpdateRequest, ): @@ -9452,6 +11383,44 @@ def test_get_aws_node_pool_rest(request_type): assert response.etag == "etag_value" +def test_get_aws_node_pool_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_aws_node_pool in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_aws_node_pool + ] = mock_rpc + + request = {} + client.get_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_aws_node_pool_rest_required_fields( request_type=aws_service.GetAwsNodePoolRequest, ): @@ -9723,6 +11692,46 @@ def test_list_aws_node_pools_rest(request_type): assert response.next_page_token == "next_page_token_value" +def test_list_aws_node_pools_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_aws_node_pools in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_aws_node_pools + ] = mock_rpc + + request = {} + client.list_aws_node_pools(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_aws_node_pools(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_list_aws_node_pools_rest_required_fields( request_type=aws_service.ListAwsNodePoolsRequest, ): @@ -10063,6 +12072,50 @@ def test_delete_aws_node_pool_rest(request_type): assert response.operation.name == "operations/spam" +def test_delete_aws_node_pool_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_aws_node_pool in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_aws_node_pool + ] = mock_rpc + + request = {} + client.delete_aws_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_aws_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_delete_aws_node_pool_rest_required_fields( request_type=aws_service.DeleteAwsNodePoolRequest, ): @@ -10368,6 +12421,47 @@ def test_get_aws_open_id_config_rest(request_type): assert response.grant_types == ["grant_types_value"] +def test_get_aws_open_id_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_aws_open_id_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_aws_open_id_config + ] = mock_rpc + + request = {} + client.get_aws_open_id_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_open_id_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_aws_open_id_config_rest_required_fields( request_type=aws_service.GetAwsOpenIdConfigRequest, ): @@ -10579,6 +12673,47 @@ def test_get_aws_json_web_keys_rest(request_type): assert isinstance(response, aws_resources.AwsJsonWebKeys) +def test_get_aws_json_web_keys_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_aws_json_web_keys + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_aws_json_web_keys + ] = mock_rpc + + request = {} + client.get_aws_json_web_keys(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_json_web_keys(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_aws_json_web_keys_rest_required_fields( request_type=aws_service.GetAwsJsonWebKeysRequest, ): @@ -10793,6 +12928,47 @@ def test_get_aws_server_config_rest(request_type): assert response.supported_aws_regions == ["supported_aws_regions_value"] +def test_get_aws_server_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AwsClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_aws_server_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_aws_server_config + ] = mock_rpc + + request = {} + client.get_aws_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_aws_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_aws_server_config_rest_required_fields( request_type=aws_service.GetAwsServerConfigRequest, ): diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py index 6e0a2a5dcb17..bbfb426ce85a 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py @@ -1176,6 +1176,9 @@ def test_create_azure_client_empty_call(): with mock.patch.object( type(client.transport.create_azure_client), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_azure_client() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1202,6 +1205,9 @@ def test_create_azure_client_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.create_azure_client), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_azure_client(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -1211,6 +1217,49 @@ def test_create_azure_client_non_empty_request_with_auto_populated_field(): ) +def test_create_azure_client_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_azure_client in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_azure_client + ] = mock_rpc + request = {} + client.create_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_create_azure_client_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1234,6 +1283,56 @@ async def test_create_azure_client_empty_call_async(): assert args[0] == azure_service.CreateAzureClientRequest() +@pytest.mark.asyncio +async def test_create_azure_client_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.create_azure_client + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.create_azure_client + ] = mock_object + + request = {} + await client.create_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.create_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_create_azure_client_async( transport: str = "grpc_asyncio", request_type=azure_service.CreateAzureClientRequest @@ -1499,6 +1598,9 @@ def test_get_azure_client_empty_call(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_azure_client), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_client() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1522,6 +1624,9 @@ def test_get_azure_client_non_empty_request_with_auto_populated_field(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_azure_client), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_client(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -1530,6 +1635,43 @@ def test_get_azure_client_non_empty_request_with_auto_populated_field(): ) +def test_get_azure_client_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_azure_client in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_client + ] = mock_rpc + request = {} + client.get_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_client_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1558,6 +1700,52 @@ async def test_get_azure_client_empty_call_async(): assert args[0] == azure_service.GetAzureClientRequest() +@pytest.mark.asyncio +async def test_get_azure_client_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_azure_client + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_azure_client + ] = mock_object + + request = {} + await client.get_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_client_async( transport: str = "grpc_asyncio", request_type=azure_service.GetAzureClientRequest @@ -1800,6 +1988,9 @@ def test_list_azure_clients_empty_call(): with mock.patch.object( type(client.transport.list_azure_clients), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_azure_clients() call.assert_called() _, args, _ = call.mock_calls[0] @@ -1826,6 +2017,9 @@ def test_list_azure_clients_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.list_azure_clients), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_azure_clients(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -1835,6 +2029,45 @@ def test_list_azure_clients_non_empty_request_with_auto_populated_field(): ) +def test_list_azure_clients_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_azure_clients in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_azure_clients + ] = mock_rpc + request = {} + client.list_azure_clients(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_azure_clients(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_list_azure_clients_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -1860,6 +2093,52 @@ async def test_list_azure_clients_empty_call_async(): assert args[0] == azure_service.ListAzureClientsRequest() +@pytest.mark.asyncio +async def test_list_azure_clients_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.list_azure_clients + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.list_azure_clients + ] = mock_object + + request = {} + await client.list_azure_clients(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.list_azure_clients(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_list_azure_clients_async( transport: str = "grpc_asyncio", request_type=azure_service.ListAzureClientsRequest @@ -2297,6 +2576,9 @@ def test_delete_azure_client_empty_call(): with mock.patch.object( type(client.transport.delete_azure_client), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_azure_client() call.assert_called() _, args, _ = call.mock_calls[0] @@ -2322,6 +2604,9 @@ def test_delete_azure_client_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.delete_azure_client), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_azure_client(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -2330,6 +2615,49 @@ def test_delete_azure_client_non_empty_request_with_auto_populated_field(): ) +def test_delete_azure_client_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_azure_client in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_azure_client + ] = mock_rpc + request = {} + client.delete_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_delete_azure_client_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -2353,6 +2681,56 @@ async def test_delete_azure_client_empty_call_async(): assert args[0] == azure_service.DeleteAzureClientRequest() +@pytest.mark.asyncio +async def test_delete_azure_client_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.delete_azure_client + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.delete_azure_client + ] = mock_object + + request = {} + await client.delete_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.delete_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_delete_azure_client_async( transport: str = "grpc_asyncio", request_type=azure_service.DeleteAzureClientRequest @@ -2589,6 +2967,9 @@ def test_create_azure_cluster_empty_call(): with mock.patch.object( type(client.transport.create_azure_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_azure_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -2615,6 +2996,9 @@ def test_create_azure_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.create_azure_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_azure_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -2624,6 +3008,49 @@ def test_create_azure_cluster_non_empty_request_with_auto_populated_field(): ) +def test_create_azure_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_azure_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_azure_cluster + ] = mock_rpc + request = {} + client.create_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_create_azure_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -2647,6 +3074,56 @@ async def test_create_azure_cluster_empty_call_async(): assert args[0] == azure_service.CreateAzureClusterRequest() +@pytest.mark.asyncio +async def test_create_azure_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.create_azure_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.create_azure_cluster + ] = mock_object + + request = {} + await client.create_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.create_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_create_azure_cluster_async( transport: str = "grpc_asyncio", @@ -2904,6 +3381,9 @@ def test_update_azure_cluster_empty_call(): with mock.patch.object( type(client.transport.update_azure_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_azure_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -2927,12 +3407,58 @@ def test_update_azure_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.update_azure_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_azure_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == azure_service.UpdateAzureClusterRequest() +def test_update_azure_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_azure_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_azure_cluster + ] = mock_rpc + request = {} + client.update_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_update_azure_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -2956,6 +3482,56 @@ async def test_update_azure_cluster_empty_call_async(): assert args[0] == azure_service.UpdateAzureClusterRequest() +@pytest.mark.asyncio +async def test_update_azure_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.update_azure_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.update_azure_cluster + ] = mock_object + + request = {} + await client.update_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.update_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_update_azure_cluster_async( transport: str = "grpc_asyncio", @@ -3226,6 +3802,9 @@ def test_get_azure_cluster_empty_call(): with mock.patch.object( type(client.transport.get_azure_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3251,6 +3830,9 @@ def test_get_azure_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_azure_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3259,14 +3841,51 @@ def test_get_azure_cluster_non_empty_request_with_auto_populated_field(): ) -@pytest.mark.asyncio -async def test_get_azure_cluster_empty_call_async(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) +def test_get_azure_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_azure_cluster in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_cluster + ] = mock_rpc + request = {} + client.get_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_get_azure_cluster_empty_call_async(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3294,6 +3913,52 @@ async def test_get_azure_cluster_empty_call_async(): assert args[0] == azure_service.GetAzureClusterRequest() +@pytest.mark.asyncio +async def test_get_azure_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_azure_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_azure_cluster + ] = mock_object + + request = {} + await client.get_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_cluster_async( transport: str = "grpc_asyncio", request_type=azure_service.GetAzureClusterRequest @@ -3556,6 +4221,9 @@ def test_list_azure_clusters_empty_call(): with mock.patch.object( type(client.transport.list_azure_clusters), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_azure_clusters() call.assert_called() _, args, _ = call.mock_calls[0] @@ -3582,6 +4250,9 @@ def test_list_azure_clusters_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.list_azure_clusters), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_azure_clusters(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -3591,6 +4262,45 @@ def test_list_azure_clusters_non_empty_request_with_auto_populated_field(): ) +def test_list_azure_clusters_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_azure_clusters in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_azure_clusters + ] = mock_rpc + request = {} + client.list_azure_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_azure_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_list_azure_clusters_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -3616,6 +4326,52 @@ async def test_list_azure_clusters_empty_call_async(): assert args[0] == azure_service.ListAzureClustersRequest() +@pytest.mark.asyncio +async def test_list_azure_clusters_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.list_azure_clusters + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.list_azure_clusters + ] = mock_object + + request = {} + await client.list_azure_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.list_azure_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_list_azure_clusters_async( transport: str = "grpc_asyncio", request_type=azure_service.ListAzureClustersRequest @@ -4053,6 +4809,9 @@ def test_delete_azure_cluster_empty_call(): with mock.patch.object( type(client.transport.delete_azure_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_azure_cluster() call.assert_called() _, args, _ = call.mock_calls[0] @@ -4079,6 +4838,9 @@ def test_delete_azure_cluster_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.delete_azure_cluster), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_azure_cluster(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -4088,6 +4850,49 @@ def test_delete_azure_cluster_non_empty_request_with_auto_populated_field(): ) +def test_delete_azure_cluster_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_azure_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_azure_cluster + ] = mock_rpc + request = {} + client.delete_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_delete_azure_cluster_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -4111,6 +4916,56 @@ async def test_delete_azure_cluster_empty_call_async(): assert args[0] == azure_service.DeleteAzureClusterRequest() +@pytest.mark.asyncio +async def test_delete_azure_cluster_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.delete_azure_cluster + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.delete_azure_cluster + ] = mock_object + + request = {} + await client.delete_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.delete_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_delete_azure_cluster_async( transport: str = "grpc_asyncio", @@ -4355,6 +5210,9 @@ def test_generate_azure_cluster_agent_token_empty_call(): with mock.patch.object( type(client.transport.generate_azure_cluster_agent_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_azure_cluster_agent_token() call.assert_called() _, args, _ = call.mock_calls[0] @@ -4389,6 +5247,9 @@ def test_generate_azure_cluster_agent_token_non_empty_request_with_auto_populate with mock.patch.object( type(client.transport.generate_azure_cluster_agent_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_azure_cluster_agent_token(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -4406,6 +5267,46 @@ def test_generate_azure_cluster_agent_token_non_empty_request_with_auto_populate ) +def test_generate_azure_cluster_agent_token_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_azure_cluster_agent_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_azure_cluster_agent_token + ] = mock_rpc + request = {} + client.generate_azure_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_azure_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_generate_azure_cluster_agent_token_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -4433,6 +5334,52 @@ async def test_generate_azure_cluster_agent_token_empty_call_async(): assert args[0] == azure_service.GenerateAzureClusterAgentTokenRequest() +@pytest.mark.asyncio +async def test_generate_azure_cluster_agent_token_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.generate_azure_cluster_agent_token + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.generate_azure_cluster_agent_token + ] = mock_object + + request = {} + await client.generate_azure_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.generate_azure_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_generate_azure_cluster_agent_token_async( transport: str = "grpc_asyncio", @@ -4594,6 +5541,9 @@ def test_generate_azure_access_token_empty_call(): with mock.patch.object( type(client.transport.generate_azure_access_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_azure_access_token() call.assert_called() _, args, _ = call.mock_calls[0] @@ -4619,6 +5569,9 @@ def test_generate_azure_access_token_non_empty_request_with_auto_populated_field with mock.patch.object( type(client.transport.generate_azure_access_token), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.generate_azure_access_token(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -4627,6 +5580,46 @@ def test_generate_azure_access_token_non_empty_request_with_auto_populated_field ) +def test_generate_azure_access_token_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_azure_access_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_azure_access_token + ] = mock_rpc + request = {} + client.generate_azure_access_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_azure_access_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_generate_azure_access_token_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -4652,6 +5645,52 @@ async def test_generate_azure_access_token_empty_call_async(): assert args[0] == azure_service.GenerateAzureAccessTokenRequest() +@pytest.mark.asyncio +async def test_generate_azure_access_token_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.generate_azure_access_token + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.generate_azure_access_token + ] = mock_object + + request = {} + await client.generate_azure_access_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.generate_azure_access_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_generate_azure_access_token_async( transport: str = "grpc_asyncio", @@ -4806,6 +5845,9 @@ def test_create_azure_node_pool_empty_call(): with mock.patch.object( type(client.transport.create_azure_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_azure_node_pool() call.assert_called() _, args, _ = call.mock_calls[0] @@ -4832,6 +5874,9 @@ def test_create_azure_node_pool_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.create_azure_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.create_azure_node_pool(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -4841,6 +5886,50 @@ def test_create_azure_node_pool_non_empty_request_with_auto_populated_field(): ) +def test_create_azure_node_pool_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_azure_node_pool + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_azure_node_pool + ] = mock_rpc + request = {} + client.create_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_create_azure_node_pool_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -4864,6 +5953,56 @@ async def test_create_azure_node_pool_empty_call_async(): assert args[0] == azure_service.CreateAzureNodePoolRequest() +@pytest.mark.asyncio +async def test_create_azure_node_pool_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.create_azure_node_pool + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.create_azure_node_pool + ] = mock_object + + request = {} + await client.create_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.create_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_create_azure_node_pool_async( transport: str = "grpc_asyncio", @@ -5121,6 +6260,9 @@ def test_update_azure_node_pool_empty_call(): with mock.patch.object( type(client.transport.update_azure_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_azure_node_pool() call.assert_called() _, args, _ = call.mock_calls[0] @@ -5144,12 +6286,59 @@ def test_update_azure_node_pool_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.update_azure_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_azure_node_pool(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == azure_service.UpdateAzureNodePoolRequest() +def test_update_azure_node_pool_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_azure_node_pool + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_azure_node_pool + ] = mock_rpc + request = {} + client.update_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_update_azure_node_pool_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -5173,6 +6362,56 @@ async def test_update_azure_node_pool_empty_call_async(): assert args[0] == azure_service.UpdateAzureNodePoolRequest() +@pytest.mark.asyncio +async def test_update_azure_node_pool_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.update_azure_node_pool + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.update_azure_node_pool + ] = mock_object + + request = {} + await client.update_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.update_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_update_azure_node_pool_async( transport: str = "grpc_asyncio", @@ -5437,6 +6676,9 @@ def test_get_azure_node_pool_empty_call(): with mock.patch.object( type(client.transport.get_azure_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_node_pool() call.assert_called() _, args, _ = call.mock_calls[0] @@ -5462,6 +6704,9 @@ def test_get_azure_node_pool_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_azure_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_node_pool(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -5470,6 +6715,45 @@ def test_get_azure_node_pool_non_empty_request_with_auto_populated_field(): ) +def test_get_azure_node_pool_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_azure_node_pool in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_node_pool + ] = mock_rpc + request = {} + client.get_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_node_pool_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -5502,6 +6786,52 @@ async def test_get_azure_node_pool_empty_call_async(): assert args[0] == azure_service.GetAzureNodePoolRequest() +@pytest.mark.asyncio +async def test_get_azure_node_pool_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_azure_node_pool + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_azure_node_pool + ] = mock_object + + request = {} + await client.get_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_node_pool_async( transport: str = "grpc_asyncio", request_type=azure_service.GetAzureNodePoolRequest @@ -5758,6 +7088,9 @@ def test_list_azure_node_pools_empty_call(): with mock.patch.object( type(client.transport.list_azure_node_pools), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_azure_node_pools() call.assert_called() _, args, _ = call.mock_calls[0] @@ -5784,6 +7117,9 @@ def test_list_azure_node_pools_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.list_azure_node_pools), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_azure_node_pools(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -5793,6 +7129,46 @@ def test_list_azure_node_pools_non_empty_request_with_auto_populated_field(): ) +def test_list_azure_node_pools_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_azure_node_pools + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_azure_node_pools + ] = mock_rpc + request = {} + client.list_azure_node_pools(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_azure_node_pools(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_list_azure_node_pools_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -5818,6 +7194,52 @@ async def test_list_azure_node_pools_empty_call_async(): assert args[0] == azure_service.ListAzureNodePoolsRequest() +@pytest.mark.asyncio +async def test_list_azure_node_pools_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.list_azure_node_pools + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.list_azure_node_pools + ] = mock_object + + request = {} + await client.list_azure_node_pools(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.list_azure_node_pools(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_list_azure_node_pools_async( transport: str = "grpc_asyncio", @@ -6256,6 +7678,9 @@ def test_delete_azure_node_pool_empty_call(): with mock.patch.object( type(client.transport.delete_azure_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_azure_node_pool() call.assert_called() _, args, _ = call.mock_calls[0] @@ -6282,6 +7707,9 @@ def test_delete_azure_node_pool_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.delete_azure_node_pool), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_azure_node_pool(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -6291,6 +7719,50 @@ def test_delete_azure_node_pool_non_empty_request_with_auto_populated_field(): ) +def test_delete_azure_node_pool_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_azure_node_pool + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_azure_node_pool + ] = mock_rpc + request = {} + client.delete_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_delete_azure_node_pool_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -6314,6 +7786,56 @@ async def test_delete_azure_node_pool_empty_call_async(): assert args[0] == azure_service.DeleteAzureNodePoolRequest() +@pytest.mark.asyncio +async def test_delete_azure_node_pool_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.delete_azure_node_pool + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.delete_azure_node_pool + ] = mock_object + + request = {} + await client.delete_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + await client.delete_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_delete_azure_node_pool_async( transport: str = "grpc_asyncio", @@ -6570,6 +8092,9 @@ def test_get_azure_open_id_config_empty_call(): with mock.patch.object( type(client.transport.get_azure_open_id_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_open_id_config() call.assert_called() _, args, _ = call.mock_calls[0] @@ -6595,6 +8120,9 @@ def test_get_azure_open_id_config_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_azure_open_id_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_open_id_config(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -6603,6 +8131,46 @@ def test_get_azure_open_id_config_non_empty_request_with_auto_populated_field(): ) +def test_get_azure_open_id_config_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_azure_open_id_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_open_id_config + ] = mock_rpc + request = {} + client.get_azure_open_id_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_open_id_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_open_id_config_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -6636,6 +8204,52 @@ async def test_get_azure_open_id_config_empty_call_async(): assert args[0] == azure_service.GetAzureOpenIdConfigRequest() +@pytest.mark.asyncio +async def test_get_azure_open_id_config_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_azure_open_id_config + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_azure_open_id_config + ] = mock_object + + request = {} + await client.get_azure_open_id_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_azure_open_id_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_open_id_config_async( transport: str = "grpc_asyncio", @@ -6892,6 +8506,9 @@ def test_get_azure_json_web_keys_empty_call(): with mock.patch.object( type(client.transport.get_azure_json_web_keys), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_json_web_keys() call.assert_called() _, args, _ = call.mock_calls[0] @@ -6917,6 +8534,9 @@ def test_get_azure_json_web_keys_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_azure_json_web_keys), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_json_web_keys(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -6925,6 +8545,46 @@ def test_get_azure_json_web_keys_non_empty_request_with_auto_populated_field(): ) +def test_get_azure_json_web_keys_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_azure_json_web_keys + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_json_web_keys + ] = mock_rpc + request = {} + client.get_azure_json_web_keys(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_json_web_keys(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_json_web_keys_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -6948,6 +8608,52 @@ async def test_get_azure_json_web_keys_empty_call_async(): assert args[0] == azure_service.GetAzureJsonWebKeysRequest() +@pytest.mark.asyncio +async def test_get_azure_json_web_keys_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_azure_json_web_keys + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_azure_json_web_keys + ] = mock_object + + request = {} + await client.get_azure_json_web_keys(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_azure_json_web_keys(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_json_web_keys_async( transport: str = "grpc_asyncio", @@ -7190,6 +8896,9 @@ def test_get_azure_server_config_empty_call(): with mock.patch.object( type(client.transport.get_azure_server_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_server_config() call.assert_called() _, args, _ = call.mock_calls[0] @@ -7215,6 +8924,9 @@ def test_get_azure_server_config_non_empty_request_with_auto_populated_field(): with mock.patch.object( type(client.transport.get_azure_server_config), "__call__" ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_azure_server_config(request=request) call.assert_called() _, args, _ = call.mock_calls[0] @@ -7223,6 +8935,46 @@ def test_get_azure_server_config_non_empty_request_with_auto_populated_field(): ) +def test_get_azure_server_config_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_azure_server_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_server_config + ] = mock_rpc + request = {} + client.get_azure_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_server_config_empty_call_async(): # This test is a coverage failsafe to make sure that totally empty calls, @@ -7249,6 +9001,52 @@ async def test_get_azure_server_config_empty_call_async(): assert args[0] == azure_service.GetAzureServerConfigRequest() +@pytest.mark.asyncio +async def test_get_azure_server_config_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = AzureClustersAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.get_azure_server_config + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + class AwaitableMock(mock.AsyncMock): + def __await__(self): + self.await_count += 1 + return iter([]) + + mock_object = AwaitableMock() + client._client._transport._wrapped_methods[ + client._client._transport.get_azure_server_config + ] = mock_object + + request = {} + await client.get_azure_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_object.call_count == 1 + + await client.get_azure_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_object.call_count == 2 + + @pytest.mark.asyncio async def test_get_azure_server_config_async( transport: str = "grpc_asyncio", @@ -7557,6 +9355,50 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_create_azure_client_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_azure_client in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_azure_client + ] = mock_rpc + + request = {} + client.create_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_create_azure_client_rest_required_fields( request_type=azure_service.CreateAzureClientRequest, ): @@ -7869,6 +9711,44 @@ def test_get_azure_client_rest(request_type): assert response.uid == "uid_value" +def test_get_azure_client_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_azure_client in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_client + ] = mock_rpc + + request = {} + client.get_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_azure_client_rest_required_fields( request_type=azure_service.GetAzureClientRequest, ): @@ -8138,6 +10018,46 @@ def test_list_azure_clients_rest(request_type): assert response.next_page_token == "next_page_token_value" +def test_list_azure_clients_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_azure_clients in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_azure_clients + ] = mock_rpc + + request = {} + client.list_azure_clients(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_azure_clients(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_list_azure_clients_rest_required_fields( request_type=azure_service.ListAzureClientsRequest, ): @@ -8472,6 +10392,50 @@ def test_delete_azure_client_rest(request_type): assert response.operation.name == "operations/spam" +def test_delete_azure_client_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_azure_client in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_azure_client + ] = mock_rpc + + request = {} + client.delete_azure_client(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_azure_client(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_delete_azure_client_rest_required_fields( request_type=azure_service.DeleteAzureClientRequest, ): @@ -8889,6 +10853,50 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_create_azure_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_azure_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_azure_cluster + ] = mock_rpc + + request = {} + client.create_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_create_azure_cluster_rest_required_fields( request_type=azure_service.CreateAzureClusterRequest, ): @@ -9331,6 +11339,50 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_update_azure_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_azure_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_azure_cluster + ] = mock_rpc + + request = {} + client.update_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_update_azure_cluster_rest_required_fields( request_type=azure_service.UpdateAzureClusterRequest, ): @@ -9641,6 +11693,44 @@ def test_get_azure_cluster_rest(request_type): assert response.cluster_ca_certificate == "cluster_ca_certificate_value" +def test_get_azure_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_azure_cluster in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_cluster + ] = mock_rpc + + request = {} + client.get_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_azure_cluster_rest_required_fields( request_type=azure_service.GetAzureClusterRequest, ): @@ -9910,6 +12000,46 @@ def test_list_azure_clusters_rest(request_type): assert response.next_page_token == "next_page_token_value" +def test_list_azure_clusters_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_azure_clusters in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_azure_clusters + ] = mock_rpc + + request = {} + client.list_azure_clusters(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_azure_clusters(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_list_azure_clusters_rest_required_fields( request_type=azure_service.ListAzureClustersRequest, ): @@ -10244,6 +12374,50 @@ def test_delete_azure_cluster_rest(request_type): assert response.operation.name == "operations/spam" +def test_delete_azure_cluster_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_azure_cluster in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_azure_cluster + ] = mock_rpc + + request = {} + client.delete_azure_cluster(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_azure_cluster(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_delete_azure_cluster_rest_required_fields( request_type=azure_service.DeleteAzureClusterRequest, ): @@ -10276,6 +12450,7 @@ def test_delete_azure_cluster_rest_required_fields( ( "allow_missing", "etag", + "ignore_errors", "validate_only", ) ) @@ -10334,6 +12509,7 @@ def test_delete_azure_cluster_rest_unset_required_fields(): ( "allowMissing", "etag", + "ignoreErrors", "validateOnly", ) ) @@ -10535,6 +12711,47 @@ def test_generate_azure_cluster_agent_token_rest(request_type): assert response.token_type == "token_type_value" +def test_generate_azure_cluster_agent_token_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_azure_cluster_agent_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_azure_cluster_agent_token + ] = mock_rpc + + request = {} + client.generate_azure_cluster_agent_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_azure_cluster_agent_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_generate_azure_cluster_agent_token_rest_required_fields( request_type=azure_service.GenerateAzureClusterAgentTokenRequest, ): @@ -10781,6 +12998,47 @@ def test_generate_azure_access_token_rest(request_type): assert response.access_token == "access_token_value" +def test_generate_azure_access_token_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.generate_azure_access_token + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.generate_azure_access_token + ] = mock_rpc + + request = {} + client.generate_azure_access_token(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.generate_azure_access_token(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_generate_azure_access_token_rest_required_fields( request_type=azure_service.GenerateAzureAccessTokenRequest, ): @@ -11095,6 +13353,51 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_create_azure_node_pool_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_azure_node_pool + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_azure_node_pool + ] = mock_rpc + + request = {} + client.create_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_create_azure_node_pool_rest_required_fields( request_type=azure_service.CreateAzureNodePoolRequest, ): @@ -11501,6 +13804,51 @@ def get_message_fields(field): assert response.operation.name == "operations/spam" +def test_update_azure_node_pool_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_azure_node_pool + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_azure_node_pool + ] = mock_rpc + + request = {} + client.update_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_update_azure_node_pool_rest_required_fields( request_type=azure_service.UpdateAzureNodePoolRequest, ): @@ -11807,6 +14155,46 @@ def test_get_azure_node_pool_rest(request_type): assert response.azure_availability_zone == "azure_availability_zone_value" +def test_get_azure_node_pool_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_azure_node_pool in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_node_pool + ] = mock_rpc + + request = {} + client.get_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_azure_node_pool_rest_required_fields( request_type=azure_service.GetAzureNodePoolRequest, ): @@ -12080,6 +14468,47 @@ def test_list_azure_node_pools_rest(request_type): assert response.next_page_token == "next_page_token_value" +def test_list_azure_node_pools_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_azure_node_pools + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_azure_node_pools + ] = mock_rpc + + request = {} + client.list_azure_node_pools(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_azure_node_pools(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_list_azure_node_pools_rest_required_fields( request_type=azure_service.ListAzureNodePoolsRequest, ): @@ -12422,6 +14851,51 @@ def test_delete_azure_node_pool_rest(request_type): assert response.operation.name == "operations/spam" +def test_delete_azure_node_pool_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_azure_node_pool + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_azure_node_pool + ] = mock_rpc + + request = {} + client.delete_azure_node_pool(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_azure_node_pool(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_delete_azure_node_pool_rest_required_fields( request_type=azure_service.DeleteAzureNodePoolRequest, ): @@ -12454,6 +14928,7 @@ def test_delete_azure_node_pool_rest_required_fields( ( "allow_missing", "etag", + "ignore_errors", "validate_only", ) ) @@ -12512,6 +14987,7 @@ def test_delete_azure_node_pool_rest_unset_required_fields(): ( "allowMissing", "etag", + "ignoreErrors", "validateOnly", ) ) @@ -12725,6 +15201,47 @@ def test_get_azure_open_id_config_rest(request_type): assert response.grant_types == ["grant_types_value"] +def test_get_azure_open_id_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_azure_open_id_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_open_id_config + ] = mock_rpc + + request = {} + client.get_azure_open_id_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_open_id_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_azure_open_id_config_rest_required_fields( request_type=azure_service.GetAzureOpenIdConfigRequest, ): @@ -12995,6 +15512,47 @@ def test_get_azure_json_web_keys_rest(request_type): assert isinstance(response, azure_resources.AzureJsonWebKeys) +def test_get_azure_json_web_keys_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_azure_json_web_keys + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_json_web_keys + ] = mock_rpc + + request = {} + client.get_azure_json_web_keys(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_json_web_keys(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_azure_json_web_keys_rest_required_fields( request_type=azure_service.GetAzureJsonWebKeysRequest, ): @@ -13268,6 +15826,47 @@ def test_get_azure_server_config_rest(request_type): assert response.supported_azure_regions == ["supported_azure_regions_value"] +def test_get_azure_server_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = AzureClustersClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_azure_server_config + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_azure_server_config + ] = mock_rpc + + request = {} + client.get_azure_server_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_azure_server_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + def test_get_azure_server_config_rest_required_fields( request_type=azure_service.GetAzureServerConfigRequest, ):