Skip to content

Commit 60676df

Browse files
committed
Pass credentials to underlying clients in TableClient
In automl_v1beta1.TablesClient.__init__(), the credentials are not given to AutoMlClient and PredictionServiceClient, causing inconsistency between the credentials that was passed and the credentials that was actually used for API calls. This commit ensures that credentials are passed, and add two unittests to catch the behavior.
1 parent 02f2dc2 commit 60676df

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

automl/google/cloud/automl_v1beta1/tables/tables_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ def __init__(
107107

108108
if client is None:
109109
self.auto_ml_client = gapic.auto_ml_client.AutoMlClient(
110-
client_info=client_info_, **kwargs
110+
credentials=credentials, client_info=client_info_, **kwargs
111111
)
112112
else:
113113
self.auto_ml_client = client
114114

115115
if prediction_client is None:
116116
self.prediction_client = gapic.prediction_service_client.PredictionServiceClient(
117-
client_info=client_info_, **kwargs
117+
credentials=credentials, client_info=client_info_, **kwargs
118118
)
119119
else:
120120
self.prediction_client = prediction_client

automl/tests/unit/gapic/v1beta1/test_tables_client_v1beta1.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,3 +1379,25 @@ def test_batch_predict_no_model(self):
13791379
)
13801380
client.auto_ml_client.list_models.assert_not_called()
13811381
client.prediction_client.batch_predict.assert_not_called()
1382+
1383+
def test_auto_ml_client_credentials(self):
1384+
credentials_mock = mock.Mock()
1385+
patch_auto_ml_client = mock.patch(
1386+
"google.cloud.automl_v1beta1.gapic.auto_ml_client.AutoMlClient"
1387+
)
1388+
with patch_auto_ml_client as MockAutoMlClient:
1389+
client = automl_v1beta1.TablesClient(credentials=credentials_mock)
1390+
_, auto_ml_client_kwargs = MockAutoMlClient.call_args
1391+
assert "credentials" in auto_ml_client_kwargs
1392+
assert auto_ml_client_kwargs["credentials"] == credentials_mock
1393+
1394+
def test_prediction_client_credentials(self):
1395+
credentials_mock = mock.Mock()
1396+
patch_prediction_client = mock.patch(
1397+
"google.cloud.automl_v1beta1.gapic.prediction_service_client.PredictionServiceClient"
1398+
)
1399+
with patch_prediction_client as MockPredictionClient:
1400+
client = automl_v1beta1.TablesClient(credentials=credentials_mock)
1401+
_, prediction_client_kwargs = MockPredictionClient.call_args
1402+
assert "credentials" in prediction_client_kwargs
1403+
assert prediction_client_kwargs["credentials"] == credentials_mock

0 commit comments

Comments
 (0)