3030 BatchWriteResponse ,
3131 DefaultTransactionOptions ,
3232)
33+ import mock
3334from google .cloud ._helpers import UTC , _datetime_to_pb_timestamp
3435import datetime
3536from google .api_core .exceptions import Aborted , Unknown
@@ -199,7 +200,8 @@ def test_commit_already_committed(self):
199200
200201 self .assertNoSpans ()
201202
202- def test_commit_grpc_error (self ):
203+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
204+ def test_commit_grpc_error (self , mock_region ):
203205 keys = [[0 ], [1 ], [2 ]]
204206 keyset = KeySet (keys = keys )
205207 database = _Database ()
@@ -220,7 +222,8 @@ def test_commit_grpc_error(self):
220222 ),
221223 )
222224
223- def test_commit_ok (self ):
225+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
226+ def test_commit_ok (self , mock_region ):
224227 now = datetime .datetime .utcnow ().replace (tzinfo = UTC )
225228 now_pb = _datetime_to_pb_timestamp (now )
226229 response = CommitResponse (commit_timestamp = now_pb )
@@ -377,35 +380,41 @@ def _test_commit_with_options(
377380
378381 self .assertEqual (max_commit_delay_in , max_commit_delay )
379382
380- def test_commit_w_request_tag_success (self ):
383+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
384+ def test_commit_w_request_tag_success (self , mock_region ):
381385 request_options = RequestOptions (
382386 request_tag = "tag-1" ,
383387 )
384388 self ._test_commit_with_options (request_options = request_options )
385389
386- def test_commit_w_transaction_tag_success (self ):
390+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
391+ def test_commit_w_transaction_tag_success (self , mock_region ):
387392 request_options = RequestOptions (
388393 transaction_tag = "tag-1-1" ,
389394 )
390395 self ._test_commit_with_options (request_options = request_options )
391396
392- def test_commit_w_request_and_transaction_tag_success (self ):
397+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
398+ def test_commit_w_request_and_transaction_tag_success (self , mock_region ):
393399 request_options = RequestOptions (
394400 request_tag = "tag-1" ,
395401 transaction_tag = "tag-1-1" ,
396402 )
397403 self ._test_commit_with_options (request_options = request_options )
398404
399- def test_commit_w_request_and_transaction_tag_dictionary_success (self ):
405+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
406+ def test_commit_w_request_and_transaction_tag_dictionary_success (self , mock_region ):
400407 request_options = {"request_tag" : "tag-1" , "transaction_tag" : "tag-1-1" }
401408 self ._test_commit_with_options (request_options = request_options )
402409
403- def test_commit_w_incorrect_tag_dictionary_error (self ):
410+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
411+ def test_commit_w_incorrect_tag_dictionary_error (self , mock_region ):
404412 request_options = {"incorrect_tag" : "tag-1-1" }
405413 with self .assertRaises (ValueError ):
406414 self ._test_commit_with_options (request_options = request_options )
407415
408- def test_commit_w_max_commit_delay (self ):
416+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
417+ def test_commit_w_max_commit_delay (self , mock_region ):
409418 request_options = RequestOptions (
410419 request_tag = "tag-1" ,
411420 )
@@ -414,15 +423,17 @@ def test_commit_w_max_commit_delay(self):
414423 max_commit_delay_in = datetime .timedelta (milliseconds = 100 ),
415424 )
416425
417- def test_commit_w_exclude_txn_from_change_streams (self ):
426+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
427+ def test_commit_w_exclude_txn_from_change_streams (self , mock_region ):
418428 request_options = RequestOptions (
419429 request_tag = "tag-1" ,
420430 )
421431 self ._test_commit_with_options (
422432 request_options = request_options , exclude_txn_from_change_streams = True
423433 )
424434
425- def test_commit_w_isolation_level (self ):
435+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
436+ def test_commit_w_isolation_level (self , mock_region ):
426437 request_options = RequestOptions (
427438 request_tag = "tag-1" ,
428439 )
@@ -431,7 +442,8 @@ def test_commit_w_isolation_level(self):
431442 isolation_level = TransactionOptions .IsolationLevel .REPEATABLE_READ ,
432443 )
433444
434- def test_commit_w_read_lock_mode (self ):
445+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
446+ def test_commit_w_read_lock_mode (self , mock_region ):
435447 request_options = RequestOptions (
436448 request_tag = "tag-1" ,
437449 )
@@ -440,7 +452,8 @@ def test_commit_w_read_lock_mode(self):
440452 read_lock_mode = TransactionOptions .ReadWrite .ReadLockMode .OPTIMISTIC ,
441453 )
442454
443- def test_commit_w_isolation_level_and_read_lock_mode (self ):
455+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
456+ def test_commit_w_isolation_level_and_read_lock_mode (self , mock_region ):
444457 request_options = RequestOptions (
445458 request_tag = "tag-1" ,
446459 )
@@ -450,7 +463,8 @@ def test_commit_w_isolation_level_and_read_lock_mode(self):
450463 read_lock_mode = TransactionOptions .ReadWrite .ReadLockMode .PESSIMISTIC ,
451464 )
452465
453- def test_context_mgr_already_committed (self ):
466+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
467+ def test_context_mgr_already_committed (self , mock_region ):
454468 now = datetime .datetime .utcnow ().replace (tzinfo = UTC )
455469 database = _Database ()
456470 api = database .spanner_api = _FauxSpannerAPI ()
@@ -464,7 +478,8 @@ def test_context_mgr_already_committed(self):
464478
465479 self .assertEqual (api ._committed , None )
466480
467- def test_context_mgr_success (self ):
481+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
482+ def test_context_mgr_success (self , mock_region ):
468483 now = datetime .datetime .utcnow ().replace (tzinfo = UTC )
469484 now_pb = _datetime_to_pb_timestamp (now )
470485 response = CommitResponse (commit_timestamp = now_pb )
@@ -511,7 +526,8 @@ def test_context_mgr_success(self):
511526 ),
512527 )
513528
514- def test_context_mgr_failure (self ):
529+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
530+ def test_context_mgr_failure (self , mock_region ):
515531 now = datetime .datetime .utcnow ().replace (tzinfo = UTC )
516532 now_pb = _datetime_to_pb_timestamp (now )
517533 response = CommitResponse (commit_timestamp = now_pb )
@@ -542,7 +558,8 @@ def test_ctor(self):
542558 groups = self ._make_one (session )
543559 self .assertIs (groups ._session , session )
544560
545- def test_batch_write_already_committed (self ):
561+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
562+ def test_batch_write_already_committed (self , mock_region ):
546563 keys = [[0 ], [1 ], [2 ]]
547564 keyset = KeySet (keys = keys )
548565 database = _Database ()
@@ -565,7 +582,8 @@ def test_batch_write_already_committed(self):
565582 with self .assertRaises (ValueError ):
566583 groups .batch_write ()
567584
568- def test_batch_write_grpc_error (self ):
585+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
586+ def test_batch_write_grpc_error (self , mock_region ):
569587 keys = [[0 ], [1 ], [2 ]]
570588 keyset = KeySet (keys = keys )
571589 database = _Database ()
@@ -663,25 +681,31 @@ def _test_batch_write_with_request_options(
663681 ),
664682 )
665683
666- def test_batch_write_no_request_options (self ):
684+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
685+ def test_batch_write_no_request_options (self , mock_region ):
667686 self ._test_batch_write_with_request_options ()
668687
669- def test_batch_write_end_to_end_tracing_enabled (self ):
688+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
689+ def test_batch_write_end_to_end_tracing_enabled (self , mock_region ):
670690 self ._test_batch_write_with_request_options (enable_end_to_end_tracing = True )
671691
672- def test_batch_write_w_transaction_tag_success (self ):
692+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
693+ def test_batch_write_w_transaction_tag_success (self , mock_region ):
673694 self ._test_batch_write_with_request_options (
674695 RequestOptions (transaction_tag = "tag-1-1" )
675696 )
676697
677- def test_batch_write_w_transaction_tag_dictionary_success (self ):
698+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
699+ def test_batch_write_w_transaction_tag_dictionary_success (self , mock_region ):
678700 self ._test_batch_write_with_request_options ({"transaction_tag" : "tag-1-1" })
679701
680- def test_batch_write_w_incorrect_tag_dictionary_error (self ):
702+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
703+ def test_batch_write_w_incorrect_tag_dictionary_error (self , mock_region ):
681704 with self .assertRaises (ValueError ):
682705 self ._test_batch_write_with_request_options ({"incorrect_tag" : "tag-1-1" })
683706
684- def test_batch_write_w_exclude_txn_from_change_streams (self ):
707+ @mock .patch ("google.cloud.spanner_v1._opentelemetry_tracing._get_cloud_region" , return_value = "global" )
708+ def test_batch_write_w_exclude_txn_from_change_streams (self , mock_region ):
685709 self ._test_batch_write_with_request_options (
686710 exclude_txn_from_change_streams = True
687711 )
0 commit comments