25
25
import test_utils .prefixer
26
26
27
27
import bigframes
28
+ import bigframes .clients
28
29
import bigframes .dtypes
29
30
import bigframes .exceptions
30
31
from bigframes .functions import _utils as bff_utils
@@ -93,6 +94,11 @@ def session_with_bq_connection(bq_cf_connection) -> bigframes.Session:
93
94
return session
94
95
95
96
97
+ def get_bq_connection_id_path_format (connection_id_dot_format ):
98
+ fields = connection_id_dot_format .split ("." )
99
+ return f"projects/{ fields [0 ]} /locations/{ fields [1 ]} /connections/{ fields [2 ]} "
100
+
101
+
96
102
@pytest .mark .flaky (retries = 2 , delay = 120 )
97
103
def test_remote_function_direct_no_session_param (
98
104
bigquery_client ,
@@ -155,11 +161,8 @@ def square(x):
155
161
156
162
157
163
@pytest .mark .flaky (retries = 2 , delay = 120 )
158
- def test_remote_function_direct_no_session_param_location_specified (
159
- bigquery_client ,
160
- bigqueryconnection_client ,
161
- cloudfunctions_client ,
162
- resourcemanager_client ,
164
+ def test_remote_function_connection_w_location (
165
+ session ,
163
166
scalars_dfs ,
164
167
dataset_id_permanent ,
165
168
bq_cf_connection_location ,
@@ -170,10 +173,7 @@ def square(x):
170
173
square = bff .remote_function (
171
174
input_types = int ,
172
175
output_type = int ,
173
- bigquery_client = bigquery_client ,
174
- bigquery_connection_client = bigqueryconnection_client ,
175
- cloud_functions_client = cloudfunctions_client ,
176
- resource_manager_client = resourcemanager_client ,
176
+ session = session ,
177
177
dataset = dataset_id_permanent ,
178
178
bigquery_connection = bq_cf_connection_location ,
179
179
# See e2e tests for tests that actually deploy the Cloud Function.
@@ -210,11 +210,8 @@ def square(x):
210
210
211
211
212
212
@pytest .mark .flaky (retries = 2 , delay = 120 )
213
- def test_remote_function_direct_no_session_param_location_mismatched (
214
- bigquery_client ,
215
- bigqueryconnection_client ,
216
- cloudfunctions_client ,
217
- resourcemanager_client ,
213
+ def test_remote_function_connection_w_location_mismatched (
214
+ session ,
218
215
dataset_id_permanent ,
219
216
bq_cf_connection_location_mismatched ,
220
217
):
@@ -223,32 +220,41 @@ def square(x):
223
220
# connection doesn't match the location of the dataset.
224
221
return x * x # pragma: NO COVER
225
222
226
- with pytest .raises (
227
- ValueError ,
228
- match = re .escape ("The location does not match BigQuery connection location:" ),
229
- ):
230
- bff .remote_function (
231
- input_types = int ,
232
- output_type = int ,
233
- bigquery_client = bigquery_client ,
234
- bigquery_connection_client = bigqueryconnection_client ,
235
- cloud_functions_client = cloudfunctions_client ,
236
- resource_manager_client = resourcemanager_client ,
237
- dataset = dataset_id_permanent ,
238
- bigquery_connection = bq_cf_connection_location_mismatched ,
239
- # See e2e tests for tests that actually deploy the Cloud Function.
240
- reuse = True ,
241
- name = get_function_name (square ),
242
- cloud_function_service_account = "default" ,
243
- )(square )
223
+ bq_cf_connection_location_mismatched_path_fmt = get_bq_connection_id_path_format (
224
+ bigframes .clients .get_canonical_bq_connection_id (
225
+ bq_cf_connection_location_mismatched ,
226
+ session .bqclient .project ,
227
+ session ._location ,
228
+ )
229
+ )
230
+ connection_ids = [
231
+ bq_cf_connection_location_mismatched ,
232
+ bq_cf_connection_location_mismatched_path_fmt ,
233
+ ]
234
+
235
+ for connection_id in connection_ids :
236
+ with pytest .raises (
237
+ ValueError ,
238
+ match = re .escape (
239
+ "The location does not match BigQuery connection location:"
240
+ ),
241
+ ):
242
+ bff .remote_function (
243
+ input_types = int ,
244
+ output_type = int ,
245
+ session = session ,
246
+ dataset = dataset_id_permanent ,
247
+ bigquery_connection = connection_id ,
248
+ # See e2e tests for tests that actually deploy the Cloud Function.
249
+ reuse = True ,
250
+ name = get_function_name (square ),
251
+ cloud_function_service_account = "default" ,
252
+ )(square )
244
253
245
254
246
255
@pytest .mark .flaky (retries = 2 , delay = 120 )
247
- def test_remote_function_direct_no_session_param_location_project_specified (
248
- bigquery_client ,
249
- bigqueryconnection_client ,
250
- cloudfunctions_client ,
251
- resourcemanager_client ,
256
+ def test_remote_function_connection_w_location_project (
257
+ session ,
252
258
scalars_dfs ,
253
259
dataset_id_permanent ,
254
260
bq_cf_connection_location_project ,
@@ -259,10 +265,7 @@ def square(x):
259
265
square = bff .remote_function (
260
266
input_types = int ,
261
267
output_type = int ,
262
- bigquery_client = bigquery_client ,
263
- bigquery_connection_client = bigqueryconnection_client ,
264
- cloud_functions_client = cloudfunctions_client ,
265
- resource_manager_client = resourcemanager_client ,
268
+ session = session ,
266
269
dataset = dataset_id_permanent ,
267
270
bigquery_connection = bq_cf_connection_location_project ,
268
271
# See e2e tests for tests that actually deploy the Cloud Function.
@@ -299,11 +302,8 @@ def square(x):
299
302
300
303
301
304
@pytest .mark .flaky (retries = 2 , delay = 120 )
302
- def test_remote_function_direct_no_session_param_project_mismatched (
303
- bigquery_client ,
304
- bigqueryconnection_client ,
305
- cloudfunctions_client ,
306
- resourcemanager_client ,
305
+ def test_remote_function_connection_w_project_mismatched (
306
+ session ,
307
307
dataset_id_permanent ,
308
308
bq_cf_connection_location_project_mismatched ,
309
309
):
@@ -312,26 +312,38 @@ def square(x):
312
312
# connection doesn't match the project of the dataset.
313
313
return x * x # pragma: NO COVER
314
314
315
- with pytest .raises (
316
- ValueError ,
317
- match = re .escape (
318
- "The project_id does not match BigQuery connection gcp_project_id:"
319
- ),
320
- ):
321
- bff .remote_function (
322
- input_types = int ,
323
- output_type = int ,
324
- bigquery_client = bigquery_client ,
325
- bigquery_connection_client = bigqueryconnection_client ,
326
- cloud_functions_client = cloudfunctions_client ,
327
- resource_manager_client = resourcemanager_client ,
328
- dataset = dataset_id_permanent ,
329
- bigquery_connection = bq_cf_connection_location_project_mismatched ,
330
- # See e2e tests for tests that actually deploy the Cloud Function.
331
- reuse = True ,
332
- name = get_function_name (square ),
333
- cloud_function_service_account = "default" ,
334
- )(square )
315
+ bq_cf_connection_location_project_mismatched_path_fmt = (
316
+ get_bq_connection_id_path_format (
317
+ bigframes .clients .get_canonical_bq_connection_id (
318
+ bq_cf_connection_location_project_mismatched ,
319
+ session .bqclient .project ,
320
+ session ._location ,
321
+ )
322
+ )
323
+ )
324
+ connection_ids = [
325
+ bq_cf_connection_location_project_mismatched ,
326
+ bq_cf_connection_location_project_mismatched_path_fmt ,
327
+ ]
328
+
329
+ for connection_id in connection_ids :
330
+ with pytest .raises (
331
+ ValueError ,
332
+ match = re .escape (
333
+ "The project_id does not match BigQuery connection gcp_project_id:"
334
+ ),
335
+ ):
336
+ bff .remote_function (
337
+ input_types = int ,
338
+ output_type = int ,
339
+ session = session ,
340
+ dataset = dataset_id_permanent ,
341
+ bigquery_connection = connection_id ,
342
+ # See e2e tests for tests that actually deploy the Cloud Function.
343
+ reuse = True ,
344
+ name = get_function_name (square ),
345
+ cloud_function_service_account = "default" ,
346
+ )(square )
335
347
336
348
337
349
@pytest .mark .flaky (retries = 2 , delay = 120 )
0 commit comments