Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/python-bigquery-datatransfer #10259

Merged
merged 117 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
6a382fc
BigQuery: Add Data Transfer Service quickstart. [(#1295)](https://git…
tswast Dec 27, 2017
882c246
Auto-update dependencies. [(#1377)](https://github.com/GoogleCloudPla…
dpebot Mar 5, 2018
c507243
bigquery_datatransfer -> bigquerydatatransfer
tswast Mar 21, 2018
05b9e48
Auto-update dependencies. [(#1846)](https://github.com/GoogleCloudPla…
dpebot Nov 20, 2018
6768a59
Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPla…
dpebot Feb 6, 2019
12b237b
Adds updates including compute [(#2436)](https://github.com/GoogleClo…
gguuss Oct 23, 2019
6d82d5b
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Mar 30, 2020
029e126
Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatf…
kurtisvg Apr 2, 2020
0867434
Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. [(#4022)](https://g…
kurtisvg Jun 9, 2020
75e1867
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Jun 30, 2020
e3fa3c6
chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://git…
renovate-bot Jul 12, 2020
092e617
chore(deps): update dependency mock to v4 [(#4287)](https://github.co…
renovate-bot Jul 13, 2020
36a9df9
Update dependency pytest to v6 [(#4390)](https://github.com/GoogleClo…
renovate-bot Aug 1, 2020
485189f
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Sep 16, 2020
28ba240
chore: transition the library to microgenerator (#56)
plamut Sep 21, 2020
22d55fc
chore: Adjust gapic namespace to google.cloud.bigquery_datatransfer (…
plamut Sep 29, 2020
51195a0
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Oct 5, 2020
c03aacc
docs: add sample for dataset copy (#76)
tswast Dec 9, 2020
cf7ed2c
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Dec 9, 2020
6453eaf
docs: remove out-of-date sample from README (#80)
tswast Dec 10, 2020
f5693fc
docs: add scheduled query samples (#83)
tswast Dec 15, 2020
4f14fd6
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Mar 10, 2021
742730b
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Apr 7, 2021
afdafcb
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Apr 8, 2021
fdf49b0
chore(deps): update dependency pytest to v6.2.3 (#137)
renovate-bot Apr 16, 2021
8648b34
chore(deps): update dependency mock to v4.0.3 (#135)
renovate-bot Apr 28, 2021
6ea6a6b
chore(deps): update dependency google-cloud-bigquery to v2.16.0 (#134)
renovate-bot May 11, 2021
7fe868f
chore(deps): update dependency pytest to v6.2.4 (#147)
renovate-bot May 11, 2021
6b4c7bf
chore(deps): update dependency google-cloud-bigquery to v2.20.0 (#154)
renovate-bot Jun 16, 2021
20bbafd
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Jun 24, 2021
b6a3979
docs: add sample to include run notification (#173)
tswast Jul 1, 2021
2d6e04b
chore: use gapic-generator-python 0.50.4 (#174)
gcf-owl-bot[bot] Jul 12, 2021
d3bde5a
chore(deps): update dependency google-cloud-pubsub to v2.6.1 (#175)
renovate-bot Jul 12, 2021
8c9f3ca
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Jul 16, 2021
84dcb4b
feat: add Samples section to CONTRIBUTING.rst (#181)
gcf-owl-bot[bot] Jul 22, 2021
4293861
chore(deps): update dependency google-cloud-bigquery to v2.22.1 (#177)
renovate-bot Jul 26, 2021
68543a2
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Jul 26, 2021
2547df0
chore(deps): update dependency google-cloud-bigquery to v2.23.0 (#189)
renovate-bot Jul 28, 2021
306fee4
chore(deps): update dependency google-cloud-bigquery to v2.23.1 (#191)
renovate-bot Jul 28, 2021
8576e86
chore(deps): update dependency google-cloud-pubsub to v2.7.0 (#190)
renovate-bot Jul 28, 2021
6f5eed2
chore(deps): update dependency google-cloud-bigquery to v2.23.2 (#193)
renovate-bot Jul 29, 2021
3f47bd7
chore(deps): update dependency google-cloud-bigquery to v2.24.0 (#195)
renovate-bot Aug 13, 2021
cc69b58
chore(deps): update dependency google-cloud-pubsub to v2.7.1 (#204)
renovate-bot Aug 27, 2021
c90fe4d
chore(deps): update dependency google-cloud-bigquery to v2.25.1 (#203)
renovate-bot Aug 27, 2021
c9242ee
chore(deps): update dependency pytest to v6.2.5 (#210)
renovate-bot Aug 30, 2021
3d3af08
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Aug 31, 2021
b79b8cc
chore(deps): update dependency google-cloud-bigquery to v2.25.2 (#213)
renovate-bot Sep 1, 2021
05ac41b
chore(deps): update dependency google-cloud-bigquery to v2.26.0 (#216)
renovate-bot Sep 2, 2021
2133c39
chore(deps): update dependency google-cloud-pubsub to v2.8.0 (#218)
renovate-bot Sep 14, 2021
634aae0
chore(deps): update all dependencies (#224)
renovate-bot Sep 27, 2021
77a4792
chore(deps): update dependency google-cloud-bigquery to v2.27.1 (#225)
renovate-bot Sep 28, 2021
3081752
chore(deps): update dependency google-cloud-bigquery to v2.28.0 (#229)
renovate-bot Sep 30, 2021
394d70a
chore(deps): update all dependencies (#231)
renovate-bot Oct 21, 2021
2d85895
chore(deps): update dependency google-cloud-bigquery to v2.29.0 (#240)
renovate-bot Oct 30, 2021
ff4242e
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Nov 3, 2021
a8575ab
chore(deps): update dependency google-cloud-bigquery to v2.30.0 (#245)
renovate-bot Nov 4, 2021
32d0f34
chore(deps): update dependency google-cloud-bigquery to v2.30.1 (#246)
renovate-bot Nov 8, 2021
c48ef0c
chore(deps): update dependency google-cloud-pubsub to v2.9.0 (#249)
renovate-bot Nov 11, 2021
6dfa378
chore(deps): update dependency google-cloud-bigquery to v2.31.0 (#256)
renovate-bot Dec 3, 2021
9fd972e
chore(deps): update dependency google-cloud-bigquery to v2.32.0 (#269)
renovate-bot Jan 13, 2022
a0979fb
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Jan 19, 2022
5b04686
chore(deps): update dependency pytest to v7 (#282)
renovate-bot Feb 7, 2022
cb62bf7
chore(deps): update dependency pytest to v7.0.1 (#284)
renovate-bot Feb 14, 2022
8a7b200
chore(deps): update all dependencies (#285)
renovate-bot Feb 24, 2022
f6b46eb
chore(deps): update all dependencies (#294)
renovate-bot Mar 3, 2022
4e73abd
chore(deps): update dependency google-cloud-pubsub to v2.10.0 (#299)
renovate-bot Mar 5, 2022
4cf4f91
chore(deps): update all dependencies (#301)
renovate-bot Mar 7, 2022
0149a42
chore(deps): update dependency google-cloud-pubsub to v2.11.0 (#302)
renovate-bot Mar 10, 2022
8451f5f
chore(deps): update dependency pytest to v7.1.0 (#305)
renovate-bot Mar 13, 2022
b76e965
chore(deps): update dependency pytest to v7.1.1 (#306)
renovate-bot Mar 19, 2022
891be72
chore(python): use black==22.3.0 (#310)
gcf-owl-bot[bot] Mar 29, 2022
612c47e
chore(deps): update dependency google-cloud-bigquery to v2.34.3 (#311)
renovate-bot Mar 30, 2022
a5b6b66
chore(deps): update dependency google-cloud-bigquery to v3 (#314)
renovate-bot Mar 30, 2022
363a38b
chore(deps): update dependency google-cloud-pubsub to v2.12.0 (#320)
renovate-bot Apr 7, 2022
748c626
chore(python): add nox session to sort python imports (#326)
gcf-owl-bot[bot] Apr 21, 2022
e729678
chore(deps): update dependency pytest to v7.1.2 (#329)
renovate-bot Apr 25, 2022
72dbac7
chore(deps): update dependency google-cloud-bigquery to v3.1.0 (#334)
renovate-bot May 9, 2022
4644cfd
chore(deps): update dependency google-cloud-pubsub to v2.12.1 (#335)
renovate-bot May 12, 2022
810b45a
chore(deps): update all dependencies (#354)
renovate-bot Jul 16, 2022
2a168bc
chore(deps): update all dependencies (#370)
renovate-bot Aug 2, 2022
ec5022f
chore(deps): update all dependencies (#372)
renovate-bot Aug 9, 2022
aa6ac29
chore(deps): update dependency google-cloud-pubsub to v2.13.5 (#374)
renovate-bot Aug 11, 2022
5a4338e
chore(deps): update dependency google-cloud-pubsub to v2.13.6 (#377)
renovate-bot Aug 12, 2022
0f8e2d7
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Aug 16, 2022
b753472
chore(deps): update dependency google-cloud-bigquery to v3.3.2 (#380)
renovate-bot Aug 19, 2022
d14da23
chore(deps): update dependency pytest to v7.1.3 (#389)
renovate-bot Sep 6, 2022
4ebbabd
chore(deps): update all dependencies (#395)
renovate-bot Oct 4, 2022
f6ed45b
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Oct 4, 2022
0b5debd
chore(deps): update all dependencies (#402)
renovate-bot Oct 18, 2022
92f84cb
chore(deps): update dependency pytest to v7.2.0 (#403)
renovate-bot Oct 26, 2022
b9810d0
chore(deps): update all dependencies (#405)
renovate-bot Nov 21, 2022
6872625
chore(deps): update dependency google-cloud-bigquery to v3.4.1 (#413)
renovate-bot Dec 15, 2022
6e61ab0
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Dec 16, 2022
a50b0eb
chore(deps): update dependency mock to v5 (#415)
renovate-bot Jan 3, 2023
29e8804
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Jan 4, 2023
f106a11
chore(deps): update dependency mock to v5.0.1 (#420)
renovate-bot Jan 9, 2023
5c1b4d7
chore(deps): update dependency google-cloud-pubsub to v2.13.12 (#423)
renovate-bot Jan 10, 2023
4c4eeba
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Jan 11, 2023
f1d9828
chore(deps): update dependency pytest to v7.2.1 (#425)
renovate-bot Jan 14, 2023
9361eb7
chore(deps): update dependency google-cloud-bigquery to v3.4.2 (#426)
renovate-bot Jan 18, 2023
0d3230f
chore(deps): update dependency google-cloud-pubsub to v2.14.0 (#427)
renovate-bot Jan 23, 2023
70b838b
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Jan 24, 2023
f9d6ab0
chore(deps): update dependency google-cloud-bigquery to v3.5.0 (#434)
renovate-bot Feb 2, 2023
5539146
chore(deps): update dependency google-cloud-pubsub to v2.14.1 (#438)
renovate-bot Feb 8, 2023
df0857f
chore(deps): update all dependencies (#442)
renovate-bot Feb 23, 2023
ddf6907
chore(deps): update dependency google-cloud-bigquery-datatransfer to …
renovate-bot Mar 1, 2023
0c0924c
chore(deps): update dependency pytest to v7.2.2 (#447)
renovate-bot Mar 4, 2023
c901a85
fix: replaces deprecated snippet (#448)
chalmerlowe Mar 10, 2023
2ebdd57
docs: removes deprecated sample (#451)
chalmerlowe Mar 22, 2023
388b960
chore(deps): update all dependencies (#452)
renovate-bot Apr 6, 2023
eb3f9eb
chore(deps): update all dependencies (#457)
renovate-bot Apr 18, 2023
27dc67b
chore(deps): update dependency google-cloud-bigquery to v3.10.0 (#459)
renovate-bot Apr 19, 2023
d2f1819
chore(deps): update dependency google-cloud-pubsub to v2.17.1 (#460)
renovate-bot Jun 1, 2023
25b3f2c
chore(deps): update dependency google-cloud-bigquery to v3.11.0 (#463)
renovate-bot Jun 4, 2023
e4d0b71
chore(deps): update all dependencies (#466)
renovate-bot Jun 14, 2023
483f657
skip python-3.6 in sample test
dizcology Jun 16, 2023
ae4686a
update .githug/CODEOWNERS
dizcology Jun 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
/bigquery/remote_function/**/* @autoerr @GoogleCloudPlatform/python-samples-reviewers
/cloud-media-livestream/**/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers
/bigquery-connection/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/bigquery-datatransfer/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/dlp/**/* @GoogleCloudPlatform/googleapis-dlp @GoogleCloudPlatform/python-samples-reviewers
/functions/spanner/* @GoogleCloudPlatform/api-spanner-python @GoogleCloudPlatform/functions-framework-google @GoogleCloudPlatform/python-samples-reviewers
/healthcare/**/* @GoogleCloudPlatform/healthcare-life-sciences @GoogleCloudPlatform/python-samples-reviewers
Expand Down
13 changes: 13 additions & 0 deletions bigquery-datatransfer/snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 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.
156 changes: 156 additions & 0 deletions bigquery-datatransfer/snippets/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Copyright 2020 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 datetime
import os
import random
import uuid

from google.api_core import client_options
import google.api_core.exceptions
import google.auth
from google.cloud import bigquery, bigquery_datatransfer, pubsub_v1
import pytest

RESOURCE_PREFIX = "python_bigquery_datatransfer_samples_snippets"
RESOURCE_DATE_FORMAT = "%Y%m%d%H%M%S"
RESOURCE_DATE_LENGTH = 4 + 2 + 2 + 2 + 2 + 2


def resource_prefix() -> str:
timestamp = datetime.datetime.utcnow().strftime(RESOURCE_DATE_FORMAT)
random_string = hex(random.randrange(1000000))[2:]
return f"{RESOURCE_PREFIX}_{timestamp}_{random_string}"


def resource_name_to_date(resource_name: str):
start_date = len(RESOURCE_PREFIX) + 1
date_string = resource_name[start_date : start_date + RESOURCE_DATE_LENGTH]
parsed_date = datetime.datetime.strptime(date_string, RESOURCE_DATE_FORMAT)
return parsed_date


@pytest.fixture(scope="session", autouse=True)
def cleanup_pubsub_topics(pubsub_client: pubsub_v1.PublisherClient, project_id):
yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
for topic in pubsub_client.list_topics(project=f"projects/{project_id}"):
topic_id = topic.name.split("/")[-1]
if (
topic_id.startswith(RESOURCE_PREFIX)
and resource_name_to_date(topic_id) < yesterday
):
pubsub_client.delete_topic(topic=topic.name)


def temp_suffix():
now = datetime.datetime.now()
return f"{now.strftime('%Y%m%d%H%M%S')}_{uuid.uuid4().hex[:8]}"


@pytest.fixture(scope="session")
def bigquery_client(default_credentials):
credentials, project_id = default_credentials
return bigquery.Client(credentials=credentials, project=project_id)


@pytest.fixture(scope="session")
def pubsub_client(default_credentials):
credentials, _ = default_credentials
return pubsub_v1.PublisherClient(credentials=credentials)


@pytest.fixture(scope="session")
def pubsub_topic(pubsub_client: pubsub_v1.PublisherClient, project_id):
topic_id = resource_prefix()
topic_path = pubsub_v1.PublisherClient.topic_path(project_id, topic_id)
pubsub_client.create_topic(name=topic_path)
yield topic_path
pubsub_client.delete_topic(topic=topic_path)


@pytest.fixture(scope="session")
def dataset_id(bigquery_client, project_id):
dataset_id = f"bqdts_{temp_suffix()}"
bigquery_client.create_dataset(f"{project_id}.{dataset_id}")
yield dataset_id
bigquery_client.delete_dataset(dataset_id, delete_contents=True)


@pytest.fixture(scope="session")
def default_credentials():
return google.auth.default(["https://www.googleapis.com/auth/cloud-platform"])


@pytest.fixture(scope="session")
def project_id():
return os.environ["GOOGLE_CLOUD_PROJECT"]


@pytest.fixture(scope="session")
def service_account_name(default_credentials):
credentials, _ = default_credentials
# The service_account_email attribute is not available when running with
# user account credentials, but should be available when running from our
# continuous integration tests.
return getattr(credentials, "service_account_email", None)


@pytest.fixture(scope="session")
def transfer_client(default_credentials, project_id):
credentials, _ = default_credentials
options = client_options.ClientOptions(quota_project_id=project_id)

transfer_client = bigquery_datatransfer.DataTransferServiceClient(
credentials=credentials, client_options=options
)

# Ensure quota is always attributed to the correct project.
bigquery_datatransfer.DataTransferServiceClient = lambda: transfer_client

return transfer_client


@pytest.fixture(scope="session")
def transfer_config_name(transfer_client, project_id, dataset_id, service_account_name):
from . import manage_transfer_configs, scheduled_query

# Use the transfer_client fixture so we know quota is attributed to the
# correct project.
assert transfer_client is not None

# To conserve limited BQ-DTS quota, this fixture creates only one transfer
# config for a whole session and is used to test the scheduled_query.py and
# the delete operation in manage_transfer_configs.py.
transfer_config = scheduled_query.create_scheduled_query(
{
"project_id": project_id,
"dataset_id": dataset_id,
"service_account_name": service_account_name,
}
)
yield transfer_config.name
manage_transfer_configs.delete_config(
{"transfer_config_name": transfer_config.name}
)


@pytest.fixture
def to_delete_configs(transfer_client):
to_delete = []
yield to_delete
for config_name in to_delete:
try:
transfer_client.delete_transfer_config(name=config_name)
except google.api_core.exceptions.GoogleAPICallError:
pass
54 changes: 54 additions & 0 deletions bigquery-datatransfer/snippets/copy_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2020 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 copy_dataset(override_values={}):
# [START bigquerydatatransfer_copy_dataset]
from google.cloud import bigquery_datatransfer

transfer_client = bigquery_datatransfer.DataTransferServiceClient()

destination_project_id = "my-destination-project"
destination_dataset_id = "my_destination_dataset"
source_project_id = "my-source-project"
source_dataset_id = "my_source_dataset"
# [END bigquerydatatransfer_copy_dataset]
# To facilitate testing, we replace values with alternatives
# provided by the testing harness.
destination_project_id = override_values.get(
"destination_project_id", destination_project_id
)
destination_dataset_id = override_values.get(
"destination_dataset_id", destination_dataset_id
)
source_project_id = override_values.get("source_project_id", source_project_id)
source_dataset_id = override_values.get("source_dataset_id", source_dataset_id)
# [START bigquerydatatransfer_copy_dataset]
transfer_config = bigquery_datatransfer.TransferConfig(
destination_dataset_id=destination_dataset_id,
display_name="Your Dataset Copy Name",
data_source_id="cross_region_copy",
params={
"source_project_id": source_project_id,
"source_dataset_id": source_dataset_id,
},
schedule="every 24 hours",
)
transfer_config = transfer_client.create_transfer_config(
parent=transfer_client.common_project_path(destination_project_id),
transfer_config=transfer_config,
)
print(f"Created transfer config: {transfer_config.name}")
# [END bigquerydatatransfer_copy_dataset]
return transfer_config
66 changes: 66 additions & 0 deletions bigquery-datatransfer/snippets/copy_dataset_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2020 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 datetime
import uuid

import pytest

from . import copy_dataset


def temp_suffix():
now = datetime.datetime.now()
return f"{now.strftime('%Y%m%d%H%M%S')}_{uuid.uuid4().hex[:8]}"


@pytest.fixture(scope="module")
def destination_dataset_id(bigquery_client, project_id):
dataset_id = f"bqdts_dest_{temp_suffix()}"
bigquery_client.create_dataset(f"{project_id}.{dataset_id}")
yield dataset_id
bigquery_client.delete_dataset(dataset_id, delete_contents=True)


@pytest.fixture(scope="module")
def source_dataset_id(bigquery_client, project_id):
dataset_id = f"bqdts_src_{temp_suffix()}"
bigquery_client.create_dataset(f"{project_id}.{dataset_id}")
yield dataset_id
bigquery_client.delete_dataset(dataset_id, delete_contents=True)


def test_copy_dataset(
capsys,
transfer_client,
project_id,
destination_dataset_id,
source_dataset_id,
to_delete_configs,
):
# Use the transfer_client fixture so we know quota is attributed to the
# correct project.
assert transfer_client is not None

transfer_config = copy_dataset.copy_dataset(
{
"destination_project_id": project_id,
"destination_dataset_id": destination_dataset_id,
"source_project_id": project_id,
"source_dataset_id": source_dataset_id,
}
)
to_delete_configs.append(transfer_config.name)
out, _ = capsys.readouterr()
assert transfer_config.name in out
Loading