@@ -65,7 +65,7 @@ def _get_target_class():
6565 return CrossSync ._Sync_Impl .DataClient
6666
6767 @classmethod
68- def _make_client (cls , * args , use_emulator = True , ** kwargs ):
68+ def _make_client (cls , * args , use_emulator = True , use_mtls = "auto" , ** kwargs ):
6969 import os
7070
7171 env_mask = {}
@@ -77,6 +77,8 @@ def _make_client(cls, *args, use_emulator=True, **kwargs):
7777 else :
7878 kwargs ["credentials" ] = kwargs .get ("credentials" , AnonymousCredentials ())
7979 kwargs ["project" ] = kwargs .get ("project" , "project-id" )
80+ if use_mtls is not None :
81+ env_mask ["GOOGLE_API_USE_MTLS_ENDPOINT" ] = use_mtls
8082 with mock .patch .dict (os .environ , env_mask ):
8183 return cls ._get_target_class ()(* args , ** kwargs )
8284
@@ -206,10 +208,8 @@ def test__start_background_channel_refresh(self):
206208 def test__ping_and_warm_instances (self ):
207209 """test ping and warm with mocked asyncio.gather"""
208210 client_mock = mock .Mock ()
209- client_mock ._execute_ping_and_warms = (
210- lambda * args : self ._get_target_class ()._execute_ping_and_warms (
211- client_mock , * args
212- )
211+ client_mock ._execute_ping_and_warms = lambda * args : (
212+ self ._get_target_class ()._execute_ping_and_warms (client_mock , * args )
213213 )
214214 with mock .patch .object (
215215 CrossSync ._Sync_Impl , "gather_partials" , CrossSync ._Sync_Impl .Mock ()
@@ -252,10 +252,8 @@ def test__ping_and_warm_instances(self):
252252 def test__ping_and_warm_single_instance (self ):
253253 """should be able to call ping and warm with single instance"""
254254 client_mock = mock .Mock ()
255- client_mock ._execute_ping_and_warms = (
256- lambda * args : self ._get_target_class ()._execute_ping_and_warms (
257- client_mock , * args
258- )
255+ client_mock ._execute_ping_and_warms = lambda * args : (
256+ self ._get_target_class ()._execute_ping_and_warms (client_mock , * args )
259257 )
260258 with mock .patch .object (
261259 CrossSync ._Sync_Impl , "gather_partials" , CrossSync ._Sync_Impl .Mock ()
@@ -844,11 +842,17 @@ def test_context_manager(self):
844842 close_mock .assert_called_once ()
845843 true_close ()
846844
847- def test_default_universe_domain (self ):
845+ @pytest .mark .parametrize (
846+ "use_mtls, expected_domain" ,
847+ [("never" , "googleapis.com" ), ("always" , "mtls.googleapis.com" )],
848+ )
849+ def test_default_universe_domain (self , use_mtls , expected_domain ):
848850 """When not passed, universe_domain should default to googleapis.com"""
849- with self ._make_client (project = "project-id" , credentials = None ) as client :
851+ with self ._make_client (
852+ project = "project-id" , credentials = None , use_mtls = use_mtls
853+ ) as client :
850854 assert client .universe_domain == "googleapis.com"
851- assert client .api_endpoint == "bigtable.googleapis.com "
855+ assert client .api_endpoint == f "bigtable.{ expected_domain } "
852856
853857 def test_custom_universe_domain (self ):
854858 """test with a customized universe domain value and emulator enabled"""
@@ -859,6 +863,7 @@ def test_custom_universe_domain(self):
859863 client_options = options ,
860864 use_emulator = True ,
861865 credentials = None ,
866+ use_mtls = "never" ,
862867 ) as client :
863868 assert client .universe_domain == universe_domain
864869 assert client .api_endpoint == f"bigtable.{ universe_domain } "
@@ -871,20 +876,20 @@ def test_configured_universe_domain_matches_GDU(self):
871876 project = "project_id" , client_options = options , credentials = None
872877 ) as client :
873878 assert client .universe_domain == "googleapis.com"
874- assert client .api_endpoint == "bigtable.googleapis.com"
875879
876880 def test_credential_universe_domain_matches_GDU (self ):
877881 """Test with credentials"""
878882 creds = AnonymousCredentials ()
879883 creds ._universe_domain = "googleapis.com"
880884 with self ._make_client (project = "project_id" , credentials = creds ) as client :
881885 assert client .universe_domain == "googleapis.com"
882- assert client .api_endpoint == "bigtable.googleapis.com"
883886
884887 def test_anomynous_credential_universe_domain (self ):
885888 """Anomynopus credentials should use default universe domain"""
886889 creds = AnonymousCredentials ()
887- with self ._make_client (project = "project_id" , credentials = creds ) as client :
890+ with self ._make_client (
891+ project = "project_id" , credentials = creds , use_mtls = "never"
892+ ) as client :
888893 assert client .universe_domain == "googleapis.com"
889894 assert client .api_endpoint == "bigtable.googleapis.com"
890895
@@ -901,6 +906,7 @@ def test_configured_universe_domain_mismatched_credentials(self):
901906 client_options = options ,
902907 use_emulator = False ,
903908 credentials = creds ,
909+ use_mtls = "never" ,
904910 )
905911 err_msg = f"The configured universe domain ({ universe_domain } ) does not match the universe domain found in the credentials ({ creds .universe_domain } ). If you haven't configured the universe domain explicitly, `googleapis.com` is the default."
906912 assert exc .value .args [0 ] == err_msg
@@ -913,7 +919,10 @@ def test_configured_universe_domain_matches_credentials(self):
913919 creds = AnonymousCredentials ()
914920 creds ._universe_domain = universe_domain
915921 with self ._make_client (
916- project = "project_id" , credentials = creds , client_options = options
922+ project = "project_id" ,
923+ credentials = creds ,
924+ client_options = options ,
925+ use_mtls = "never" ,
917926 ) as client :
918927 assert client .universe_domain == universe_domain
919928 assert client .api_endpoint == f"bigtable.{ universe_domain } "
@@ -1313,11 +1322,11 @@ def _make_client(self, *args, **kwargs):
13131322
13141323 def _make_table (self , * args , ** kwargs ):
13151324 client_mock = mock .Mock ()
1316- client_mock ._register_instance .side_effect = (
1317- lambda * args , ** kwargs : CrossSync ._Sync_Impl .yield_to_event_loop ()
1325+ client_mock ._register_instance .side_effect = lambda * args , ** kwargs : (
1326+ CrossSync ._Sync_Impl .yield_to_event_loop ()
13181327 )
1319- client_mock ._remove_instance_registration .side_effect = (
1320- lambda * args , ** kwargs : CrossSync ._Sync_Impl .yield_to_event_loop ()
1328+ client_mock ._remove_instance_registration .side_effect = lambda * args , ** kwargs : (
1329+ CrossSync ._Sync_Impl .yield_to_event_loop ()
13211330 )
13221331 kwargs ["instance_id" ] = kwargs .get (
13231332 "instance_id" , args [0 ] if args else "instance"
@@ -1779,9 +1788,8 @@ def test_read_rows_sharded_multiple_queries(self):
17791788 with mock .patch .object (
17801789 table .client ._gapic_client , "read_rows"
17811790 ) as read_rows :
1782- read_rows .side_effect = (
1783- lambda * args ,
1784- ** kwargs : CrossSync ._Sync_Impl .TestReadRows ._make_gapic_stream (
1791+ read_rows .side_effect = lambda * args , ** kwargs : (
1792+ CrossSync ._Sync_Impl .TestReadRows ._make_gapic_stream (
17851793 [
17861794 CrossSync ._Sync_Impl .TestReadRows ._make_chunk (row_key = k )
17871795 for k in args [0 ].rows .row_keys
@@ -2870,6 +2878,7 @@ def prepare_mock(self, client):
28702878 yield prepare_mock
28712879
28722880 def _make_gapic_stream (self , sample_list : list ["ExecuteQueryResponse" | Exception ]):
2881+
28732882 class MockStream :
28742883 def __init__ (self , sample_list ):
28752884 self .sample_list = sample_list
0 commit comments