Пример #1
0
    def test_get_data_source(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        data_source_id = "dataSourceId-1015796374"
        display_name = "displayName1615086568"
        description = "description-1724546052"
        client_id = "clientId-1904089585"
        supports_multiple_transfers = True
        update_deadline_seconds = 991471694
        default_schedule = "defaultSchedule-800168235"
        supports_custom_schedule = True
        help_url = "helpUrl-789431439"
        default_data_refresh_window_days = 1804935157
        manual_runs_disabled = True
        expected_response = {
            "name": name_2,
            "data_source_id": data_source_id,
            "display_name": display_name,
            "description": description,
            "client_id": client_id,
            "supports_multiple_transfers": supports_multiple_transfers,
            "update_deadline_seconds": update_deadline_seconds,
            "default_schedule": default_schedule,
            "supports_custom_schedule": supports_custom_schedule,
            "help_url": help_url,
            "default_data_refresh_window_days":
            default_data_refresh_window_days,
            "manual_runs_disabled": manual_runs_disabled,
        }
        expected_response = datatransfer_pb2.DataSource(**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_data_source_path("[PROJECT]", "[DATA_SOURCE]")

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

        assert len(channel.requests) == 1
        expected_request = datatransfer_pb2.GetDataSourceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_get_data_source(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        data_source_id = 'dataSourceId-1015796374'
        display_name = 'displayName1615086568'
        description = 'description-1724546052'
        client_id = 'clientId-1904089585'
        supports_multiple_transfers = True
        update_deadline_seconds = 991471694
        default_schedule = 'defaultSchedule-800168235'
        supports_custom_schedule = True
        help_url = 'helpUrl-789431439'
        default_data_refresh_window_days = 1804935157
        manual_runs_disabled = True
        expected_response = {
            'name': name_2,
            'data_source_id': data_source_id,
            'display_name': display_name,
            'description': description,
            'client_id': client_id,
            'supports_multiple_transfers': supports_multiple_transfers,
            'update_deadline_seconds': update_deadline_seconds,
            'default_schedule': default_schedule,
            'supports_custom_schedule': supports_custom_schedule,
            'help_url': help_url,
            'default_data_refresh_window_days':
            default_data_refresh_window_days,
            'manual_runs_disabled': manual_runs_disabled
        }
        expected_response = datatransfer_pb2.DataSource(**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_data_source_path('[PROJECT]', '[DATA_SOURCE]')

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

        assert len(channel.requests) == 1
        expected_request = datatransfer_pb2.GetDataSourceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Пример #3
0
    def get_data_source(self,
                        name,
                        retry=google.api_core.gapic_v1.method.DEFAULT,
                        timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Retrieves a supported data source and returns its settings,
        which can be used for UI rendering.

        Example:
            >>> from google.cloud import bigquery_datatransfer_v1
            >>>
            >>> client = bigquery_datatransfer_v1.DataTransferServiceClient()
            >>>
            >>> name = client.location_data_source_path('[PROJECT]', '[LOCATION]', '[DATA_SOURCE]')
            >>>
            >>> response = client.get_data_source(name)

        Args:
            name (str): The field will contain name of the resource requested, for example:
                ``projects/{project_id}/dataSources/{data_source_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.DataSource` 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.GetDataSourceRequest(name=name)
        return self._get_data_source(request, retry=retry, timeout=timeout)