Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 4249607

Browse files
1 parent 2ebe4fa commit 4249607

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

google/cloud/language_v1/services/language_service/client.py

+4
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ def __init__(
329329
client_cert_source_for_mtls=client_cert_source_func,
330330
quota_project_id=client_options.quota_project_id,
331331
client_info=client_info,
332+
always_use_jwt_access=(
333+
Transport == type(self).get_transport_class("grpc")
334+
or Transport == type(self).get_transport_class("grpc_asyncio")
335+
),
332336
)
333337

334338
def analyze_sentiment(

google/cloud/language_v1beta2/services/language_service/client.py

+4
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ def __init__(
329329
client_cert_source_for_mtls=client_cert_source_func,
330330
quota_project_id=client_options.quota_project_id,
331331
client_info=client_info,
332+
always_use_jwt_access=(
333+
Transport == type(self).get_transport_class("grpc")
334+
or Transport == type(self).get_transport_class("grpc_asyncio")
335+
),
332336
)
333337

334338
def analyze_sentiment(

tests/unit/gapic/language_v1/test_language_service.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,14 @@ def test_language_service_client_from_service_account_info(client_class):
119119
assert client.transport._host == "language.googleapis.com:443"
120120

121121

122-
@pytest.mark.parametrize(
123-
"client_class", [LanguageServiceClient, LanguageServiceAsyncClient,]
124-
)
125-
def test_language_service_client_service_account_always_use_jwt(client_class):
126-
with mock.patch.object(
127-
service_account.Credentials, "with_always_use_jwt_access", create=True
128-
) as use_jwt:
129-
creds = service_account.Credentials(None, None, None)
130-
client = client_class(credentials=creds)
131-
use_jwt.assert_not_called()
132-
133-
134122
@pytest.mark.parametrize(
135123
"transport_class,transport_name",
136124
[
137125
(transports.LanguageServiceGrpcTransport, "grpc"),
138126
(transports.LanguageServiceGrpcAsyncIOTransport, "grpc_asyncio"),
139127
],
140128
)
141-
def test_language_service_client_service_account_always_use_jwt_true(
129+
def test_language_service_client_service_account_always_use_jwt(
142130
transport_class, transport_name
143131
):
144132
with mock.patch.object(
@@ -148,6 +136,13 @@ def test_language_service_client_service_account_always_use_jwt_true(
148136
transport = transport_class(credentials=creds, always_use_jwt_access=True)
149137
use_jwt.assert_called_once_with(True)
150138

139+
with mock.patch.object(
140+
service_account.Credentials, "with_always_use_jwt_access", create=True
141+
) as use_jwt:
142+
creds = service_account.Credentials(None, None, None)
143+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
144+
use_jwt.assert_not_called()
145+
151146

152147
@pytest.mark.parametrize(
153148
"client_class", [LanguageServiceClient, LanguageServiceAsyncClient,]
@@ -228,6 +223,7 @@ def test_language_service_client_client_options(
228223
client_cert_source_for_mtls=None,
229224
quota_project_id=None,
230225
client_info=transports.base.DEFAULT_CLIENT_INFO,
226+
always_use_jwt_access=True,
231227
)
232228

233229
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -244,6 +240,7 @@ def test_language_service_client_client_options(
244240
client_cert_source_for_mtls=None,
245241
quota_project_id=None,
246242
client_info=transports.base.DEFAULT_CLIENT_INFO,
243+
always_use_jwt_access=True,
247244
)
248245

249246
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -260,6 +257,7 @@ def test_language_service_client_client_options(
260257
client_cert_source_for_mtls=None,
261258
quota_project_id=None,
262259
client_info=transports.base.DEFAULT_CLIENT_INFO,
260+
always_use_jwt_access=True,
263261
)
264262

265263
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -288,6 +286,7 @@ def test_language_service_client_client_options(
288286
client_cert_source_for_mtls=None,
289287
quota_project_id="octopus",
290288
client_info=transports.base.DEFAULT_CLIENT_INFO,
289+
always_use_jwt_access=True,
291290
)
292291

293292

@@ -364,6 +363,7 @@ def test_language_service_client_mtls_env_auto(
364363
client_cert_source_for_mtls=expected_client_cert_source,
365364
quota_project_id=None,
366365
client_info=transports.base.DEFAULT_CLIENT_INFO,
366+
always_use_jwt_access=True,
367367
)
368368

369369
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -397,6 +397,7 @@ def test_language_service_client_mtls_env_auto(
397397
client_cert_source_for_mtls=expected_client_cert_source,
398398
quota_project_id=None,
399399
client_info=transports.base.DEFAULT_CLIENT_INFO,
400+
always_use_jwt_access=True,
400401
)
401402

402403
# Check the case client_cert_source and ADC client cert are not provided.
@@ -418,6 +419,7 @@ def test_language_service_client_mtls_env_auto(
418419
client_cert_source_for_mtls=None,
419420
quota_project_id=None,
420421
client_info=transports.base.DEFAULT_CLIENT_INFO,
422+
always_use_jwt_access=True,
421423
)
422424

423425

@@ -448,6 +450,7 @@ def test_language_service_client_client_options_scopes(
448450
client_cert_source_for_mtls=None,
449451
quota_project_id=None,
450452
client_info=transports.base.DEFAULT_CLIENT_INFO,
453+
always_use_jwt_access=True,
451454
)
452455

453456

@@ -478,6 +481,7 @@ def test_language_service_client_client_options_credentials_file(
478481
client_cert_source_for_mtls=None,
479482
quota_project_id=None,
480483
client_info=transports.base.DEFAULT_CLIENT_INFO,
484+
always_use_jwt_access=True,
481485
)
482486

483487

@@ -497,6 +501,7 @@ def test_language_service_client_client_options_from_dict():
497501
client_cert_source_for_mtls=None,
498502
quota_project_id=None,
499503
client_info=transports.base.DEFAULT_CLIENT_INFO,
504+
always_use_jwt_access=True,
500505
)
501506

502507

tests/unit/gapic/language_v1beta2/test_language_service.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,14 @@ def test_language_service_client_from_service_account_info(client_class):
121121
assert client.transport._host == "language.googleapis.com:443"
122122

123123

124-
@pytest.mark.parametrize(
125-
"client_class", [LanguageServiceClient, LanguageServiceAsyncClient,]
126-
)
127-
def test_language_service_client_service_account_always_use_jwt(client_class):
128-
with mock.patch.object(
129-
service_account.Credentials, "with_always_use_jwt_access", create=True
130-
) as use_jwt:
131-
creds = service_account.Credentials(None, None, None)
132-
client = client_class(credentials=creds)
133-
use_jwt.assert_not_called()
134-
135-
136124
@pytest.mark.parametrize(
137125
"transport_class,transport_name",
138126
[
139127
(transports.LanguageServiceGrpcTransport, "grpc"),
140128
(transports.LanguageServiceGrpcAsyncIOTransport, "grpc_asyncio"),
141129
],
142130
)
143-
def test_language_service_client_service_account_always_use_jwt_true(
131+
def test_language_service_client_service_account_always_use_jwt(
144132
transport_class, transport_name
145133
):
146134
with mock.patch.object(
@@ -150,6 +138,13 @@ def test_language_service_client_service_account_always_use_jwt_true(
150138
transport = transport_class(credentials=creds, always_use_jwt_access=True)
151139
use_jwt.assert_called_once_with(True)
152140

141+
with mock.patch.object(
142+
service_account.Credentials, "with_always_use_jwt_access", create=True
143+
) as use_jwt:
144+
creds = service_account.Credentials(None, None, None)
145+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
146+
use_jwt.assert_not_called()
147+
153148

154149
@pytest.mark.parametrize(
155150
"client_class", [LanguageServiceClient, LanguageServiceAsyncClient,]
@@ -230,6 +225,7 @@ def test_language_service_client_client_options(
230225
client_cert_source_for_mtls=None,
231226
quota_project_id=None,
232227
client_info=transports.base.DEFAULT_CLIENT_INFO,
228+
always_use_jwt_access=True,
233229
)
234230

235231
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -246,6 +242,7 @@ def test_language_service_client_client_options(
246242
client_cert_source_for_mtls=None,
247243
quota_project_id=None,
248244
client_info=transports.base.DEFAULT_CLIENT_INFO,
245+
always_use_jwt_access=True,
249246
)
250247

251248
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -262,6 +259,7 @@ def test_language_service_client_client_options(
262259
client_cert_source_for_mtls=None,
263260
quota_project_id=None,
264261
client_info=transports.base.DEFAULT_CLIENT_INFO,
262+
always_use_jwt_access=True,
265263
)
266264

267265
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -290,6 +288,7 @@ def test_language_service_client_client_options(
290288
client_cert_source_for_mtls=None,
291289
quota_project_id="octopus",
292290
client_info=transports.base.DEFAULT_CLIENT_INFO,
291+
always_use_jwt_access=True,
293292
)
294293

295294

@@ -366,6 +365,7 @@ def test_language_service_client_mtls_env_auto(
366365
client_cert_source_for_mtls=expected_client_cert_source,
367366
quota_project_id=None,
368367
client_info=transports.base.DEFAULT_CLIENT_INFO,
368+
always_use_jwt_access=True,
369369
)
370370

371371
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -399,6 +399,7 @@ def test_language_service_client_mtls_env_auto(
399399
client_cert_source_for_mtls=expected_client_cert_source,
400400
quota_project_id=None,
401401
client_info=transports.base.DEFAULT_CLIENT_INFO,
402+
always_use_jwt_access=True,
402403
)
403404

404405
# Check the case client_cert_source and ADC client cert are not provided.
@@ -420,6 +421,7 @@ def test_language_service_client_mtls_env_auto(
420421
client_cert_source_for_mtls=None,
421422
quota_project_id=None,
422423
client_info=transports.base.DEFAULT_CLIENT_INFO,
424+
always_use_jwt_access=True,
423425
)
424426

425427

@@ -450,6 +452,7 @@ def test_language_service_client_client_options_scopes(
450452
client_cert_source_for_mtls=None,
451453
quota_project_id=None,
452454
client_info=transports.base.DEFAULT_CLIENT_INFO,
455+
always_use_jwt_access=True,
453456
)
454457

455458

@@ -480,6 +483,7 @@ def test_language_service_client_client_options_credentials_file(
480483
client_cert_source_for_mtls=None,
481484
quota_project_id=None,
482485
client_info=transports.base.DEFAULT_CLIENT_INFO,
486+
always_use_jwt_access=True,
483487
)
484488

485489

@@ -499,6 +503,7 @@ def test_language_service_client_client_options_from_dict():
499503
client_cert_source_for_mtls=None,
500504
quota_project_id=None,
501505
client_info=transports.base.DEFAULT_CLIENT_INFO,
506+
always_use_jwt_access=True,
502507
)
503508

504509

0 commit comments

Comments
 (0)