@@ -230,6 +230,7 @@ def test_cloud_deploy_client_client_options(
230230 quota_project_id = None ,
231231 client_info = transports .base .DEFAULT_CLIENT_INFO ,
232232 always_use_jwt_access = True ,
233+ api_audience = None ,
233234 )
234235
235236 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -247,6 +248,7 @@ def test_cloud_deploy_client_client_options(
247248 quota_project_id = None ,
248249 client_info = transports .base .DEFAULT_CLIENT_INFO ,
249250 always_use_jwt_access = True ,
251+ api_audience = None ,
250252 )
251253
252254 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -264,6 +266,7 @@ def test_cloud_deploy_client_client_options(
264266 quota_project_id = None ,
265267 client_info = transports .base .DEFAULT_CLIENT_INFO ,
266268 always_use_jwt_access = True ,
269+ api_audience = None ,
267270 )
268271
269272 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -293,6 +296,25 @@ def test_cloud_deploy_client_client_options(
293296 quota_project_id = "octopus" ,
294297 client_info = transports .base .DEFAULT_CLIENT_INFO ,
295298 always_use_jwt_access = True ,
299+ api_audience = None ,
300+ )
301+ # Check the case api_endpoint is provided
302+ options = client_options .ClientOptions (
303+ api_audience = "https://language.googleapis.com"
304+ )
305+ with mock .patch .object (transport_class , "__init__" ) as patched :
306+ patched .return_value = None
307+ client = client_class (client_options = options , transport = transport_name )
308+ patched .assert_called_once_with (
309+ credentials = None ,
310+ credentials_file = None ,
311+ host = client .DEFAULT_ENDPOINT ,
312+ scopes = None ,
313+ client_cert_source_for_mtls = None ,
314+ quota_project_id = None ,
315+ client_info = transports .base .DEFAULT_CLIENT_INFO ,
316+ always_use_jwt_access = True ,
317+ api_audience = "https://language.googleapis.com" ,
296318 )
297319
298320
@@ -358,6 +380,7 @@ def test_cloud_deploy_client_mtls_env_auto(
358380 quota_project_id = None ,
359381 client_info = transports .base .DEFAULT_CLIENT_INFO ,
360382 always_use_jwt_access = True ,
383+ api_audience = None ,
361384 )
362385
363386 # Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -392,6 +415,7 @@ def test_cloud_deploy_client_mtls_env_auto(
392415 quota_project_id = None ,
393416 client_info = transports .base .DEFAULT_CLIENT_INFO ,
394417 always_use_jwt_access = True ,
418+ api_audience = None ,
395419 )
396420
397421 # Check the case client_cert_source and ADC client cert are not provided.
@@ -414,6 +438,7 @@ def test_cloud_deploy_client_mtls_env_auto(
414438 quota_project_id = None ,
415439 client_info = transports .base .DEFAULT_CLIENT_INFO ,
416440 always_use_jwt_access = True ,
441+ api_audience = None ,
417442 )
418443
419444
@@ -524,6 +549,7 @@ def test_cloud_deploy_client_client_options_scopes(
524549 quota_project_id = None ,
525550 client_info = transports .base .DEFAULT_CLIENT_INFO ,
526551 always_use_jwt_access = True ,
552+ api_audience = None ,
527553 )
528554
529555
@@ -557,6 +583,7 @@ def test_cloud_deploy_client_client_options_credentials_file(
557583 quota_project_id = None ,
558584 client_info = transports .base .DEFAULT_CLIENT_INFO ,
559585 always_use_jwt_access = True ,
586+ api_audience = None ,
560587 )
561588
562589
@@ -575,6 +602,7 @@ def test_cloud_deploy_client_client_options_from_dict():
575602 quota_project_id = None ,
576603 client_info = transports .base .DEFAULT_CLIENT_INFO ,
577604 always_use_jwt_access = True ,
605+ api_audience = None ,
578606 )
579607
580608
@@ -608,6 +636,7 @@ def test_cloud_deploy_client_create_channel_credentials_file(
608636 quota_project_id = None ,
609637 client_info = transports .base .DEFAULT_CLIENT_INFO ,
610638 always_use_jwt_access = True ,
639+ api_audience = None ,
611640 )
612641
613642 # test that the credentials from file are saved and used as the credentials.
@@ -6055,6 +6084,28 @@ def test_cloud_deploy_transport_auth_adc(transport_class):
60556084 )
60566085
60576086
6087+ @pytest .mark .parametrize (
6088+ "transport_class" ,
6089+ [
6090+ transports .CloudDeployGrpcTransport ,
6091+ transports .CloudDeployGrpcAsyncIOTransport ,
6092+ ],
6093+ )
6094+ def test_cloud_deploy_transport_auth_gdch_credentials (transport_class ):
6095+ host = "https://language.com"
6096+ api_audience_tests = [None , "https://language2.com" ]
6097+ api_audience_expect = [host , "https://language2.com" ]
6098+ for t , e in zip (api_audience_tests , api_audience_expect ):
6099+ with mock .patch .object (google .auth , "default" , autospec = True ) as adc :
6100+ gdch_mock = mock .MagicMock ()
6101+ type(gdch_mock ).with_gdch_audience = mock .PropertyMock (
6102+ return_value = gdch_mock
6103+ )
6104+ adc .return_value = (gdch_mock , None )
6105+ transport_class (host = host , api_audience = t )
6106+ gdch_mock .with_gdch_audience .assert_called_once_with (e )
6107+
6108+
60586109@pytest .mark .parametrize (
60596110 "transport_class,grpc_helpers" ,
60606111 [
@@ -6770,4 +6821,5 @@ def test_api_key_credentials(client_class, transport_class):
67706821 quota_project_id = None ,
67716822 client_info = transports .base .DEFAULT_CLIENT_INFO ,
67726823 always_use_jwt_access = True ,
6824+ api_audience = None ,
67736825 )
0 commit comments