Skip to content

Commit 6851bb8

Browse files
feat: add client_options to base class (#132)
1 parent 91c32f7 commit 6851bb8

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

google/cloud/spanner_v1/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ def __init__(
192192
# will have no impact since the _http() @property only lazily
193193
# creates a working HTTP object.
194194
super(Client, self).__init__(
195-
project=project, credentials=credentials, _http=None
195+
project=project,
196+
credentials=credentials,
197+
client_options=client_options,
198+
_http=None,
196199
)
197200
self._client_info = client_info
198201

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
release_status = "Development Status :: 5 - Production/Stable"
3131
dependencies = [
3232
"google-api-core[grpc, grpcgcp] >= 1.14.0, < 2.0.0dev",
33-
"google-cloud-core >= 1.0.3, < 2.0dev",
33+
"google-cloud-core >= 1.4.1, < 2.0dev",
3434
"grpc-google-iam-v1 >= 0.12.3, < 0.13dev",
3535
]
3636
extras = {}

tests/unit/test_client.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ def test_constructor_custom_query_options_env_config(self, mock_ver):
223223
@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
224224
def test_instance_admin_api(self, mock_em):
225225
from google.cloud.spanner_v1.client import SPANNER_ADMIN_SCOPE
226+
from google.api_core.client_options import ClientOptions
226227

227228
mock_em.return_value = None
228229

229230
credentials = _make_credentials()
230231
client_info = mock.Mock()
231-
client_options = mock.Mock()
232+
client_options = ClientOptions(quota_project_id="QUOTA-PROJECT")
232233
client = self._make_one(
233234
project=self.PROJECT,
234235
credentials=credentials,
@@ -248,19 +249,19 @@ def test_instance_admin_api(self, mock_em):
248249
self.assertIs(again, api)
249250

250251
instance_admin_client.assert_called_once_with(
251-
credentials=credentials.with_scopes.return_value,
252-
client_info=client_info,
253-
client_options=client_options,
252+
credentials=mock.ANY, client_info=client_info, client_options=client_options
254253
)
255254

256255
credentials.with_scopes.assert_called_once_with(expected_scopes)
257256

258257
@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
259258
def test_instance_admin_api_emulator_env(self, mock_em):
259+
from google.api_core.client_options import ClientOptions
260+
260261
mock_em.return_value = "emulator.host"
261262
credentials = _make_credentials()
262263
client_info = mock.Mock()
263-
client_options = mock.Mock()
264+
client_options = ClientOptions(api_endpoint="endpoint")
264265
client = self._make_one(
265266
project=self.PROJECT,
266267
credentials=credentials,
@@ -321,11 +322,12 @@ def test_instance_admin_api_emulator_code(self):
321322
@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
322323
def test_database_admin_api(self, mock_em):
323324
from google.cloud.spanner_v1.client import SPANNER_ADMIN_SCOPE
325+
from google.api_core.client_options import ClientOptions
324326

325327
mock_em.return_value = None
326328
credentials = _make_credentials()
327329
client_info = mock.Mock()
328-
client_options = mock.Mock()
330+
client_options = ClientOptions(quota_project_id="QUOTA-PROJECT")
329331
client = self._make_one(
330332
project=self.PROJECT,
331333
credentials=credentials,
@@ -345,19 +347,19 @@ def test_database_admin_api(self, mock_em):
345347
self.assertIs(again, api)
346348

347349
database_admin_client.assert_called_once_with(
348-
credentials=credentials.with_scopes.return_value,
349-
client_info=client_info,
350-
client_options=client_options,
350+
credentials=mock.ANY, client_info=client_info, client_options=client_options
351351
)
352352

353353
credentials.with_scopes.assert_called_once_with(expected_scopes)
354354

355355
@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
356356
def test_database_admin_api_emulator_env(self, mock_em):
357+
from google.api_core.client_options import ClientOptions
358+
357359
mock_em.return_value = "host:port"
358360
credentials = _make_credentials()
359361
client_info = mock.Mock()
360-
client_options = mock.Mock()
362+
client_options = ClientOptions(api_endpoint="endpoint")
361363
client = self._make_one(
362364
project=self.PROJECT,
363365
credentials=credentials,

0 commit comments

Comments
 (0)