Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(trace): add client_options to constructor (#9154)
  • Loading branch information
busunkim96 committed Oct 22, 2019
1 parent 376b7ad commit a5b4f7a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 10 deletions.
4 changes: 3 additions & 1 deletion google/cloud/trace/_gapic.py
Expand Up @@ -314,6 +314,8 @@ def make_trace_api(client):
proper configurations.
"""
generated = trace_service_client.TraceServiceClient(
credentials=client._credentials, client_info=client._client_info
credentials=client._credentials,
client_info=client._client_info,
client_options=client._client_options,
)
return _TraceAPI(generated, client)
12 changes: 11 additions & 1 deletion google/cloud/trace/client.py
Expand Up @@ -39,6 +39,9 @@ class Client(ClientWithProject):
requests. If ``None``, then default info will be used. Generally,
you only need to set this if you're developing your own library
or partner tool.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""

SCOPE = (
Expand All @@ -49,9 +52,16 @@ class Client(ClientWithProject):

_trace_api = None

def __init__(self, project=None, credentials=None, client_info=_CLIENT_INFO):
def __init__(
self,
project=None,
credentials=None,
client_info=_CLIENT_INFO,
client_options=None,
):
super(Client, self).__init__(project=project, credentials=credentials)
self._client_info = client_info
self._client_options = client_options

@property
def trace_api(self):
Expand Down
4 changes: 3 additions & 1 deletion google/cloud/trace/v1/_gapic.py
Expand Up @@ -178,7 +178,9 @@ def make_trace_api(client):
proper configurations.
"""
generated = trace_service_client.TraceServiceClient(
credentials=client._credentials, client_info=client._client_info
credentials=client._credentials,
client_info=client._client_info,
client_options=client._client_options,
)
return _TraceAPI(generated, client)

Expand Down
12 changes: 11 additions & 1 deletion google/cloud/trace/v1/client.py
Expand Up @@ -41,6 +41,9 @@ class Client(ClientWithProject):
requests. If ``None``, then default info will be used. Generally,
you only need to set this if you're developing your own library
or partner tool.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""

SCOPE = (
Expand All @@ -51,9 +54,16 @@ class Client(ClientWithProject):

_trace_api = None

def __init__(self, project=None, credentials=None, client_info=_CLIENT_INFO):
def __init__(
self,
project=None,
credentials=None,
client_info=_CLIENT_INFO,
client_options=None,
):
super(Client, self).__init__(project=project, credentials=credentials)
self._client_info = client_info
self._client_options = client_options

@property
def trace_api(self):
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/v1/test__gapic_v1.py
Expand Up @@ -227,7 +227,7 @@ def _call_fut(self, client):
def test_it(self):
from google.cloud.trace.v1._gapic import _TraceAPI

client = mock.Mock(spec=["_credentials", "_client_info"])
client = mock.Mock(spec=["_credentials", "_client_info", "_client_options"])

patch_api = mock.patch(
"google.cloud.trace.v1._gapic.trace_service_client.TraceServiceClient"
Expand All @@ -237,7 +237,9 @@ def test_it(self):
trace_api = self._call_fut(client)

patched.assert_called_once_with(
credentials=client._credentials, client_info=client._client_info
credentials=client._credentials,
client_info=client._client_info,
client_options=client._client_options,
)

self.assertIsInstance(trace_api, _TraceAPI)
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/v1/test_client_v1.py
Expand Up @@ -47,11 +47,16 @@ def test_constructor_defaults(self):
def test_constructor_explicit(self):
credentials = _make_credentials()
client_info = mock.Mock()
client_options = mock.Mock()
client = self._make_one(
project=self.project, credentials=credentials, client_info=client_info
project=self.project,
credentials=credentials,
client_info=client_info,
client_options=client_options,
)
self.assertEqual(client.project, self.project)
self.assertIs(client._client_info, client_info)
self.assertIs(client._client_options, client_options)

def test_trace_api(self):
clients = []
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/v2/test__gapic_v2.py
Expand Up @@ -272,7 +272,7 @@ def _call_fut(self, client):
def test_it(self):
from google.cloud.trace._gapic import _TraceAPI

client = mock.Mock(spec=["_credentials", "_client_info"])
client = mock.Mock(spec=["_credentials", "_client_info", "_client_options"])

patch_api = mock.patch(
"google.cloud.trace._gapic.trace_service_client.TraceServiceClient"
Expand All @@ -282,7 +282,9 @@ def test_it(self):
trace_api = self._call_fut(client)

patched.assert_called_once_with(
credentials=client._credentials, client_info=client._client_info
credentials=client._credentials,
client_info=client._client_info,
client_options=client._client_options,
)

self.assertIsInstance(trace_api, _TraceAPI)
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/v2/test_client_v2.py
Expand Up @@ -47,10 +47,15 @@ def test_constructor_defaults(self):
def test_constructor_explicit(self):
credentials = _make_credentials()
client_info = mock.Mock()
client_options = mock.Mock()
client = self._make_one(
project=self.project, credentials=credentials, client_info=client_info
project=self.project,
credentials=credentials,
client_info=client_info,
client_options=client_options,
)
self.assertEqual(client.project, self.project)
self.assertIs(client._client_options, client_options)

def test_trace_api(self):
clients = []
Expand Down

0 comments on commit a5b4f7a

Please sign in to comment.