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

Commit 26b493b

Browse files
1 parent 680319e commit 26b493b

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

google/cloud/clouddms_v1/services/data_migration_service/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ def __init__(
372372
client_cert_source_for_mtls=client_cert_source_func,
373373
quota_project_id=client_options.quota_project_id,
374374
client_info=client_info,
375+
always_use_jwt_access=(
376+
Transport == type(self).get_transport_class("grpc")
377+
or Transport == type(self).get_transport_class("grpc_asyncio")
378+
),
375379
)
376380

377381
def list_migration_jobs(

tests/unit/gapic/clouddms_v1/test_data_migration_service.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,14 @@ def test_data_migration_service_client_from_service_account_info(client_class):
134134
assert client.transport._host == "datamigration.googleapis.com:443"
135135

136136

137-
@pytest.mark.parametrize(
138-
"client_class", [DataMigrationServiceClient, DataMigrationServiceAsyncClient,]
139-
)
140-
def test_data_migration_service_client_service_account_always_use_jwt(client_class):
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-
client = client_class(credentials=creds)
146-
use_jwt.assert_not_called()
147-
148-
149137
@pytest.mark.parametrize(
150138
"transport_class,transport_name",
151139
[
152140
(transports.DataMigrationServiceGrpcTransport, "grpc"),
153141
(transports.DataMigrationServiceGrpcAsyncIOTransport, "grpc_asyncio"),
154142
],
155143
)
156-
def test_data_migration_service_client_service_account_always_use_jwt_true(
144+
def test_data_migration_service_client_service_account_always_use_jwt(
157145
transport_class, transport_name
158146
):
159147
with mock.patch.object(
@@ -163,6 +151,13 @@ def test_data_migration_service_client_service_account_always_use_jwt_true(
163151
transport = transport_class(credentials=creds, always_use_jwt_access=True)
164152
use_jwt.assert_called_once_with(True)
165153

154+
with mock.patch.object(
155+
service_account.Credentials, "with_always_use_jwt_access", create=True
156+
) as use_jwt:
157+
creds = service_account.Credentials(None, None, None)
158+
transport = transport_class(credentials=creds, always_use_jwt_access=False)
159+
use_jwt.assert_not_called()
160+
166161

167162
@pytest.mark.parametrize(
168163
"client_class", [DataMigrationServiceClient, DataMigrationServiceAsyncClient,]
@@ -247,6 +242,7 @@ def test_data_migration_service_client_client_options(
247242
client_cert_source_for_mtls=None,
248243
quota_project_id=None,
249244
client_info=transports.base.DEFAULT_CLIENT_INFO,
245+
always_use_jwt_access=True,
250246
)
251247

252248
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -263,6 +259,7 @@ def test_data_migration_service_client_client_options(
263259
client_cert_source_for_mtls=None,
264260
quota_project_id=None,
265261
client_info=transports.base.DEFAULT_CLIENT_INFO,
262+
always_use_jwt_access=True,
266263
)
267264

268265
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -279,6 +276,7 @@ def test_data_migration_service_client_client_options(
279276
client_cert_source_for_mtls=None,
280277
quota_project_id=None,
281278
client_info=transports.base.DEFAULT_CLIENT_INFO,
279+
always_use_jwt_access=True,
282280
)
283281

284282
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -307,6 +305,7 @@ def test_data_migration_service_client_client_options(
307305
client_cert_source_for_mtls=None,
308306
quota_project_id="octopus",
309307
client_info=transports.base.DEFAULT_CLIENT_INFO,
308+
always_use_jwt_access=True,
310309
)
311310

312311

@@ -383,6 +382,7 @@ def test_data_migration_service_client_mtls_env_auto(
383382
client_cert_source_for_mtls=expected_client_cert_source,
384383
quota_project_id=None,
385384
client_info=transports.base.DEFAULT_CLIENT_INFO,
385+
always_use_jwt_access=True,
386386
)
387387

388388
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -416,6 +416,7 @@ def test_data_migration_service_client_mtls_env_auto(
416416
client_cert_source_for_mtls=expected_client_cert_source,
417417
quota_project_id=None,
418418
client_info=transports.base.DEFAULT_CLIENT_INFO,
419+
always_use_jwt_access=True,
419420
)
420421

421422
# Check the case client_cert_source and ADC client cert are not provided.
@@ -437,6 +438,7 @@ def test_data_migration_service_client_mtls_env_auto(
437438
client_cert_source_for_mtls=None,
438439
quota_project_id=None,
439440
client_info=transports.base.DEFAULT_CLIENT_INFO,
441+
always_use_jwt_access=True,
440442
)
441443

442444

@@ -471,6 +473,7 @@ def test_data_migration_service_client_client_options_scopes(
471473
client_cert_source_for_mtls=None,
472474
quota_project_id=None,
473475
client_info=transports.base.DEFAULT_CLIENT_INFO,
476+
always_use_jwt_access=True,
474477
)
475478

476479

@@ -505,6 +508,7 @@ def test_data_migration_service_client_client_options_credentials_file(
505508
client_cert_source_for_mtls=None,
506509
quota_project_id=None,
507510
client_info=transports.base.DEFAULT_CLIENT_INFO,
511+
always_use_jwt_access=True,
508512
)
509513

510514

@@ -524,6 +528,7 @@ def test_data_migration_service_client_client_options_from_dict():
524528
client_cert_source_for_mtls=None,
525529
quota_project_id=None,
526530
client_info=transports.base.DEFAULT_CLIENT_INFO,
531+
always_use_jwt_access=True,
527532
)
528533

529534

0 commit comments

Comments
 (0)