Exemple #1
0
async def test_update_group_field_headers_async():
    client = ErrorGroupServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Any value that is part of the HTTP/1.1 URI should be sent as
    # a field header. Set these to a non-empty value.
    request = error_group_service.UpdateGroupRequest()
    request.group.name = "group.name/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.update_group),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            common.ErrorGroup())

        await client.update_group(request)

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

    # Establish that the field header was sent.
    _, _, kw = call.mock_calls[0]
    assert (
        "x-goog-request-params",
        "group.name=group.name/value",
    ) in kw["metadata"]
Exemple #2
0
async def test_update_group_async(transport: str = "grpc_asyncio"):
    client = ErrorGroupServiceAsyncClient(
        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 = error_group_service.UpdateGroupRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.update_group),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            common.ErrorGroup(
                name="name_value",
                group_id="group_id_value",
            ))

        response = await client.update_group(request)

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

        assert args[0] == request

    # Establish that the response is the type that we expect.
    assert isinstance(response, common.ErrorGroup)

    assert response.name == "name_value"

    assert response.group_id == "group_id_value"
Exemple #3
0
async def test_update_group_flattened_error_async():
    client = ErrorGroupServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        await client.update_group(
            error_group_service.UpdateGroupRequest(),
            group=common.ErrorGroup(name="name_value"),
        )
Exemple #4
0
    def update_group(
        self,
        request: error_group_service.UpdateGroupRequest = None,
        *,
        group: common.ErrorGroup = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> common.ErrorGroup:
        r"""Replace the data for the specified group.
        Fails if the group does not exist.

        Args:
            request (google.cloud.errorreporting_v1beta1.types.UpdateGroupRequest):
                The request object. A request to replace the existing
                data for the given group.
            group (google.cloud.errorreporting_v1beta1.types.ErrorGroup):
                Required. The group which replaces
                the resource on the server.

                This corresponds to the ``group`` 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:
            google.cloud.errorreporting_v1beta1.types.ErrorGroup:
                Description of a group of similar
                error events.

        """
        # 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([group])
        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 error_group_service.UpdateGroupRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(request, error_group_service.UpdateGroupRequest):
            request = error_group_service.UpdateGroupRequest(request)

            # If we have keyword arguments corresponding to fields on the
            # request, apply these.

            if group is not None:
                request.group = group

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

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (
            gapic_v1.routing_header.to_grpc_metadata(
                (("group.name", request.group.name),)
            ),
        )

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

        # Done; return the response.
        return response
    async def update_group(
            self,
            request: error_group_service.UpdateGroupRequest = None,
            *,
            group: common.ErrorGroup = None,
            retry: retries.Retry = gapic_v1.method.DEFAULT,
            timeout: float = None,
            metadata: Sequence[Tuple[str, str]] = (),
    ) -> common.ErrorGroup:
        r"""Replace the data for the specified group.
        Fails if the group does not exist.

        Args:
            request (:class:`~.error_group_service.UpdateGroupRequest`):
                The request object. A request to replace the existing
                data for the given group.
            group (:class:`~.common.ErrorGroup`):
                Required. The group which replaces
                the resource on the server.
                This corresponds to the ``group`` 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:
            ~.common.ErrorGroup:
                Description of a group of similar
                error events.

        """
        # 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([group]):
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        request = error_group_service.UpdateGroupRequest(request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.

        if group is not None:
            request.group = group

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method_async.wrap_method(
            self._client._transport.update_group,
            default_timeout=None,
            client_info=DEFAULT_CLIENT_INFO,
        )

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("group.name", request.group.name), )), )

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

        # Done; return the response.
        return response