Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: add client_options to base class (#132)
  • Loading branch information
HemangChothani committed Aug 14, 2020
1 parent 91c32f7 commit 6851bb8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
5 changes: 4 additions & 1 deletion google/cloud/spanner_v1/client.py
Expand Up @@ -192,7 +192,10 @@ def __init__(
# will have no impact since the _http() @property only lazily
# creates a working HTTP object.
super(Client, self).__init__(
project=project, credentials=credentials, _http=None
project=project,
credentials=credentials,
client_options=client_options,
_http=None,
)
self._client_info = client_info

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -30,7 +30,7 @@
release_status = "Development Status :: 5 - Production/Stable"
dependencies = [
"google-api-core[grpc, grpcgcp] >= 1.14.0, < 2.0.0dev",
"google-cloud-core >= 1.0.3, < 2.0dev",
"google-cloud-core >= 1.4.1, < 2.0dev",
"grpc-google-iam-v1 >= 0.12.3, < 0.13dev",
]
extras = {}
Expand Down
22 changes: 12 additions & 10 deletions tests/unit/test_client.py
Expand Up @@ -223,12 +223,13 @@ def test_constructor_custom_query_options_env_config(self, mock_ver):
@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
def test_instance_admin_api(self, mock_em):
from google.cloud.spanner_v1.client import SPANNER_ADMIN_SCOPE
from google.api_core.client_options import ClientOptions

mock_em.return_value = None

credentials = _make_credentials()
client_info = mock.Mock()
client_options = mock.Mock()
client_options = ClientOptions(quota_project_id="QUOTA-PROJECT")
client = self._make_one(
project=self.PROJECT,
credentials=credentials,
Expand All @@ -248,19 +249,19 @@ def test_instance_admin_api(self, mock_em):
self.assertIs(again, api)

instance_admin_client.assert_called_once_with(
credentials=credentials.with_scopes.return_value,
client_info=client_info,
client_options=client_options,
credentials=mock.ANY, client_info=client_info, client_options=client_options
)

credentials.with_scopes.assert_called_once_with(expected_scopes)

@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
def test_instance_admin_api_emulator_env(self, mock_em):
from google.api_core.client_options import ClientOptions

mock_em.return_value = "emulator.host"
credentials = _make_credentials()
client_info = mock.Mock()
client_options = mock.Mock()
client_options = ClientOptions(api_endpoint="endpoint")
client = self._make_one(
project=self.PROJECT,
credentials=credentials,
Expand Down Expand Up @@ -321,11 +322,12 @@ def test_instance_admin_api_emulator_code(self):
@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
def test_database_admin_api(self, mock_em):
from google.cloud.spanner_v1.client import SPANNER_ADMIN_SCOPE
from google.api_core.client_options import ClientOptions

mock_em.return_value = None
credentials = _make_credentials()
client_info = mock.Mock()
client_options = mock.Mock()
client_options = ClientOptions(quota_project_id="QUOTA-PROJECT")
client = self._make_one(
project=self.PROJECT,
credentials=credentials,
Expand All @@ -345,19 +347,19 @@ def test_database_admin_api(self, mock_em):
self.assertIs(again, api)

database_admin_client.assert_called_once_with(
credentials=credentials.with_scopes.return_value,
client_info=client_info,
client_options=client_options,
credentials=mock.ANY, client_info=client_info, client_options=client_options
)

credentials.with_scopes.assert_called_once_with(expected_scopes)

@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
def test_database_admin_api_emulator_env(self, mock_em):
from google.api_core.client_options import ClientOptions

mock_em.return_value = "host:port"
credentials = _make_credentials()
client_info = mock.Mock()
client_options = mock.Mock()
client_options = ClientOptions(api_endpoint="endpoint")
client = self._make_one(
project=self.PROJECT,
credentials=credentials,
Expand Down

0 comments on commit 6851bb8

Please sign in to comment.