@@ -243,6 +243,7 @@ def test_livestream_service_client_client_options(
243243 quota_project_id = None ,
244244 client_info = transports .base .DEFAULT_CLIENT_INFO ,
245245 always_use_jwt_access = True ,
246+ api_audience = None ,
246247 )
247248
248249 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -260,6 +261,7 @@ def test_livestream_service_client_client_options(
260261 quota_project_id = None ,
261262 client_info = transports .base .DEFAULT_CLIENT_INFO ,
262263 always_use_jwt_access = True ,
264+ api_audience = None ,
263265 )
264266
265267 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -277,6 +279,7 @@ def test_livestream_service_client_client_options(
277279 quota_project_id = None ,
278280 client_info = transports .base .DEFAULT_CLIENT_INFO ,
279281 always_use_jwt_access = True ,
282+ api_audience = None ,
280283 )
281284
282285 # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -306,6 +309,25 @@ def test_livestream_service_client_client_options(
306309 quota_project_id = "octopus" ,
307310 client_info = transports .base .DEFAULT_CLIENT_INFO ,
308311 always_use_jwt_access = True ,
312+ api_audience = None ,
313+ )
314+ # Check the case api_endpoint is provided
315+ options = client_options .ClientOptions (
316+ api_audience = "https://language.googleapis.com"
317+ )
318+ with mock .patch .object (transport_class , "__init__" ) as patched :
319+ patched .return_value = None
320+ client = client_class (client_options = options , transport = transport_name )
321+ patched .assert_called_once_with (
322+ credentials = None ,
323+ credentials_file = None ,
324+ host = client .DEFAULT_ENDPOINT ,
325+ scopes = None ,
326+ client_cert_source_for_mtls = None ,
327+ quota_project_id = None ,
328+ client_info = transports .base .DEFAULT_CLIENT_INFO ,
329+ always_use_jwt_access = True ,
330+ api_audience = "https://language.googleapis.com" ,
309331 )
310332
311333
@@ -383,6 +405,7 @@ def test_livestream_service_client_mtls_env_auto(
383405 quota_project_id = None ,
384406 client_info = transports .base .DEFAULT_CLIENT_INFO ,
385407 always_use_jwt_access = True ,
408+ api_audience = None ,
386409 )
387410
388411 # Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -417,6 +440,7 @@ def test_livestream_service_client_mtls_env_auto(
417440 quota_project_id = None ,
418441 client_info = transports .base .DEFAULT_CLIENT_INFO ,
419442 always_use_jwt_access = True ,
443+ api_audience = None ,
420444 )
421445
422446 # Check the case client_cert_source and ADC client cert are not provided.
@@ -439,6 +463,7 @@ def test_livestream_service_client_mtls_env_auto(
439463 quota_project_id = None ,
440464 client_info = transports .base .DEFAULT_CLIENT_INFO ,
441465 always_use_jwt_access = True ,
466+ api_audience = None ,
442467 )
443468
444469
@@ -553,6 +578,7 @@ def test_livestream_service_client_client_options_scopes(
553578 quota_project_id = None ,
554579 client_info = transports .base .DEFAULT_CLIENT_INFO ,
555580 always_use_jwt_access = True ,
581+ api_audience = None ,
556582 )
557583
558584
@@ -591,6 +617,7 @@ def test_livestream_service_client_client_options_credentials_file(
591617 quota_project_id = None ,
592618 client_info = transports .base .DEFAULT_CLIENT_INFO ,
593619 always_use_jwt_access = True ,
620+ api_audience = None ,
594621 )
595622
596623
@@ -611,6 +638,7 @@ def test_livestream_service_client_client_options_from_dict():
611638 quota_project_id = None ,
612639 client_info = transports .base .DEFAULT_CLIENT_INFO ,
613640 always_use_jwt_access = True ,
641+ api_audience = None ,
614642 )
615643
616644
@@ -649,6 +677,7 @@ def test_livestream_service_client_create_channel_credentials_file(
649677 quota_project_id = None ,
650678 client_info = transports .base .DEFAULT_CLIENT_INFO ,
651679 always_use_jwt_access = True ,
680+ api_audience = None ,
652681 )
653682
654683 # test that the credentials from file are saved and used as the credentials.
@@ -5253,6 +5282,28 @@ def test_livestream_service_transport_auth_adc(transport_class):
52535282 )
52545283
52555284
5285+ @pytest .mark .parametrize (
5286+ "transport_class" ,
5287+ [
5288+ transports .LivestreamServiceGrpcTransport ,
5289+ transports .LivestreamServiceGrpcAsyncIOTransport ,
5290+ ],
5291+ )
5292+ def test_livestream_service_transport_auth_gdch_credentials (transport_class ):
5293+ host = "https://language.com"
5294+ api_audience_tests = [None , "https://language2.com" ]
5295+ api_audience_expect = [host , "https://language2.com" ]
5296+ for t , e in zip (api_audience_tests , api_audience_expect ):
5297+ with mock .patch .object (google .auth , "default" , autospec = True ) as adc :
5298+ gdch_mock = mock .MagicMock ()
5299+ type(gdch_mock ).with_gdch_audience = mock .PropertyMock (
5300+ return_value = gdch_mock
5301+ )
5302+ adc .return_value = (gdch_mock , None )
5303+ transport_class (host = host , api_audience = t )
5304+ gdch_mock .with_gdch_audience .assert_called_once_with (e )
5305+
5306+
52565307@pytest .mark .parametrize (
52575308 "transport_class,grpc_helpers" ,
52585309 [
@@ -5813,4 +5864,5 @@ def test_api_key_credentials(client_class, transport_class):
58135864 quota_project_id = None ,
58145865 client_info = transports .base .DEFAULT_CLIENT_INFO ,
58155866 always_use_jwt_access = True ,
5867+ api_audience = None ,
58165868 )
0 commit comments