Repository: googleapis/google-cloud-python

Issue:
AutoML: pass credentials from Table client to underlying client.
#### Problem

It seems that TablesClient doesn't correctly pass the credentials down to underlying clients.

Since I have neither a default credential nor `GOOGLE_APPLICATION_CREDENTIALS` set on my machine, I end up getting `DefaultCredentialsError`.

#### Environment details

os: macOS 10.14.2
python version: 3.7
google-cloud-automl==0.7.0

#### Code example

```python
from google.cloud import automl_v1beta1
from google.oauth2 import service_account


credentials = service_account.Credentials.from_service_account_file('sa.json')
client = automl_v1beta1.TablesClient(
    credentials=credentials,
    project=credentials.project_id,
    region='us-central1',
)
```

#### Stacktrace

```
/Users/account/project/.venv/bin/python /Users/account/project/prediction_starter/main.py
Traceback (most recent call last):
  File "/Users/account/project/prediction_starter/main.py", line 9, in <module>
    region='us-central1',
  File "/Users/account/project/.venv/lib/python3.7/site-packages/google/cloud/automl_v1beta1/tables/tables_client.py", line 110, in __init__
    client_info=client_info_, **kwargs
  File "/Users/account/project/.venv/lib/python3.7/site-packages/google/cloud/automl_v1beta1/gapic/auto_ml_client.py", line 265, in __init__
    address=api_endpoint, channel=channel, credentials=credentials
  File "/Users/account/project/.venv/lib/python3.7/site-packages/google/cloud/automl_v1beta1/gapic/transports/auto_ml_grpc_transport.py", line 67, in __init__
    "grpc.max_receive_message_length": -1,
  File "/Users/account/project/.venv/lib/python3.7/site-packages/google/cloud/automl_v1beta1/gapic/transports/auto_ml_grpc_transport.py", line 104, in create_channel
    address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs
  File "/Users/account/project/.venv/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 177, in create_channel
    credentials, _ = google.auth.default(scopes=scopes)
  File "/Users/account/project/.venv/lib/python3.7/site-packages/google/auth/_default.py", line 317, in default
    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
```

#### Expected Behavior

Successfully instantiate a `TablesClient` instance.


Discussion:

Resolving patch:
diff --git a/automl/google/cloud/automl_v1beta1/tables/tables_client.py b/automl/google/cloud/automl_v1beta1/tables/tables_client.py
--- a/automl/google/cloud/automl_v1beta1/tables/tables_client.py
+++ b/automl/google/cloud/automl_v1beta1/tables/tables_client.py
@@ -107,14 +107,14 @@ def __init__(
 
         if client is None:
             self.auto_ml_client = gapic.auto_ml_client.AutoMlClient(
-                client_info=client_info_, **kwargs
+                credentials=credentials, client_info=client_info_, **kwargs
             )
         else:
             self.auto_ml_client = client
 
         if prediction_client is None:
             self.prediction_client = gapic.prediction_service_client.PredictionServiceClient(
-                client_info=client_info_, **kwargs
+                credentials=credentials, client_info=client_info_, **kwargs
             )
         else:
             self.prediction_client = prediction_client


Test patch:
diff --git a/automl/tests/unit/gapic/v1beta1/test_tables_client_v1beta1.py b/automl/tests/unit/gapic/v1beta1/test_tables_client_v1beta1.py
--- a/automl/tests/unit/gapic/v1beta1/test_tables_client_v1beta1.py
+++ b/automl/tests/unit/gapic/v1beta1/test_tables_client_v1beta1.py
@@ -1379,3 +1379,25 @@ def test_batch_predict_no_model(self):
             )
         client.auto_ml_client.list_models.assert_not_called()
         client.prediction_client.batch_predict.assert_not_called()
+
+    def test_auto_ml_client_credentials(self):
+        credentials_mock = mock.Mock()
+        patch_auto_ml_client = mock.patch(
+            "google.cloud.automl_v1beta1.gapic.auto_ml_client.AutoMlClient"
+        )
+        with patch_auto_ml_client as MockAutoMlClient:
+            client = automl_v1beta1.TablesClient(credentials=credentials_mock)
+        _, auto_ml_client_kwargs = MockAutoMlClient.call_args
+        assert "credentials" in auto_ml_client_kwargs
+        assert auto_ml_client_kwargs["credentials"] == credentials_mock
+
+    def test_prediction_client_credentials(self):
+        credentials_mock = mock.Mock()
+        patch_prediction_client = mock.patch(
+            "google.cloud.automl_v1beta1.gapic.prediction_service_client.PredictionServiceClient"
+        )
+        with patch_prediction_client as MockPredictionClient:
+            client = automl_v1beta1.TablesClient(credentials=credentials_mock)
+        _, prediction_client_kwargs = MockPredictionClient.call_args
+        assert "credentials" in prediction_client_kwargs
+        assert prediction_client_kwargs["credentials"] == credentials_mock