def test_list_transfer_configs(self):
        # Setup Expected Response
        next_page_token = ""
        transfer_configs_element = {}
        transfer_configs = [transfer_configs_element]
        expected_response = {
            "next_page_token": next_page_token,
            "transfer_configs": transfer_configs,
        }
        expected_response = datatransfer_pb2.ListTransferConfigsResponse(
            **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 = bigquery_datatransfer_v1.DataTransferServiceClient()

        # Setup Request
        parent = client.project_path("[PROJECT]")

        paged_list_response = client.list_transfer_configs(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.transfer_configs[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = datatransfer_pb2.ListTransferConfigsRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #2
0
    def test_list_transfer_configs(self):
        # Setup Expected Response
        next_page_token = ''
        transfer_configs_element = {}
        transfer_configs = [transfer_configs_element]
        expected_response = {
            'next_page_token': next_page_token,
            'transfer_configs': transfer_configs
        }
        expected_response = datatransfer_pb2.ListTransferConfigsResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = bigquery_datatransfer_v1.DataTransferServiceClient(
            channel=channel)

        # Setup Request
        parent = client.project_path('[PROJECT]')

        paged_list_response = client.list_transfer_configs(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.transfer_configs[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = datatransfer_pb2.ListTransferConfigsRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #3
0
    def list_transfer_configs(self,
                              parent,
                              data_source_ids=None,
                              page_size=None,
                              retry=google.api_core.gapic_v1.method.DEFAULT,
                              timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Returns information about all data transfers in the project.

        Example:
            >>> from google.cloud import bigquery_datatransfer_v1
            >>>
            >>> client = bigquery_datatransfer_v1.DataTransferServiceClient()
            >>>
            >>> parent = client.location_path('[PROJECT]', '[LOCATION]')
            >>>
            >>>
            >>> # Iterate over all results
            >>> for element in client.list_transfer_configs(parent):
            ...     # process element
            ...     pass
            >>>
            >>> # Or iterate over results one page at a time
            >>> for page in client.list_transfer_configs(parent, options=CallOptions(page_token=INITIAL_PAGE)):
            ...     for element in page:
            ...         # process element
            ...         pass

        Args:
            parent (str): The BigQuery project id for which data sources
                should be returned: ``projects/{project_id}``.
            data_source_ids (list[str]): When specified, only configurations of requested data sources are returned.
            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 not
                be retried.
            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.

        Returns:
            A :class:`~google.gax.PageIterator` instance. By default, this
            is an iterable of :class:`~google.cloud.bigquery_datatransfer_v1.types.TransferConfig` instances.
            This object can also be configured to iterate over the pages
            of the response through the `options` parameter.

        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.
        """
        request = datatransfer_pb2.ListTransferConfigsRequest(
            parent=parent,
            data_source_ids=data_source_ids,
            page_size=page_size)
        iterator = google.api_core.page_iterator.GRPCIterator(
            client=None,
            method=functools.partial(self._list_transfer_configs,
                                     retry=retry,
                                     timeout=timeout),
            request=request,
            items_field='transfer_configs',
            request_token_field='page_token',
            response_token_field='next_page_token')
        return iterator