async def test_allocate_quota_async( transport: str = "grpc_asyncio", request_type=quota_controller.AllocateQuotaRequest ): client = QuotaControllerAsyncClient( 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 = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.allocate_quota), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( quota_controller.AllocateQuotaResponse( operation_id="operation_id_value", service_config_id="service_config_id_value", ) ) response = await client.allocate_quota(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] assert args[0] == quota_controller.AllocateQuotaRequest() # Establish that the response is the type that we expect. assert isinstance(response, quota_controller.AllocateQuotaResponse) assert response.operation_id == "operation_id_value" assert response.service_config_id == "service_config_id_value"
async def allocate_quota( self, request: quota_controller.AllocateQuotaRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> quota_controller.AllocateQuotaResponse: r"""Attempts to allocate quota for the specified consumer. It should be called before the operation is executed. This method requires the ``servicemanagement.services.quota`` permission on the specified service. For more information, see `Cloud IAM <https://cloud.google.com/iam>`__. **NOTE:** The client **must** fail-open on server errors ``INTERNAL``, ``UNKNOWN``, ``DEADLINE_EXCEEDED``, and ``UNAVAILABLE``. To ensure system reliability, the server may inject these errors to prohibit any hard dependency on the quota functionality. Args: request (:class:`google.cloud.servicecontrol_v1.types.AllocateQuotaRequest`): The request object. Request message for the AllocateQuota method. 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: google.cloud.servicecontrol_v1.types.AllocateQuotaResponse: Response message for the AllocateQuota method. """ # Create or coerce a protobuf request object. request = quota_controller.AllocateQuotaRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.allocate_quota, default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
def allocate_quota( self, request: quota_controller.AllocateQuotaRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> quota_controller.AllocateQuotaResponse: r"""Attempts to allocate quota for the specified consumer. It should be called before the operation is executed. This method requires the ``servicemanagement.services.quota`` permission on the specified service. For more information, see `Cloud IAM <https://cloud.google.com/iam>`__. **NOTE:** The client **must** fail-open on server errors ``INTERNAL``, ``UNKNOWN``, ``DEADLINE_EXCEEDED``, and ``UNAVAILABLE``. To ensure system reliability, the server may inject these errors to prohibit any hard dependency on the quota functionality. Args: request (google.cloud.servicecontrol_v1.types.AllocateQuotaRequest): The request object. Request message for the AllocateQuota method. 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: google.cloud.servicecontrol_v1.types.AllocateQuotaResponse: Response message for the AllocateQuota method. """ # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a quota_controller.AllocateQuotaRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, quota_controller.AllocateQuotaRequest): request = quota_controller.AllocateQuotaRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.allocate_quota] # Send the request. response = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
def test_allocate_quota_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = QuotaControllerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.allocate_quota), "__call__") as call: client.allocate_quota() call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == quota_controller.AllocateQuotaRequest()