async def test_check_async(transport: str = 'grpc_asyncio',
                           request_type=service_controller.CheckRequest):
    client = ServiceControllerAsyncClient(
        credentials=ga_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.check), '__call__') as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            service_controller.CheckResponse(
                operation_id='operation_id_value',
                service_config_id='service_config_id_value',
                service_rollout_id='service_rollout_id_value',
            ))
        response = await client.check(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]
        assert args[0] == service_controller.CheckRequest()

    # Establish that the response is the type that we expect.
    assert isinstance(response, service_controller.CheckResponse)
    assert response.operation_id == 'operation_id_value'
    assert response.service_config_id == 'service_config_id_value'
    assert response.service_rollout_id == 'service_rollout_id_value'
def test_check_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 = ServiceControllerClient(
        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.check), "__call__") as call:
        client.check()
        call.assert_called()
        _, args, _ = call.mock_calls[0]
        assert args[0] == service_controller.CheckRequest()
Example #3
0
    def check(
        self,
        request: service_controller.CheckRequest = None,
        *,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> service_controller.CheckResponse:
        r"""Checks whether an operation on a service should be allowed to
        proceed based on the configuration of the service and related
        policies. It must be called before the operation is executed.

        If feasible, the client should cache the check results and reuse
        them for 60 seconds. In case of any server errors, the client
        should rely on the cached results for much longer time to avoid
        outage. WARNING: There is general 60s delay for the
        configuration and policy propagation, therefore callers MUST NOT
        depend on the ``Check`` method having the latest policy
        information.

        NOTE: the
        [CheckRequest][google.api.servicecontrol.v1.CheckRequest] has
        the size limit of 64KB.

        This method requires the ``servicemanagement.services.check``
        permission on the specified service. For more information, see
        `Cloud IAM <https://cloud.google.com/iam>`__.

        Args:
            request (google.cloud.servicecontrol_v1.types.CheckRequest):
                The request object. Request message for the Check
                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.CheckResponse:
                Response message for the Check
                method.

        """
        # Create or coerce a protobuf request object.

        # Minor optimization to avoid making a copy if the user passes
        # in a service_controller.CheckRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(request, service_controller.CheckRequest):
            request = service_controller.CheckRequest(request)

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = self._transport._wrapped_methods[self._transport.check]

        # Send the request.
        response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

        # Done; return the response.
        return response
Example #4
0
    async def check(self,
            request: service_controller.CheckRequest = None,
            *,
            retry: retries.Retry = gapic_v1.method.DEFAULT,
            timeout: float = None,
            metadata: Sequence[Tuple[str, str]] = (),
            ) -> service_controller.CheckResponse:
        r"""Checks whether an operation on a service should be allowed to
        proceed based on the configuration of the service and related
        policies. It must be called before the operation is executed.

        If feasible, the client should cache the check results and reuse
        them for 60 seconds. In case of any server errors, the client
        should rely on the cached results for much longer time to avoid
        outage. WARNING: There is general 60s delay for the
        configuration and policy propagation, therefore callers MUST NOT
        depend on the ``Check`` method having the latest policy
        information.

        NOTE: the
        [CheckRequest][google.api.servicecontrol.v1.CheckRequest] has
        the size limit (wire-format byte size) of 1MB.

        This method requires the ``servicemanagement.services.check``
        permission on the specified service. For more information, see
        `Cloud IAM <https://cloud.google.com/iam>`__.

        Args:
            request (:class:`google.cloud.servicecontrol_v1.types.CheckRequest`):
                The request object. Request message for the Check
                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.CheckResponse:
                Response message for the Check
                method.

        """
        # Create or coerce a protobuf request object.
        request = service_controller.CheckRequest(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.check,
            default_retry=retries.Retry(
initial=1.0,maximum=10.0,multiplier=1.3,                predicate=retries.if_exception_type(
                    core_exceptions.ServiceUnavailable,
                ),
                deadline=5.0,
            ),
            default_timeout=5.0,
            client_info=DEFAULT_CLIENT_INFO,
        )

        # Send the request.
        response = await rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )

        # Done; return the response.
        return response