Skip to content
Permalink
Browse files
feat: add client_options to base class (#132)
  • Loading branch information
HemangChothani committed Aug 14, 2020
1 parent 91c32f7 commit 6851bb86c21ca489a1982bda0d6e97cbccde341c
Showing with 17 additions and 12 deletions.
  1. +4 −1 google/cloud/spanner_v1/client.py
  2. +1 −1 setup.py
  3. +12 −10 tests/unit/test_client.py
@@ -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

@@ -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 = {}
@@ -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,
@@ -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,
@@ -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,
@@ -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,

0 comments on commit 6851bb8

Please sign in to comment.