22
22
23
23
from airflow .providers .google .cloud .transfers .bigquery_to_bigquery import BigQueryToBigQueryOperator
24
24
25
+ BQ_HOOK_PATH = "airflow.providers.google.cloud.transfers.bigquery_to_bigquery.BigQueryHook"
25
26
TASK_ID = "test-bq-create-table-operator"
26
27
TEST_DATASET = "test-dataset"
27
28
TEST_TABLE_ID = "test-table-id"
28
29
29
30
30
31
class TestBigQueryToBigQueryOperator (unittest .TestCase ):
31
- @mock .patch ("airflow.providers.google.cloud.transfers.bigquery_to_bigquery.BigQueryHook" )
32
- def test_execute (self , mock_hook ):
32
+ @mock .patch (BQ_HOOK_PATH )
33
+ def test_execute_without_location_should_execute_successfully (self , mock_hook ):
33
34
source_project_dataset_tables = f"{ TEST_DATASET } .{ TEST_TABLE_ID } "
34
35
destination_project_dataset_table = f"{ TEST_DATASET + '_new' } .{ TEST_TABLE_ID } "
35
36
write_disposition = "WRITE_EMPTY"
@@ -56,3 +57,31 @@ def test_execute(self, mock_hook):
56
57
labels = labels ,
57
58
encryption_configuration = encryption_configuration ,
58
59
)
60
+
61
+ @mock .patch (BQ_HOOK_PATH )
62
+ def test_execute_single_regional_location_should_execute_successfully (self , mock_hook ):
63
+ source_project_dataset_tables = f"{ TEST_DATASET } .{ TEST_TABLE_ID } "
64
+ destination_project_dataset_table = f"{ TEST_DATASET + '_new' } .{ TEST_TABLE_ID } "
65
+ write_disposition = "WRITE_EMPTY"
66
+ create_disposition = "CREATE_IF_NEEDED"
67
+ labels = {"k1" : "v1" }
68
+ location = "us-central1"
69
+ encryption_configuration = {"key" : "kk" }
70
+ mock_hook .return_value .run_copy .return_value = "job-id"
71
+
72
+ operator = BigQueryToBigQueryOperator (
73
+ task_id = TASK_ID ,
74
+ source_project_dataset_tables = source_project_dataset_tables ,
75
+ destination_project_dataset_table = destination_project_dataset_table ,
76
+ write_disposition = write_disposition ,
77
+ create_disposition = create_disposition ,
78
+ labels = labels ,
79
+ encryption_configuration = encryption_configuration ,
80
+ location = location ,
81
+ )
82
+
83
+ operator .execute (context = mock .MagicMock ())
84
+ mock_hook .return_value .get_job .assert_called_once_with (
85
+ job_id = "job-id" ,
86
+ location = location ,
87
+ )
0 commit comments