def test_get_transfer_run(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        destination_dataset_id = "destinationDatasetId1541564179"
        data_source_id = "dataSourceId-1015796374"
        user_id = 147132913
        schedule = "schedule-697920873"
        notification_pubsub_topic = "notificationPubsubTopic1794281191"
        expected_response = {
            "name": name_2,
            "destination_dataset_id": destination_dataset_id,
            "data_source_id": data_source_id,
            "user_id": user_id,
            "schedule": schedule,
            "notification_pubsub_topic": notification_pubsub_topic,
        }
        expected_response = transfer_pb2.TransferRun(**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
        name = client.project_run_path("[PROJECT]", "[TRANSFER_CONFIG]", "[RUN]")

        response = client.get_transfer_run(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datatransfer_pb2.GetTransferRunRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
示例#2
0
    def test_get_transfer_run(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        destination_dataset_id = 'destinationDatasetId1541564179'
        data_source_id = 'dataSourceId-1015796374'
        user_id = 147132913
        schedule = 'schedule-697920873'
        expected_response = {
            'name': name_2,
            'destination_dataset_id': destination_dataset_id,
            'data_source_id': data_source_id,
            'user_id': user_id,
            'schedule': schedule
        }
        expected_response = transfer_pb2.TransferRun(**expected_response)

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

        # Setup Request
        name = client.project_run_path('[PROJECT]', '[TRANSFER_CONFIG]',
                                       '[RUN]')

        response = client.get_transfer_run(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datatransfer_pb2.GetTransferRunRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
示例#3
0
    def get_transfer_run(self,
                         name,
                         retry=google.api_core.gapic_v1.method.DEFAULT,
                         timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Returns information about the particular transfer run.

        Example:
            >>> from google.cloud import bigquery_datatransfer_v1
            >>>
            >>> client = bigquery_datatransfer_v1.DataTransferServiceClient()
            >>>
            >>> name = client.location_run_path('[PROJECT]', '[LOCATION]', '[TRANSFER_CONFIG]', '[RUN]')
            >>>
            >>> response = client.get_transfer_run(name)

        Args:
            name (str): The field will contain name of the resource requested, for example:
                ``projects/{project_id}/transferConfigs/{config_id}/runs/{run_id}``
            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.cloud.bigquery_datatransfer_v1.types.TransferRun` instance.

        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.GetTransferRunRequest(name=name)
        return self._get_transfer_run(request, retry=retry, timeout=timeout)