def test_list_workflow_templates(self): # Setup Expected Response next_page_token = "" templates_element = {} templates = [templates_element] expected_response = { "next_page_token": next_page_token, "templates": templates } expected_response = workflow_templates_pb2.ListWorkflowTemplatesResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = dataproc_v1.WorkflowTemplateServiceClient() # Setup Request parent = client.region_path("[PROJECT]", "[REGION]") paged_list_response = client.list_workflow_templates(parent) resources = list(paged_list_response) assert len(resources) == 1 assert expected_response.templates[0] == resources[0] assert len(channel.requests) == 1 expected_request = workflow_templates_pb2.ListWorkflowTemplatesRequest( parent=parent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def list_workflow_templates( self, parent, page_size=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Lists workflows that match the specified filter in the request. Example: >>> from google.cloud import dataproc_v1 >>> >>> client = dataproc_v1.WorkflowTemplateServiceClient() >>> >>> parent = client.region_path('[PROJECT]', '[REGION]') >>> >>> # Iterate over all results >>> for element in client.list_workflow_templates(parent): ... # process element ... pass >>> >>> >>> # Alternatively: >>> >>> # Iterate over results one page at a time >>> for page in client.list_workflow_templates(parent).pages: ... for element in page: ... # process element ... pass Args: parent (str): Required. The resource name of the region or location, as described in https://cloud.google.com/apis/design/resource\_names. - For ``projects.regions.workflowTemplates,list``, the resource name of the region has the following format: ``projects/{project_id}/regions/{region}`` - For ``projects.locations.workflowTemplates.list``, the resource name of the location has the following format: ``projects/{project_id}/locations/{location}`` page_size (int): The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page. retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will be retried using a default configuration. timeout (Optional[float]): The amount of time, in seconds, to wait for the request to complete. Note that if ``retry`` is specified, the timeout applies to each individual attempt. metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata that is provided to the method. Returns: A :class:`~google.api_core.page_iterator.PageIterator` instance. An iterable of :class:`~google.cloud.dataproc_v1.types.WorkflowTemplate` instances. You can also iterate over the pages of the response using its `pages` property. Raises: google.api_core.exceptions.GoogleAPICallError: If the request failed for any reason. google.api_core.exceptions.RetryError: If the request failed due to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. if "list_workflow_templates" not in self._inner_api_calls: self._inner_api_calls[ "list_workflow_templates"] = google.api_core.gapic_v1.method.wrap_method( self.transport.list_workflow_templates, default_retry=self. _method_configs["ListWorkflowTemplates"].retry, default_timeout=self. _method_configs["ListWorkflowTemplates"].timeout, client_info=self._client_info, ) request = workflow_templates_pb2.ListWorkflowTemplatesRequest( parent=parent, page_size=page_size) if metadata is None: metadata = [] metadata = list(metadata) try: routing_header = [("parent", parent)] except AttributeError: pass else: routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata( routing_header) metadata.append(routing_metadata) iterator = google.api_core.page_iterator.GRPCIterator( client=None, method=functools.partial( self._inner_api_calls["list_workflow_templates"], retry=retry, timeout=timeout, metadata=metadata, ), request=request, items_field="templates", request_token_field="page_token", response_token_field="next_page_token", ) return iterator