async def test_create_client_event_field_headers_async(): client = EventServiceAsyncClient( 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 = event_service.CreateClientEventRequest() request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client._client._transport.create_client_event), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( event.ClientEvent()) await client.create_client_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", "parent=parent/value", ) in kw["metadata"]
async def test_create_client_event_async( transport: str = "grpc_asyncio", request_type=event_service.CreateClientEventRequest): client = EventServiceAsyncClient( 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.create_client_event), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( event.ClientEvent( request_id="request_id_value", event_id="event_id_value", event_notes="event_notes_value", )) response = await client.create_client_event(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] assert args[0] == event_service.CreateClientEventRequest() # Establish that the response is the type that we expect. assert isinstance(response, event.ClientEvent) assert response.request_id == "request_id_value" assert response.event_id == "event_id_value" assert response.event_notes == "event_notes_value"
async def test_create_client_event_flattened_error_async(): client = EventServiceAsyncClient( 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.create_client_event( event_service.CreateClientEventRequest(), parent="parent_value", client_event=event.ClientEvent(request_id="request_id_value"), )
def test_create_client_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 = EventServiceClient( 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.create_client_event), "__call__") as call: client.create_client_event() call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == event_service.CreateClientEventRequest()
async def create_client_event( self, request: event_service.CreateClientEventRequest = None, *, parent: str = None, client_event: event.ClientEvent = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> event.ClientEvent: r"""Report events issued when end user interacts with customer's application that uses Cloud Talent Solution. You may inspect the created events in `self service tools <https://console.cloud.google.com/talent-solution/overview>`__. `Learn more <https://cloud.google.com/talent-solution/docs/management-tools>`__ about self service tools. Args: request (:class:`google.cloud.talent_v4.types.CreateClientEventRequest`): The request object. The report event request. parent (:class:`str`): Required. Resource name of the tenant under which the event is created. The format is "projects/{project_id}/tenants/{tenant_id}", for example, "projects/foo/tenants/bar". This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. client_event (:class:`google.cloud.talent_v4.types.ClientEvent`): Required. Events issued when end user interacts with customer's application that uses Cloud Talent Solution. This corresponds to the ``client_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.talent_v4.types.ClientEvent: An event issued when an end user interacts with the application that implements Cloud Talent Solution. Providing this information improves the quality of results for the API clients, enabling the service to perform optimally. The number of events sent must be consistent with other calls, such as job searches, issued to the service by the client. """ # 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([parent, client_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.") request = event_service.CreateClientEventRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent if client_event is not None: request.client_event = client_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.create_client_event, default_timeout=30.0, 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( (("parent", request.parent), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response