-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BigQuery: Add Data Transfer Service quickstart. [(#1295)](GoogleCloud…
…Platform/python-docs-samples#1295) * BigQuery: Add Data Transfer Service quickstart. Client library docs: https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery_datatransfer/index.html * Enable BigQuery Data Transfer API in test project. * Remove project from quickstart test assertion. Don't depend on specific data sources being available. I believe the reason the tests are failing is that the data sources weren't allowed for the test project because the API was enabled, but the project wasn't enrolled as described in https://cloud.google.com/bigquery/docs/enable-transfer-service
- Loading branch information
1 parent
6d1979e
commit 0a98581
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/google-cloud-bigquery-datatransfer/samples/snippets/quickstart.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
41 changes: 41 additions & 0 deletions
41
packages/google-cloud-bigquery-datatransfer/samples/snippets/quickstart_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
1 change: 1 addition & 0 deletions
1
packages/google-cloud-bigquery-datatransfer/samples/snippets/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
google-cloud-bigquery-datatransfer==0.1.0 |