Esempio n. 1
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
    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