diff --git a/bigquery/transfer/cloud-client/quickstart.py b/bigquery/transfer/cloud-client/quickstart.py new file mode 100644 index 000000000000..7ae44669a090 --- /dev/null +++ b/bigquery/transfer/cloud-client/quickstart.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +# Copyright 2017 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +def run_quickstart(): + # [START bigquery_datatransfer_quickstart] + from google.cloud import bigquery_datatransfer + + client = bigquery_datatransfer.DataTransferServiceClient() + + project = 'my-project' # TODO: Update to your project ID. + + # Get the full path to your project. + parent = client.project_path(project) + + print('Supported Data Sources:') + + # Iterate over all possible data sources. + for data_source in client.list_data_sources(parent): + print('{}:'.format(data_source.display_name)) + print('\tID: {}'.format(data_source.data_source_id)) + print('\tFull path: {}'.format(data_source.name)) + print('\tDescription: {}'.format(data_source.description)) + # [END bigquery_datatransfer_quickstart] + + +if __name__ == '__main__': + run_quickstart() diff --git a/bigquery/transfer/cloud-client/quickstart_test.py b/bigquery/transfer/cloud-client/quickstart_test.py new file mode 100644 index 000000000000..0bb5ddd68110 --- /dev/null +++ b/bigquery/transfer/cloud-client/quickstart_test.py @@ -0,0 +1,41 @@ +# Copyright 2017 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import mock +import pytest + +import quickstart + + +PROJECT = os.environ['GCLOUD_PROJECT'] + + +@pytest.fixture +def mock_project_path(): + """Mock out project and replace with project from environment.""" + project_patch = mock.patch( + 'google.cloud.bigquery_datatransfer.DataTransferServiceClient.' + 'project_path') + + with project_patch as project_mock: + project_mock.return_value = 'projects/{}'.format(PROJECT) + yield project_mock + + +def test_quickstart(capsys, mock_project_path): + quickstart.run_quickstart() + out, _ = capsys.readouterr() + assert 'Supported Data Sources:' in out diff --git a/bigquery/transfer/cloud-client/requirements.txt b/bigquery/transfer/cloud-client/requirements.txt new file mode 100644 index 000000000000..25782e4b01ed --- /dev/null +++ b/bigquery/transfer/cloud-client/requirements.txt @@ -0,0 +1 @@ +google-cloud-bigquery-datatransfer==0.1.0 diff --git a/scripts/prepare-testing-project.sh b/scripts/prepare-testing-project.sh index d25ec4af3283..9a6243dc0a98 100755 --- a/scripts/prepare-testing-project.sh +++ b/scripts/prepare-testing-project.sh @@ -50,4 +50,4 @@ echo "Creating speech resources." gsutil cp speech/api-client/resources/audio.raw gs://$GCLOUD_PROJECT/speech/ echo "To finish setup, follow this link to enable APIs." -echo "https://console.cloud.google.com/flows/enableapi?project=${GCLOUD_PROJECT}&apiid=bigtable.googleapis.com,bigtableadmin.googleapis.com,bigquery,cloudmonitoring,compute_component,datastore,datastore.googleapis.com,dataproc,dns,plus,pubsub,logging,storage_api,vision.googleapis.com" +echo "https://console.cloud.google.com/flows/enableapi?project=${GCLOUD_PROJECT}&apiid=bigtable.googleapis.com,bigtableadmin.googleapis.com,bigquery,bigquerydatatransfer.googleapis.com,cloudmonitoring,compute_component,datastore,datastore.googleapis.com,dataproc,dns,plus,pubsub,logging,storage_api,vision.googleapis.com"