async def test_resolve_service_async( transport: str = "grpc_asyncio", request_type=lookup_service.ResolveServiceRequest): client = LookupServiceAsyncClient( 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.resolve_service), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( lookup_service.ResolveServiceResponse()) response = await client.resolve_service(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] assert args[0] == lookup_service.ResolveServiceRequest() # Establish that the response is the type that we expect. assert isinstance(response, lookup_service.ResolveServiceResponse)
async def test_resolve_service_field_headers_async(): client = LookupServiceAsyncClient( 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 = lookup_service.ResolveServiceRequest() request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.resolve_service), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( lookup_service.ResolveServiceResponse()) await client.resolve_service(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", "name=name/value", ) in kw["metadata"]
async def resolve_service( self, request: lookup_service.ResolveServiceRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> lookup_service.ResolveServiceResponse: r"""Returns a [service][google.cloud.servicedirectory.v1beta1.Service] and its associated endpoints. Resolving a service is not considered an active developer method. Args: request (:class:`google.cloud.servicedirectory_v1beta1.types.ResolveServiceRequest`): The request object. The request message for [LookupService.ResolveService][google.cloud.servicedirectory.v1beta1.LookupService.ResolveService]. Looks up a service by its name, returns the service and its endpoints. 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.servicedirectory_v1beta1.types.ResolveServiceResponse: The response message for [LookupService.ResolveService][google.cloud.servicedirectory.v1beta1.LookupService.ResolveService]. """ # Create or coerce a protobuf request object. request = lookup_service.ResolveServiceRequest(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.resolve_service, 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( (("name", request.name), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
def resolve_service( self, request: lookup_service.ResolveServiceRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> lookup_service.ResolveServiceResponse: r"""Returns a [service][google.cloud.servicedirectory.v1beta1.Service] and its associated endpoints. Resolving a service is not considered an active developer method. Args: request (google.cloud.servicedirectory_v1beta1.types.ResolveServiceRequest): The request object. The request message for [LookupService.ResolveService][google.cloud.servicedirectory.v1beta1.LookupService.ResolveService]. Looks up a service by its name, returns the service and its endpoints. 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.servicedirectory_v1beta1.types.ResolveServiceResponse: The response message for [LookupService.ResolveService][google.cloud.servicedirectory.v1beta1.LookupService.ResolveService]. """ # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a lookup_service.ResolveServiceRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, lookup_service.ResolveServiceRequest): request = lookup_service.ResolveServiceRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.resolve_service] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response
def test_resolve_service_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 = LookupServiceClient( 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.resolve_service), "__call__") as call: client.resolve_service() call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == lookup_service.ResolveServiceRequest()