diff --git a/docs/redis_v1/types.rst b/docs/redis_v1/types.rst index babee02..7eb7c77 100644 --- a/docs/redis_v1/types.rst +++ b/docs/redis_v1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Redis v1 API .. automodule:: google.cloud.redis_v1.types :members: + :show-inheritance: diff --git a/docs/redis_v1beta1/types.rst b/docs/redis_v1beta1/types.rst index e552277..4306941 100644 --- a/docs/redis_v1beta1/types.rst +++ b/docs/redis_v1beta1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Redis v1beta1 API .. automodule:: google.cloud.redis_v1beta1.types :members: + :show-inheritance: diff --git a/google/cloud/redis_v1/services/cloud_redis/async_client.py b/google/cloud/redis_v1/services/cloud_redis/async_client.py index abe09f0..1553c6c 100644 --- a/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -74,9 +74,41 @@ class CloudRedisAsyncClient: instance_path = staticmethod(CloudRedisClient.instance_path) parse_instance_path = staticmethod(CloudRedisClient.parse_instance_path) + common_billing_account_path = staticmethod( + CloudRedisClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + CloudRedisClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(CloudRedisClient.common_folder_path) + parse_common_folder_path = staticmethod(CloudRedisClient.parse_common_folder_path) + + common_organization_path = staticmethod(CloudRedisClient.common_organization_path) + parse_common_organization_path = staticmethod( + CloudRedisClient.parse_common_organization_path + ) + + common_project_path = staticmethod(CloudRedisClient.common_project_path) + parse_common_project_path = staticmethod(CloudRedisClient.parse_common_project_path) + + common_location_path = staticmethod(CloudRedisClient.common_location_path) + parse_common_location_path = staticmethod( + CloudRedisClient.parse_common_location_path + ) + from_service_account_file = CloudRedisClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> CloudRedisTransport: + """Return the transport used by the client instance. + + Returns: + CloudRedisTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(CloudRedisClient).get_transport_class, type(CloudRedisClient) ) @@ -180,7 +212,8 @@ async def list_instances( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([parent]): + has_flattened_params = builtins.any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -256,7 +289,8 @@ async def get_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name]): + has_flattened_params = builtins.any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -365,7 +399,8 @@ async def create_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([parent, instance_id, instance]): + has_flattened_params = builtins.any([parent, instance_id, instance]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -470,7 +505,8 @@ async def update_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([update_mask, instance]): + has_flattened_params = builtins.any([update_mask, instance]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -565,7 +601,8 @@ async def upgrade_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name, redis_version]): + has_flattened_params = builtins.any([name, redis_version]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -665,7 +702,8 @@ async def import_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name, input_config]): + has_flattened_params = builtins.any([name, input_config]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -761,7 +799,8 @@ async def export_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name, output_config]): + has_flattened_params = builtins.any([name, output_config]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -856,7 +895,8 @@ async def failover_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name, data_protection_mode]): + has_flattened_params = builtins.any([name, data_protection_mode]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -954,7 +994,8 @@ async def delete_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name]): + has_flattened_params = builtins.any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." diff --git a/google/cloud/redis_v1/services/cloud_redis/client.py b/google/cloud/redis_v1/services/cloud_redis/client.py index 899e7ed..8a5206f 100644 --- a/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/google/cloud/redis_v1/services/cloud_redis/client.py @@ -155,6 +155,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> CloudRedisTransport: + """Return the transport used by the client instance. + + Returns: + CloudRedisTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def instance_path(project: str, location: str, instance: str,) -> str: """Return a fully-qualified instance string.""" @@ -171,6 +180,65 @@ def parse_instance_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, @@ -206,10 +274,10 @@ def __init__( not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/__init__.py b/google/cloud/redis_v1/services/cloud_redis/transports/__init__.py index 3b0088e..7959435 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/__init__.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/__init__.py @@ -28,7 +28,6 @@ _transport_registry["grpc"] = CloudRedisGrpcTransport _transport_registry["grpc_asyncio"] = CloudRedisGrpcAsyncIOTransport - __all__ = ( "CloudRedisTransport", "CloudRedisGrpcTransport", diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py b/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py index b54f906..ae96591 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py @@ -111,10 +111,10 @@ def __init__( for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -123,6 +123,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -130,6 +132,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -165,7 +168,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -182,9 +190,14 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] + self._operations_client = None # Run the base constructor. super().__init__( @@ -208,7 +221,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -243,12 +256,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property @@ -259,13 +268,11 @@ def operations_client(self) -> operations_v1.OperationsClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsClient( - self.grpc_channel - ) + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def list_instances( diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py b/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py index 30cdc40..b667778 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py @@ -168,6 +168,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -175,6 +177,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -210,7 +213,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -227,6 +235,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. @@ -240,6 +252,7 @@ def __init__( ) self._stubs = {} + self._operations_client = None @property def grpc_channel(self) -> aio.Channel: @@ -259,13 +272,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient( + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel ) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def list_instances( diff --git a/google/cloud/redis_v1/types/__init__.py b/google/cloud/redis_v1/types/__init__.py index fb1f7e5..1942d36 100644 --- a/google/cloud/redis_v1/types/__init__.py +++ b/google/cloud/redis_v1/types/__init__.py @@ -36,7 +36,6 @@ ZoneMetadata, ) - __all__ = ( "Instance", "ListInstancesRequest", diff --git a/google/cloud/redis_v1/types/cloud_redis.py b/google/cloud/redis_v1/types/cloud_redis.py index a95e46b..9821f43 100644 --- a/google/cloud/redis_v1/types/cloud_redis.py +++ b/google/cloud/redis_v1/types/cloud_redis.py @@ -292,7 +292,7 @@ class ListInstancesResponse(proto.Message): def raw_page(self): return self - instances = proto.RepeatedField(proto.MESSAGE, number=1, message=Instance,) + instances = proto.RepeatedField(proto.MESSAGE, number=1, message="Instance",) next_page_token = proto.Field(proto.STRING, number=2) @@ -340,7 +340,7 @@ class CreateInstanceRequest(proto.Message): instance_id = proto.Field(proto.STRING, number=2) - instance = proto.Field(proto.MESSAGE, number=3, message=Instance,) + instance = proto.Field(proto.MESSAGE, number=3, message="Instance",) class UpdateInstanceRequest(proto.Message): @@ -365,7 +365,7 @@ class UpdateInstanceRequest(proto.Message): update_mask = proto.Field(proto.MESSAGE, number=1, message=field_mask.FieldMask,) - instance = proto.Field(proto.MESSAGE, number=2, message=Instance,) + instance = proto.Field(proto.MESSAGE, number=2, message="Instance",) class UpgradeInstanceRequest(proto.Message): @@ -423,7 +423,7 @@ class InputConfig(proto.Message): """ gcs_source = proto.Field( - proto.MESSAGE, number=1, oneof="source", message=GcsSource, + proto.MESSAGE, number=1, oneof="source", message="GcsSource", ) @@ -442,7 +442,7 @@ class ImportInstanceRequest(proto.Message): name = proto.Field(proto.STRING, number=1) - input_config = proto.Field(proto.MESSAGE, number=3, message=InputConfig,) + input_config = proto.Field(proto.MESSAGE, number=3, message="InputConfig",) class GcsDestination(proto.Message): @@ -468,7 +468,7 @@ class OutputConfig(proto.Message): """ gcs_destination = proto.Field( - proto.MESSAGE, number=1, oneof="destination", message=GcsDestination, + proto.MESSAGE, number=1, oneof="destination", message="GcsDestination", ) @@ -487,7 +487,7 @@ class ExportInstanceRequest(proto.Message): name = proto.Field(proto.STRING, number=1) - output_config = proto.Field(proto.MESSAGE, number=3, message=OutputConfig,) + output_config = proto.Field(proto.MESSAGE, number=3, message="OutputConfig",) class FailoverInstanceRequest(proto.Message): diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py b/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py index 72bb315..fef3d14 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/async_client.py @@ -75,9 +75,41 @@ class CloudRedisAsyncClient: instance_path = staticmethod(CloudRedisClient.instance_path) parse_instance_path = staticmethod(CloudRedisClient.parse_instance_path) + common_billing_account_path = staticmethod( + CloudRedisClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + CloudRedisClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(CloudRedisClient.common_folder_path) + parse_common_folder_path = staticmethod(CloudRedisClient.parse_common_folder_path) + + common_organization_path = staticmethod(CloudRedisClient.common_organization_path) + parse_common_organization_path = staticmethod( + CloudRedisClient.parse_common_organization_path + ) + + common_project_path = staticmethod(CloudRedisClient.common_project_path) + parse_common_project_path = staticmethod(CloudRedisClient.parse_common_project_path) + + common_location_path = staticmethod(CloudRedisClient.common_location_path) + parse_common_location_path = staticmethod( + CloudRedisClient.parse_common_location_path + ) + from_service_account_file = CloudRedisClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> CloudRedisTransport: + """Return the transport used by the client instance. + + Returns: + CloudRedisTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(CloudRedisClient).get_transport_class, type(CloudRedisClient) ) @@ -181,7 +213,8 @@ async def list_instances( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([parent]): + has_flattened_params = builtins.any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -257,7 +290,8 @@ async def get_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name]): + has_flattened_params = builtins.any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -366,7 +400,8 @@ async def create_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([parent, instance_id, instance]): + has_flattened_params = builtins.any([parent, instance_id, instance]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -471,7 +506,8 @@ async def update_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([update_mask, instance]): + has_flattened_params = builtins.any([update_mask, instance]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -566,7 +602,8 @@ async def upgrade_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name, redis_version]): + has_flattened_params = builtins.any([name, redis_version]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -666,7 +703,8 @@ async def import_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name, input_config]): + has_flattened_params = builtins.any([name, input_config]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -762,7 +800,8 @@ async def export_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name, output_config]): + has_flattened_params = builtins.any([name, output_config]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -857,7 +896,8 @@ async def failover_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name, data_protection_mode]): + has_flattened_params = builtins.any([name, data_protection_mode]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -955,7 +995,8 @@ async def delete_instance( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and builtins.any([name]): + has_flattened_params = builtins.any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/client.py b/google/cloud/redis_v1beta1/services/cloud_redis/client.py index 5b075bd..ed583d8 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/client.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/client.py @@ -156,6 +156,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> CloudRedisTransport: + """Return the transport used by the client instance. + + Returns: + CloudRedisTransport: The transport used by the client instance. + """ + return self._transport + @staticmethod def instance_path(project: str, location: str, instance: str,) -> str: """Return a fully-qualified instance string.""" @@ -172,6 +181,65 @@ def parse_instance_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, @@ -207,10 +275,10 @@ def __init__( not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/transports/__init__.py b/google/cloud/redis_v1beta1/services/cloud_redis/transports/__init__.py index 3b0088e..7959435 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/transports/__init__.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/transports/__init__.py @@ -28,7 +28,6 @@ _transport_registry["grpc"] = CloudRedisGrpcTransport _transport_registry["grpc_asyncio"] = CloudRedisGrpcAsyncIOTransport - __all__ = ( "CloudRedisTransport", "CloudRedisGrpcTransport", diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py b/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py index b450f6e..1354c3d 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc.py @@ -111,10 +111,10 @@ def __init__( for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -123,6 +123,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -130,6 +132,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -165,7 +168,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -182,9 +190,14 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] + self._operations_client = None # Run the base constructor. super().__init__( @@ -208,7 +221,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (Optional[str]): The host for the channel to use. credentials (Optional[~.Credentials]): The authorization credentials to attach to requests. These credentials identify this application to the service. If @@ -243,12 +256,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property @@ -259,13 +268,11 @@ def operations_client(self) -> operations_v1.OperationsClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsClient( - self.grpc_channel - ) + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def list_instances( diff --git a/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py b/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py index 239d7d7..b091718 100644 --- a/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py +++ b/google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py @@ -168,6 +168,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -175,6 +177,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -210,7 +213,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -227,6 +235,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. @@ -240,6 +252,7 @@ def __init__( ) self._stubs = {} + self._operations_client = None @property def grpc_channel(self) -> aio.Channel: @@ -259,13 +272,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient( + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel ) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def list_instances( diff --git a/google/cloud/redis_v1beta1/types/__init__.py b/google/cloud/redis_v1beta1/types/__init__.py index 3d4931d..d2450f1 100644 --- a/google/cloud/redis_v1beta1/types/__init__.py +++ b/google/cloud/redis_v1beta1/types/__init__.py @@ -35,7 +35,6 @@ ZoneMetadata, ) - __all__ = ( "Instance", "ListInstancesRequest", diff --git a/google/cloud/redis_v1beta1/types/cloud_redis.py b/google/cloud/redis_v1beta1/types/cloud_redis.py index 80ec425..5b7c71f 100644 --- a/google/cloud/redis_v1beta1/types/cloud_redis.py +++ b/google/cloud/redis_v1beta1/types/cloud_redis.py @@ -293,7 +293,7 @@ class ListInstancesResponse(proto.Message): def raw_page(self): return self - instances = proto.RepeatedField(proto.MESSAGE, number=1, message=Instance,) + instances = proto.RepeatedField(proto.MESSAGE, number=1, message="Instance",) next_page_token = proto.Field(proto.STRING, number=2) @@ -341,7 +341,7 @@ class CreateInstanceRequest(proto.Message): instance_id = proto.Field(proto.STRING, number=2) - instance = proto.Field(proto.MESSAGE, number=3, message=Instance,) + instance = proto.Field(proto.MESSAGE, number=3, message="Instance",) class UpdateInstanceRequest(proto.Message): @@ -366,7 +366,7 @@ class UpdateInstanceRequest(proto.Message): update_mask = proto.Field(proto.MESSAGE, number=1, message=field_mask.FieldMask,) - instance = proto.Field(proto.MESSAGE, number=2, message=Instance,) + instance = proto.Field(proto.MESSAGE, number=2, message="Instance",) class UpgradeInstanceRequest(proto.Message): @@ -424,7 +424,7 @@ class InputConfig(proto.Message): """ gcs_source = proto.Field( - proto.MESSAGE, number=1, oneof="source", message=GcsSource, + proto.MESSAGE, number=1, oneof="source", message="GcsSource", ) @@ -443,7 +443,7 @@ class ImportInstanceRequest(proto.Message): name = proto.Field(proto.STRING, number=1) - input_config = proto.Field(proto.MESSAGE, number=3, message=InputConfig,) + input_config = proto.Field(proto.MESSAGE, number=3, message="InputConfig",) class GcsDestination(proto.Message): @@ -469,7 +469,7 @@ class OutputConfig(proto.Message): """ gcs_destination = proto.Field( - proto.MESSAGE, number=1, oneof="destination", message=GcsDestination, + proto.MESSAGE, number=1, oneof="destination", message="GcsDestination", ) @@ -488,7 +488,7 @@ class ExportInstanceRequest(proto.Message): name = proto.Field(proto.STRING, number=1) - output_config = proto.Field(proto.MESSAGE, number=3, message=OutputConfig,) + output_config = proto.Field(proto.MESSAGE, number=3, message="OutputConfig",) class FailoverInstanceRequest(proto.Message): diff --git a/scripts/fixup_redis_v1_keywords.py b/scripts/fixup_redis_v1_keywords.py index 5d1dd0c..b142431 100644 --- a/scripts/fixup_redis_v1_keywords.py +++ b/scripts/fixup_redis_v1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/scripts/fixup_redis_v1beta1_keywords.py b/scripts/fixup_redis_v1beta1_keywords.py index 5d1dd0c..b142431 100644 --- a/scripts/fixup_redis_v1beta1_keywords.py +++ b/scripts/fixup_redis_v1beta1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/synth.metadata b/synth.metadata index ce9a452..e0ca973 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-redis.git", - "sha": "66eecbbddf3ed0c6faaee6c778d561c0ba6e53e2" + "sha": "add073580f4734289adc03abe8a44657c8686951" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "3dbeac0d54125b123c8dfd39c774b37473c36944", - "internalRef": "333159182" + "sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907", + "internalRef": "347055288" } }, { diff --git a/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/unit/gapic/redis_v1/test_cloud_redis.py index 449fb13..7712657 100644 --- a/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -95,12 +95,12 @@ def test_cloud_redis_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "redis.googleapis.com:443" + assert client.transport._host == "redis.googleapis.com:443" def test_cloud_redis_client_get_transport_class(): @@ -444,7 +444,7 @@ def test_list_instances( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.ListInstancesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], @@ -459,6 +459,7 @@ def test_list_instances( assert args[0] == cloud_redis.ListInstancesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstancesPager) assert response.next_page_token == "next_page_token_value" @@ -471,19 +472,19 @@ def test_list_instances_from_dict(): @pytest.mark.asyncio -async def test_list_instances_async(transport: str = "grpc_asyncio"): +async def test_list_instances_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.ListInstancesRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.ListInstancesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_instances), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.ListInstancesResponse( @@ -498,7 +499,7 @@ async def test_list_instances_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.ListInstancesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListInstancesAsyncPager) @@ -508,6 +509,11 @@ async def test_list_instances_async(transport: str = "grpc_asyncio"): assert response.unreachable == ["unreachable_value"] +@pytest.mark.asyncio +async def test_list_instances_async_from_dict(): + await test_list_instances_async(request_type=dict) + + def test_list_instances_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -517,7 +523,7 @@ def test_list_instances_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: call.return_value = cloud_redis.ListInstancesResponse() client.list_instances(request) @@ -542,9 +548,7 @@ async def test_list_instances_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_instances), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.ListInstancesResponse() ) @@ -565,7 +569,7 @@ def test_list_instances_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.ListInstancesResponse() @@ -597,9 +601,7 @@ async def test_list_instances_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_instances), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.ListInstancesResponse() @@ -634,7 +636,7 @@ def test_list_instances_pager(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( cloud_redis.ListInstancesResponse( @@ -672,7 +674,7 @@ def test_list_instances_pages(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( cloud_redis.ListInstancesResponse( @@ -703,9 +705,7 @@ async def test_list_instances_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instances), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_instances), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -742,9 +742,7 @@ async def test_list_instances_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instances), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_instances), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -784,7 +782,7 @@ def test_get_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instance), "__call__") as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.Instance( name="name_value", @@ -814,6 +812,7 @@ def test_get_instance( assert args[0] == cloud_redis.GetInstanceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, cloud_redis.Instance) assert response.name == "name_value" @@ -854,19 +853,19 @@ def test_get_instance_from_dict(): @pytest.mark.asyncio -async def test_get_instance_async(transport: str = "grpc_asyncio"): +async def test_get_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.GetInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.GetInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.Instance( @@ -895,7 +894,7 @@ async def test_get_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.GetInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, cloud_redis.Instance) @@ -933,6 +932,11 @@ async def test_get_instance_async(transport: str = "grpc_asyncio"): assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING +@pytest.mark.asyncio +async def test_get_instance_async_from_dict(): + await test_get_instance_async(request_type=dict) + + def test_get_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -942,7 +946,7 @@ def test_get_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instance), "__call__") as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: call.return_value = cloud_redis.Instance() client.get_instance(request) @@ -967,9 +971,7 @@ async def test_get_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.Instance() ) @@ -990,7 +992,7 @@ def test_get_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instance), "__call__") as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.Instance() @@ -1022,9 +1024,7 @@ async def test_get_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.Instance() @@ -1067,7 +1067,7 @@ def test_create_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_instance), "__call__") as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1088,19 +1088,19 @@ def test_create_instance_from_dict(): @pytest.mark.asyncio -async def test_create_instance_async(transport: str = "grpc_asyncio"): +async def test_create_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.CreateInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.CreateInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1112,12 +1112,17 @@ async def test_create_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.CreateInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_create_instance_async_from_dict(): + await test_create_instance_async(request_type=dict) + + def test_create_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1127,7 +1132,7 @@ def test_create_instance_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_instance), "__call__") as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.create_instance(request) @@ -1152,9 +1157,7 @@ async def test_create_instance_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1175,7 +1178,7 @@ def test_create_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_instance), "__call__") as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1218,9 +1221,7 @@ async def test_create_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1274,7 +1275,7 @@ def test_update_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_instance), "__call__") as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1295,19 +1296,19 @@ def test_update_instance_from_dict(): @pytest.mark.asyncio -async def test_update_instance_async(transport: str = "grpc_asyncio"): +async def test_update_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.UpdateInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.UpdateInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1319,12 +1320,17 @@ async def test_update_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.UpdateInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_update_instance_async_from_dict(): + await test_update_instance_async(request_type=dict) + + def test_update_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1334,7 +1340,7 @@ def test_update_instance_field_headers(): request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_instance), "__call__") as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.update_instance(request) @@ -1361,9 +1367,7 @@ async def test_update_instance_field_headers_async(): request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1386,7 +1390,7 @@ def test_update_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_instance), "__call__") as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1425,9 +1429,7 @@ async def test_update_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1477,9 +1479,7 @@ def test_upgrade_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1500,19 +1500,19 @@ def test_upgrade_instance_from_dict(): @pytest.mark.asyncio -async def test_upgrade_instance_async(transport: str = "grpc_asyncio"): +async def test_upgrade_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.UpgradeInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.UpgradeInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1524,12 +1524,17 @@ async def test_upgrade_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.UpgradeInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_upgrade_instance_async_from_dict(): + await test_upgrade_instance_async(request_type=dict) + + def test_upgrade_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1539,9 +1544,7 @@ def test_upgrade_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.upgrade_instance(request) @@ -1566,9 +1569,7 @@ async def test_upgrade_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1589,9 +1590,7 @@ def test_upgrade_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1629,9 +1628,7 @@ async def test_upgrade_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1680,7 +1677,7 @@ def test_import_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_instance), "__call__") as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1701,19 +1698,19 @@ def test_import_instance_from_dict(): @pytest.mark.asyncio -async def test_import_instance_async(transport: str = "grpc_asyncio"): +async def test_import_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.ImportInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.ImportInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1725,12 +1722,17 @@ async def test_import_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.ImportInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_import_instance_async_from_dict(): + await test_import_instance_async(request_type=dict) + + def test_import_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1740,7 +1742,7 @@ def test_import_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_instance), "__call__") as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.import_instance(request) @@ -1765,9 +1767,7 @@ async def test_import_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1788,7 +1788,7 @@ def test_import_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_instance), "__call__") as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1833,9 +1833,7 @@ async def test_import_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1891,7 +1889,7 @@ def test_export_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_instance), "__call__") as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1912,19 +1910,19 @@ def test_export_instance_from_dict(): @pytest.mark.asyncio -async def test_export_instance_async(transport: str = "grpc_asyncio"): +async def test_export_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.ExportInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.ExportInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1936,12 +1934,17 @@ async def test_export_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.ExportInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_export_instance_async_from_dict(): + await test_export_instance_async(request_type=dict) + + def test_export_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1951,7 +1954,7 @@ def test_export_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_instance), "__call__") as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.export_instance(request) @@ -1976,9 +1979,7 @@ async def test_export_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1999,7 +2000,7 @@ def test_export_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_instance), "__call__") as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2044,9 +2045,7 @@ async def test_export_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2103,7 +2102,7 @@ def test_failover_instance( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -2125,18 +2124,20 @@ def test_failover_instance_from_dict(): @pytest.mark.asyncio -async def test_failover_instance_async(transport: str = "grpc_asyncio"): +async def test_failover_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.FailoverInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.FailoverInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2149,12 +2150,17 @@ async def test_failover_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.FailoverInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_failover_instance_async_from_dict(): + await test_failover_instance_async(request_type=dict) + + def test_failover_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -2165,7 +2171,7 @@ def test_failover_instance_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") @@ -2192,7 +2198,7 @@ async def test_failover_instance_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") @@ -2215,7 +2221,7 @@ def test_failover_instance_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2259,7 +2265,7 @@ async def test_failover_instance_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2313,7 +2319,7 @@ def test_delete_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_instance), "__call__") as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -2334,19 +2340,19 @@ def test_delete_instance_from_dict(): @pytest.mark.asyncio -async def test_delete_instance_async(transport: str = "grpc_asyncio"): +async def test_delete_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.DeleteInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.DeleteInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -2358,12 +2364,17 @@ async def test_delete_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.DeleteInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_delete_instance_async_from_dict(): + await test_delete_instance_async(request_type=dict) + + def test_delete_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -2373,7 +2384,7 @@ def test_delete_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_instance), "__call__") as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.delete_instance(request) @@ -2398,9 +2409,7 @@ async def test_delete_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -2421,7 +2430,7 @@ def test_delete_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_instance), "__call__") as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2453,9 +2462,7 @@ async def test_delete_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2522,7 +2529,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = CloudRedisClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -2555,7 +2562,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.CloudRedisGrpcTransport,) + assert isinstance(client.transport, transports.CloudRedisGrpcTransport,) def test_cloud_redis_base_transport_error(): @@ -2662,7 +2669,7 @@ def test_cloud_redis_host_no_port(): api_endpoint="redis.googleapis.com" ), ) - assert client._transport._host == "redis.googleapis.com:443" + assert client.transport._host == "redis.googleapis.com:443" def test_cloud_redis_host_with_port(): @@ -2672,7 +2679,7 @@ def test_cloud_redis_host_with_port(): api_endpoint="redis.googleapis.com:8000" ), ) - assert client._transport._host == "redis.googleapis.com:8000" + assert client.transport._host == "redis.googleapis.com:8000" def test_cloud_redis_grpc_transport_channel(): @@ -2684,6 +2691,7 @@ def test_cloud_redis_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_cloud_redis_grpc_asyncio_transport_channel(): @@ -2695,6 +2703,7 @@ def test_cloud_redis_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -2735,8 +2744,13 @@ def test_cloud_redis_transport_channel_mtls_with_client_cert_source(transport_cl scopes=("https://www.googleapis.com/auth/cloud-platform",), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -2772,6 +2786,10 @@ def test_cloud_redis_transport_channel_mtls_with_adc(transport_class): scopes=("https://www.googleapis.com/auth/cloud-platform",), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel @@ -2780,7 +2798,7 @@ def test_cloud_redis_grpc_lro_client(): client = CloudRedisClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -2793,7 +2811,7 @@ def test_cloud_redis_grpc_lro_async_client(): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -2827,6 +2845,107 @@ def test_parse_instance_path(): assert expected == actual +def test_common_billing_account_path(): + billing_account = "cuttlefish" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = CloudRedisClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = CloudRedisClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "winkle" + + expected = "folders/{folder}".format(folder=folder,) + actual = CloudRedisClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nautilus", + } + path = CloudRedisClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "scallop" + + expected = "organizations/{organization}".format(organization=organization,) + actual = CloudRedisClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "abalone", + } + path = CloudRedisClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "squid" + + expected = "projects/{project}".format(project=project,) + actual = CloudRedisClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = CloudRedisClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "whelk" + location = "octopus" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = CloudRedisClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + } + path = CloudRedisClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo() diff --git a/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py b/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py index 1b1a26b..8254137 100644 --- a/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py +++ b/tests/unit/gapic/redis_v1beta1/test_cloud_redis.py @@ -96,12 +96,12 @@ def test_cloud_redis_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "redis.googleapis.com:443" + assert client.transport._host == "redis.googleapis.com:443" def test_cloud_redis_client_get_transport_class(): @@ -445,7 +445,7 @@ def test_list_instances( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.ListInstancesResponse( next_page_token="next_page_token_value", unreachable=["unreachable_value"], @@ -460,6 +460,7 @@ def test_list_instances( assert args[0] == cloud_redis.ListInstancesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstancesPager) assert response.next_page_token == "next_page_token_value" @@ -472,19 +473,19 @@ def test_list_instances_from_dict(): @pytest.mark.asyncio -async def test_list_instances_async(transport: str = "grpc_asyncio"): +async def test_list_instances_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.ListInstancesRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.ListInstancesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_instances), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.ListInstancesResponse( @@ -499,7 +500,7 @@ async def test_list_instances_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.ListInstancesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListInstancesAsyncPager) @@ -509,6 +510,11 @@ async def test_list_instances_async(transport: str = "grpc_asyncio"): assert response.unreachable == ["unreachable_value"] +@pytest.mark.asyncio +async def test_list_instances_async_from_dict(): + await test_list_instances_async(request_type=dict) + + def test_list_instances_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -518,7 +524,7 @@ def test_list_instances_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: call.return_value = cloud_redis.ListInstancesResponse() client.list_instances(request) @@ -543,9 +549,7 @@ async def test_list_instances_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_instances), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.ListInstancesResponse() ) @@ -566,7 +570,7 @@ def test_list_instances_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.ListInstancesResponse() @@ -598,9 +602,7 @@ async def test_list_instances_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_instances), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.ListInstancesResponse() @@ -635,7 +637,7 @@ def test_list_instances_pager(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( cloud_redis.ListInstancesResponse( @@ -673,7 +675,7 @@ def test_list_instances_pages(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_instances), "__call__") as call: + with mock.patch.object(type(client.transport.list_instances), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( cloud_redis.ListInstancesResponse( @@ -704,9 +706,7 @@ async def test_list_instances_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instances), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_instances), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -743,9 +743,7 @@ async def test_list_instances_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_instances), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_instances), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -785,7 +783,7 @@ def test_get_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instance), "__call__") as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.Instance( name="name_value", @@ -815,6 +813,7 @@ def test_get_instance( assert args[0] == cloud_redis.GetInstanceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, cloud_redis.Instance) assert response.name == "name_value" @@ -855,19 +854,19 @@ def test_get_instance_from_dict(): @pytest.mark.asyncio -async def test_get_instance_async(transport: str = "grpc_asyncio"): +async def test_get_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.GetInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.GetInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.Instance( @@ -896,7 +895,7 @@ async def test_get_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.GetInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, cloud_redis.Instance) @@ -934,6 +933,11 @@ async def test_get_instance_async(transport: str = "grpc_asyncio"): assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING +@pytest.mark.asyncio +async def test_get_instance_async_from_dict(): + await test_get_instance_async(request_type=dict) + + def test_get_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -943,7 +947,7 @@ def test_get_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instance), "__call__") as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: call.return_value = cloud_redis.Instance() client.get_instance(request) @@ -968,9 +972,7 @@ async def test_get_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( cloud_redis.Instance() ) @@ -991,7 +993,7 @@ def test_get_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_instance), "__call__") as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.Instance() @@ -1023,9 +1025,7 @@ async def test_get_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_redis.Instance() @@ -1068,7 +1068,7 @@ def test_create_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_instance), "__call__") as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1089,19 +1089,19 @@ def test_create_instance_from_dict(): @pytest.mark.asyncio -async def test_create_instance_async(transport: str = "grpc_asyncio"): +async def test_create_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.CreateInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.CreateInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1113,12 +1113,17 @@ async def test_create_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.CreateInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_create_instance_async_from_dict(): + await test_create_instance_async(request_type=dict) + + def test_create_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1128,7 +1133,7 @@ def test_create_instance_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_instance), "__call__") as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.create_instance(request) @@ -1153,9 +1158,7 @@ async def test_create_instance_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1176,7 +1179,7 @@ def test_create_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_instance), "__call__") as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1219,9 +1222,7 @@ async def test_create_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1275,7 +1276,7 @@ def test_update_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_instance), "__call__") as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1296,19 +1297,19 @@ def test_update_instance_from_dict(): @pytest.mark.asyncio -async def test_update_instance_async(transport: str = "grpc_asyncio"): +async def test_update_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.UpdateInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.UpdateInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1320,12 +1321,17 @@ async def test_update_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.UpdateInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_update_instance_async_from_dict(): + await test_update_instance_async(request_type=dict) + + def test_update_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1335,7 +1341,7 @@ def test_update_instance_field_headers(): request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_instance), "__call__") as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.update_instance(request) @@ -1362,9 +1368,7 @@ async def test_update_instance_field_headers_async(): request.instance.name = "instance.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1387,7 +1391,7 @@ def test_update_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_instance), "__call__") as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1426,9 +1430,7 @@ async def test_update_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1478,9 +1480,7 @@ def test_upgrade_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1501,19 +1501,19 @@ def test_upgrade_instance_from_dict(): @pytest.mark.asyncio -async def test_upgrade_instance_async(transport: str = "grpc_asyncio"): +async def test_upgrade_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.UpgradeInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.UpgradeInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1525,12 +1525,17 @@ async def test_upgrade_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.UpgradeInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_upgrade_instance_async_from_dict(): + await test_upgrade_instance_async(request_type=dict) + + def test_upgrade_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1540,9 +1545,7 @@ def test_upgrade_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.upgrade_instance(request) @@ -1567,9 +1570,7 @@ async def test_upgrade_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1590,9 +1591,7 @@ def test_upgrade_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1630,9 +1629,7 @@ async def test_upgrade_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.upgrade_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.upgrade_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1681,7 +1678,7 @@ def test_import_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_instance), "__call__") as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1702,19 +1699,19 @@ def test_import_instance_from_dict(): @pytest.mark.asyncio -async def test_import_instance_async(transport: str = "grpc_asyncio"): +async def test_import_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.ImportInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.ImportInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1726,12 +1723,17 @@ async def test_import_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.ImportInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_import_instance_async_from_dict(): + await test_import_instance_async(request_type=dict) + + def test_import_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1741,7 +1743,7 @@ def test_import_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_instance), "__call__") as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.import_instance(request) @@ -1766,9 +1768,7 @@ async def test_import_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1789,7 +1789,7 @@ def test_import_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.import_instance), "__call__") as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1834,9 +1834,7 @@ async def test_import_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1892,7 +1890,7 @@ def test_export_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_instance), "__call__") as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1913,19 +1911,19 @@ def test_export_instance_from_dict(): @pytest.mark.asyncio -async def test_export_instance_async(transport: str = "grpc_asyncio"): +async def test_export_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.ExportInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.ExportInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1937,12 +1935,17 @@ async def test_export_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.ExportInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_export_instance_async_from_dict(): + await test_export_instance_async(request_type=dict) + + def test_export_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -1952,7 +1955,7 @@ def test_export_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_instance), "__call__") as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.export_instance(request) @@ -1977,9 +1980,7 @@ async def test_export_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -2000,7 +2001,7 @@ def test_export_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.export_instance), "__call__") as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2045,9 +2046,7 @@ async def test_export_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2104,7 +2103,7 @@ def test_failover_instance( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -2126,18 +2125,20 @@ def test_failover_instance_from_dict(): @pytest.mark.asyncio -async def test_failover_instance_async(transport: str = "grpc_asyncio"): +async def test_failover_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.FailoverInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.FailoverInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2150,12 +2151,17 @@ async def test_failover_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.FailoverInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_failover_instance_async_from_dict(): + await test_failover_instance_async(request_type=dict) + + def test_failover_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -2166,7 +2172,7 @@ def test_failover_instance_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") @@ -2193,7 +2199,7 @@ async def test_failover_instance_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") @@ -2216,7 +2222,7 @@ def test_failover_instance_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2260,7 +2266,7 @@ async def test_failover_instance_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.failover_instance), "__call__" + type(client.transport.failover_instance), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2314,7 +2320,7 @@ def test_delete_instance( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_instance), "__call__") as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -2335,19 +2341,19 @@ def test_delete_instance_from_dict(): @pytest.mark.asyncio -async def test_delete_instance_async(transport: str = "grpc_asyncio"): +async def test_delete_instance_async( + transport: str = "grpc_asyncio", request_type=cloud_redis.DeleteInstanceRequest +): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = cloud_redis.DeleteInstanceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -2359,12 +2365,17 @@ async def test_delete_instance_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == cloud_redis.DeleteInstanceRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_delete_instance_async_from_dict(): + await test_delete_instance_async(request_type=dict) + + def test_delete_instance_field_headers(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) @@ -2374,7 +2385,7 @@ def test_delete_instance_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_instance), "__call__") as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.delete_instance(request) @@ -2399,9 +2410,7 @@ async def test_delete_instance_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -2422,7 +2431,7 @@ def test_delete_instance_flattened(): client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_instance), "__call__") as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2454,9 +2463,7 @@ async def test_delete_instance_flattened_async(): client = CloudRedisAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_instance), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2523,7 +2530,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = CloudRedisClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -2556,7 +2563,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CloudRedisClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.CloudRedisGrpcTransport,) + assert isinstance(client.transport, transports.CloudRedisGrpcTransport,) def test_cloud_redis_base_transport_error(): @@ -2663,7 +2670,7 @@ def test_cloud_redis_host_no_port(): api_endpoint="redis.googleapis.com" ), ) - assert client._transport._host == "redis.googleapis.com:443" + assert client.transport._host == "redis.googleapis.com:443" def test_cloud_redis_host_with_port(): @@ -2673,7 +2680,7 @@ def test_cloud_redis_host_with_port(): api_endpoint="redis.googleapis.com:8000" ), ) - assert client._transport._host == "redis.googleapis.com:8000" + assert client.transport._host == "redis.googleapis.com:8000" def test_cloud_redis_grpc_transport_channel(): @@ -2685,6 +2692,7 @@ def test_cloud_redis_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_cloud_redis_grpc_asyncio_transport_channel(): @@ -2696,6 +2704,7 @@ def test_cloud_redis_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -2736,8 +2745,13 @@ def test_cloud_redis_transport_channel_mtls_with_client_cert_source(transport_cl scopes=("https://www.googleapis.com/auth/cloud-platform",), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -2773,6 +2787,10 @@ def test_cloud_redis_transport_channel_mtls_with_adc(transport_class): scopes=("https://www.googleapis.com/auth/cloud-platform",), ssl_credentials=mock_ssl_cred, quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) assert transport.grpc_channel == mock_grpc_channel @@ -2781,7 +2799,7 @@ def test_cloud_redis_grpc_lro_client(): client = CloudRedisClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -2794,7 +2812,7 @@ def test_cloud_redis_grpc_lro_async_client(): client = CloudRedisAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -2828,6 +2846,107 @@ def test_parse_instance_path(): assert expected == actual +def test_common_billing_account_path(): + billing_account = "cuttlefish" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = CloudRedisClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = CloudRedisClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "winkle" + + expected = "folders/{folder}".format(folder=folder,) + actual = CloudRedisClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nautilus", + } + path = CloudRedisClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "scallop" + + expected = "organizations/{organization}".format(organization=organization,) + actual = CloudRedisClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "abalone", + } + path = CloudRedisClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "squid" + + expected = "projects/{project}".format(project=project,) + actual = CloudRedisClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = CloudRedisClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "whelk" + location = "octopus" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = CloudRedisClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + } + path = CloudRedisClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = CloudRedisClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo()