async def test_report_error_event_field_headers_async():
    client = ReportErrorsServiceAsyncClient(
        credentials=ga_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 = report_errors_service.ReportErrorEventRequest()

    request.project_name = "project_name/value"

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client.transport.report_error_event),
                           "__call__") as call:
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            report_errors_service.ReportErrorEventResponse())
        await client.report_error_event(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",
        "project_name=project_name/value",
    ) in kw["metadata"]
async def test_report_error_event_async(
    transport: str = "grpc_asyncio",
    request_type=report_errors_service.ReportErrorEventRequest,
):
    client = ReportErrorsServiceAsyncClient(
        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.report_error_event),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
            report_errors_service.ReportErrorEventResponse())
        response = await client.report_error_event(request)

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

    # Establish that the response is the type that we expect.
    assert isinstance(response, report_errors_service.ReportErrorEventResponse)
async def test_report_error_event_flattened_error_async():
    client = ReportErrorsServiceAsyncClient(
        credentials=ga_credentials.AnonymousCredentials(), )

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        await client.report_error_event(
            report_errors_service.ReportErrorEventRequest(),
            project_name="project_name_value",
            event=report_errors_service.ReportedErrorEvent(
                event_time=timestamp_pb2.Timestamp(seconds=751)),
        )
def test_report_error_event_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 = ReportErrorsServiceClient(
        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.report_error_event),
                           "__call__") as call:
        client.report_error_event()
        call.assert_called()
        _, args, _ = call.mock_calls[0]
        assert args[0] == report_errors_service.ReportErrorEventRequest()
    def report_error_event(
        self,
        request: report_errors_service.ReportErrorEventRequest = None,
        *,
        project_name: str = None,
        event: report_errors_service.ReportedErrorEvent = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> report_errors_service.ReportErrorEventResponse:
        r"""Report an individual error event and record the event to a log.

        This endpoint accepts **either** an OAuth token, **or** an `API
        key <https://support.google.com/cloud/answer/6158862>`__ for
        authentication. To use an API key, append it to the URL as the
        value of a ``key`` parameter. For example:

        ``POST https://clouderrorreporting.googleapis.com/v1beta1/{projectName}/events:report?key=123ABC456``

        **Note:** `Error Reporting </error-reporting>`__ is a global
        service built on Cloud Logging and doesn't analyze logs stored
        in regional log buckets or logs routed to other Google Cloud
        projects.

        For more information, see `Using Error Reporting with
        regionalized logs </error-reporting/docs/regionalization>`__.

        Args:
            request (google.cloud.errorreporting_v1beta1.types.ReportErrorEventRequest):
                The request object. A request for reporting an
                individual error event.
            project_name (str):
                Required. The resource name of the Google Cloud Platform
                project. Written as ``projects/{projectId}``, where
                ``{projectId}`` is the `Google Cloud Platform project
                ID <https://support.google.com/cloud/answer/6158840>`__.

                Example: // ``projects/my-project-123``.

                This corresponds to the ``project_name`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            event (google.cloud.errorreporting_v1beta1.types.ReportedErrorEvent):
                Required. The error event to be
                reported.

                This corresponds to the ``event`` 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.ReportErrorEventResponse:
                Response for reporting an individual
                error event. Data may be added to this
                message in the future.

        """
        # 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([project_name, event])
        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 report_errors_service.ReportErrorEventRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(request,
                          report_errors_service.ReportErrorEventRequest):
            request = report_errors_service.ReportErrorEventRequest(request)
            # If we have keyword arguments corresponding to fields on the
            # request, apply these.
            if project_name is not None:
                request.project_name = project_name
            if event is not None:
                request.event = event

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

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

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

        # Done; return the response.
        return response
    async def report_error_event(
        self,
        request: report_errors_service.ReportErrorEventRequest = None,
        *,
        project_name: str = None,
        event: report_errors_service.ReportedErrorEvent = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> report_errors_service.ReportErrorEventResponse:
        r"""Report an individual error event.

        This endpoint accepts **either** an OAuth token, **or** an `API
        key <https://support.google.com/cloud/answer/6158862>`__ for
        authentication. To use an API key, append it to the URL as the
        value of a ``key`` parameter. For example:

        ``POST https://clouderrorreporting.googleapis.com/v1beta1/projects/example-project/events:report?key=123ABC456``

        Args:
            request (:class:`~.report_errors_service.ReportErrorEventRequest`):
                The request object. A request for reporting an
                individual error event.
            project_name (:class:`str`):
                Required. The resource name of the Google Cloud Platform
                project. Written as ``projects/`` plus the `Google Cloud
                Platform project
                ID <https://support.google.com/cloud/answer/6158840>`__.
                Example: ``projects/my-project-123``.
                This corresponds to the ``project_name`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            event (:class:`~.report_errors_service.ReportedErrorEvent`):
                Required. The error event to be
                reported.
                This corresponds to the ``event`` 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:
            ~.report_errors_service.ReportErrorEventResponse:
                Response for reporting an individual
                error event. Data may be added to this
                message in the future.

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

        request = report_errors_service.ReportErrorEventRequest(request)

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

        if project_name is not None:
            request.project_name = project_name
        if event is not None:
            request.event = event

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method_async.wrap_method(
            self._client._transport.report_error_event,
            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(
            (("project_name", request.project_name), )), )

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

        # Done; return the response.
        return response