def test_list_services(transport: str = "grpc"): client = CloudCatalogClient(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 = cloud_catalog.ListServicesRequest() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client._transport.list_services), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = cloud_catalog.ListServicesResponse( next_page_token="next_page_token_value") response = client.list_services(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0] == request # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListServicesPager) assert response.next_page_token == "next_page_token_value"
def list_services( self, request: Union[cloud_catalog.ListServicesRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListServicesPager: r"""Lists all public cloud services. Args: request (Union[google.cloud.billing_v1.types.ListServicesRequest, dict]): The request object. Request message for `ListServices`. 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.billing_v1.services.cloud_catalog.pagers.ListServicesPager: Response message for ListServices. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a cloud_catalog.ListServicesRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, cloud_catalog.ListServicesRequest): request = cloud_catalog.ListServicesRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_services] # Send the request. response = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. response = pagers.ListServicesPager( method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. return response
def list_services( self, request: cloud_catalog.ListServicesRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListServicesPager: r"""Lists all public cloud services. Args: request (:class:`~.cloud_catalog.ListServicesRequest`): The request object. Request message for `ListServices`. 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: ~.pagers.ListServicesPager: Response message for ``ListServices``. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. request = cloud_catalog.ListServicesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method.wrap_method( self._transport.list_services, default_timeout=None, client_info=_client_info, ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata) # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. response = pagers.ListServicesPager(method=rpc, request=request, response=response) # Done; return the response. return response
async def list_services( self, request: Union[cloud_catalog.ListServicesRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListServicesAsyncPager: r"""Lists all public cloud services. Args: request (Union[google.cloud.billing_v1.types.ListServicesRequest, dict]): The request object. Request message for `ListServices`. 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.billing_v1.services.cloud_catalog.pagers.ListServicesAsyncPager: Response message for ListServices. Iterating over this object will yield results and resolve additional pages automatically. """ # Create or coerce a protobuf request object. request = cloud_catalog.ListServicesRequest(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.list_services, default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # This method is paged; wrap the response in a pager, which provides # an `__aiter__` convenience method. response = pagers.ListServicesAsyncPager( method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. return response
def __init__( self, method: Callable[[cloud_catalog.ListServicesRequest], cloud_catalog.ListServicesResponse], request: cloud_catalog.ListServicesRequest, response: cloud_catalog.ListServicesResponse, ): """Instantiate the pager. Args: method (Callable): The method that was originally called, and which instantiated this pager. request (:class:`~.cloud_catalog.ListServicesRequest`): The initial request object. response (:class:`~.cloud_catalog.ListServicesResponse`): The initial response object. """ self._method = method self._request = cloud_catalog.ListServicesRequest(request) self._response = response
def __init__(self, method: Callable[..., cloud_catalog.ListServicesResponse], request: cloud_catalog.ListServicesRequest, response: cloud_catalog.ListServicesResponse, *, metadata: Sequence[Tuple[str, str]] = ()): """Instantiate the pager. Args: method (Callable): The method that was originally called, and which instantiated this pager. request (google.cloud.billing_v1.types.ListServicesRequest): The initial request object. response (google.cloud.billing_v1.types.ListServicesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. """ self._method = method self._request = cloud_catalog.ListServicesRequest(request) self._response = response self._metadata = metadata