Skip to content

Commit f26155d

Browse files
tswastleahecole
authored andcommitted
docs: remove out-of-date sample from README (#80)
See samples/ directory for maintained and tested samples
1 parent 989b5f1 commit f26155d

File tree

4 files changed

+72
-64
lines changed

4 files changed

+72
-64
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import google.api_core.exceptions
16+
import google.auth
17+
from google.cloud import bigquery
18+
from google.cloud import bigquery_datatransfer
19+
import pytest
20+
21+
22+
@pytest.fixture(scope="session")
23+
def default_credentials():
24+
return google.auth.default(["https://www.googleapis.com/auth/cloud-platform"])
25+
26+
27+
@pytest.fixture(scope="session")
28+
def project_id(default_credentials):
29+
_, project_id = default_credentials
30+
return project_id
31+
32+
33+
@pytest.fixture(scope="session")
34+
def bigquery_client(default_credentials):
35+
credentials, project_id = default_credentials
36+
return bigquery.Client(credentials=credentials, project=project_id)
37+
38+
39+
@pytest.fixture(scope="session")
40+
def transfer_client(default_credentials):
41+
credentials, _ = default_credentials
42+
return bigquery_datatransfer.DataTransferServiceClient(credentials=credentials)
43+
44+
45+
@pytest.fixture
46+
def to_delete_configs(transfer_client):
47+
to_delete = []
48+
yield to_delete
49+
for config_name in to_delete:
50+
try:
51+
transfer_client.delete_transfer_config(name=config_name)
52+
except google.api_core.exceptions.GoogleAPICallError:
53+
pass

bigquery-datatransfer/snippets/copy_dataset_test.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
import datetime
1616
import uuid
1717

18-
import google.api_core.exceptions
19-
import google.auth
20-
from google.cloud import bigquery
21-
from google.cloud import bigquery_datatransfer
2218
import pytest
2319

2420
from . import copy_dataset
@@ -29,40 +25,6 @@ def temp_suffix():
2925
return f"{now.strftime('%Y%m%d%H%M%S')}_{uuid.uuid4().hex[:8]}"
3026

3127

32-
@pytest.fixture(scope="session")
33-
def default_credentials():
34-
return google.auth.default(["https://www.googleapis.com/auth/cloud-platform"])
35-
36-
37-
@pytest.fixture(scope="session")
38-
def project_id(default_credentials):
39-
_, project_id = default_credentials
40-
return project_id
41-
42-
43-
@pytest.fixture(scope="session")
44-
def bigquery_client(default_credentials):
45-
credentials, project_id = default_credentials
46-
return bigquery.Client(credentials=credentials, project=project_id)
47-
48-
49-
@pytest.fixture(scope="session")
50-
def transfer_client(default_credentials):
51-
credentials, _ = default_credentials
52-
return bigquery_datatransfer.DataTransferServiceClient(credentials=credentials)
53-
54-
55-
@pytest.fixture
56-
def to_delete_configs(transfer_client):
57-
to_delete = []
58-
yield to_delete
59-
for config_name in to_delete:
60-
try:
61-
transfer_client.delete_transfer_config(name=config_name)
62-
except google.api_core.exceptions.GoogleAPICallError:
63-
pass
64-
65-
6628
@pytest.fixture(scope="module")
6729
def destination_dataset_id(bigquery_client, project_id):
6830
dataset_id = f"bqdts_dest_{temp_suffix()}"

bigquery-datatransfer/snippets/quickstart.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,36 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import sys
1718

18-
def run_quickstart(project="my-project"):
19+
20+
def run_quickstart(override_values={}):
1921
# [START bigquerydatatransfer_quickstart]
2022
from google.cloud import bigquery_datatransfer
2123

2224
client = bigquery_datatransfer.DataTransferServiceClient()
2325

2426
# TODO: Update to your project ID.
25-
# project = "my-project"
27+
project_id = "my-project"
28+
# [END bigquerydatatransfer_quickstart]
29+
# To facilitate testing, we replace values with alternatives
30+
# provided by the testing harness.
31+
project_id = override_values.get("project_id", project_id)
32+
# [START bigquerydatatransfer_quickstart]
2633

2734
# Get the full path to your project.
28-
parent = f"projects/{project}"
35+
parent = client.common_project_path(project_id)
2936

30-
print('Supported Data Sources:')
37+
print("Supported Data Sources:")
3138

3239
# Iterate over all possible data sources.
3340
for data_source in client.list_data_sources(parent=parent):
34-
print('{}:'.format(data_source.display_name))
35-
print('\tID: {}'.format(data_source.data_source_id))
36-
print('\tFull path: {}'.format(data_source.name))
37-
print('\tDescription: {}'.format(data_source.description))
41+
print("{}:".format(data_source.display_name))
42+
print("\tID: {}".format(data_source.data_source_id))
43+
print("\tFull path: {}".format(data_source.name))
44+
print("\tDescription: {}".format(data_source.description))
3845
# [END bigquerydatatransfer_quickstart]
3946

4047

41-
if __name__ == '__main__':
42-
run_quickstart()
48+
if __name__ == "__main__":
49+
run_quickstart(override_values={"project_id": sys.argv[1]})

bigquery-datatransfer/snippets/quickstart_test.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
16-
17-
import pytest
18-
1915
from . import quickstart
2016

2117

22-
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
23-
24-
25-
@pytest.fixture
26-
def mock_project_id():
27-
"""Mock out project and replace with project from environment."""
28-
29-
return PROJECT
30-
31-
32-
def test_quickstart(capsys, mock_project_id):
33-
quickstart.run_quickstart(mock_project_id)
18+
def test_quickstart(capsys, project_id):
19+
quickstart.run_quickstart(override_values={"project_id": project_id})
3420
out, _ = capsys.readouterr()
3521
assert "Supported Data Sources:" in out

0 commit comments

Comments
 (0)