def test_check_valid_creds(self):
        # Setup Expected Response
        has_valid_creds = False
        expected_response = {"has_valid_creds": has_valid_creds}
        expected_response = datatransfer_pb2.CheckValidCredsResponse(
            **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.check_valid_creds(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = datatransfer_pb2.CheckValidCredsRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 2
0
    def check_valid_creds(self,
                          name,
                          retry=google.api_core.gapic_v1.method.DEFAULT,
                          timeout=google.api_core.gapic_v1.method.DEFAULT):
        """
        Returns true if valid credentials exist for the given data source and
        requesting user.
        Some data sources doesn't support service account, so we need to talk to
        them on behalf of the end user. This API just checks whether we have OAuth
        token for the particular user, which is a pre-requisite before user can
        create a transfer config.

        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.check_valid_creds(name)

        Args:
            name (str): The data source in the form:
                ``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.CheckValidCredsResponse` 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.CheckValidCredsRequest(name=name)
        return self._check_valid_creds(request, retry=retry, timeout=timeout)
Esempio n. 3
0
    def test_check_valid_creds(self):
        # Setup Expected Response
        has_valid_creds = False
        expected_response = {'has_valid_creds': has_valid_creds}
        expected_response = datatransfer_pb2.CheckValidCredsResponse(
            **expected_response)

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

        # Setup Request
        name = client.project_data_source_path('[PROJECT]', '[DATA_SOURCE]')

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

        assert len(channel.requests) == 1
        expected_request = datatransfer_pb2.CheckValidCredsRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request