def test_update_instance_flattened_error(): client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.update_instance( cloud_memcache.UpdateInstanceRequest(), update_mask=field_mask.FieldMask(paths=["paths_value"]), resource=cloud_memcache.Instance(name="name_value"), )
def test_update_instance(transport: str = "grpc"): client = CloudMemcacheClient( 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_memcache.UpdateInstanceRequest() # Mock the actual call within the gRPC stub, and fake the request. 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") response = client.update_instance(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, future.Future)
def update_instance( self, request: cloud_memcache.UpdateInstanceRequest = None, *, update_mask: field_mask.FieldMask = None, resource: cloud_memcache.Instance = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates an existing Instance in a given project and location. Args: request (:class:`~.cloud_memcache.UpdateInstanceRequest`): The request object. Request for [UpdateInstance][google.cloud.memcache.v1beta2.CloudMemcache.UpdateInstance]. update_mask (:class:`~.field_mask.FieldMask`): Required. Mask of fields to update. - ``displayName`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. resource (:class:`~.cloud_memcache.Instance`): Required. A Memcached [Instance] resource. Only fields specified in update_mask are updated. This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.operation.Operation: An object representing a long-running operation. The result type for the operation will be :class:``~.cloud_memcache.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 any([update_mask, resource]): raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = cloud_memcache.UpdateInstanceRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if update_mask is not None: request.update_mask = update_mask if resource is not None: request.resource = resource # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method.wrap_method( self._transport.update_instance, default_timeout=None, client_info=_client_info, ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, cloud_memcache.Instance, metadata_type=cloud_memcache.OperationMetadata, ) # Done; return the response. return response
def update_instance( self, request: cloud_memcache.UpdateInstanceRequest = None, *, update_mask: field_mask.FieldMask = None, resource: cloud_memcache.Instance = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Updates an existing Instance in a given project and location. Args: request (:class:`~.cloud_memcache.UpdateInstanceRequest`): The request object. Request for [UpdateInstance][google.cloud.memcache.v1beta2.CloudMemcache.UpdateInstance]. update_mask (:class:`~.field_mask.FieldMask`): Required. Mask of fields to update. - ``displayName`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. resource (:class:`~.cloud_memcache.Instance`): Required. A Memcached [Instance] resource. Only fields specified in update_mask are updated. This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.operation.Operation: An object representing a long-running operation. The result type for the operation will be :class:``~.cloud_memcache.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. has_flattened_params = any([update_mask, resource]) 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." ) # Minor optimization to avoid making a copy if the user passes # in a cloud_memcache.UpdateInstanceRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, cloud_memcache.UpdateInstanceRequest): request = cloud_memcache.UpdateInstanceRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if update_mask is not None: request.update_mask = update_mask if resource is not None: request.resource = resource # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_instance] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( (("resource.name", request.resource.name),) ), ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Wrap the response in an operation future. response = operation.from_gapic( response, self._transport.operations_client, cloud_memcache.Instance, metadata_type=cloud_memcache.OperationMetadata, ) # Done; return the response. return response