Skip to content

Commit ae2d90c

Browse files
committed
Removing _connection_class from base client.
1 parent 7f7dc42 commit ae2d90c

3 files changed

Lines changed: 33 additions & 60 deletions

File tree

core/google/cloud/client.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import six
2020

2121
from google.cloud._helpers import _determine_default_project
22-
from google.cloud._http import Connection
2322
from google.cloud.credentials import get_credentials
2423

2524

@@ -72,33 +71,32 @@ def from_service_account_json(cls, json_credentials_path, *args, **kwargs):
7271
class Client(_ClientFactoryMixin):
7372
"""Client to bundle configuration needed for API requests.
7473
75-
Assumes that the associated ``_connection_class`` only accepts
76-
``http`` and ``credentials`` in its constructor.
74+
Stores ``credentials`` and ``http`` object so that subclasses
75+
can pass them along to a connection class.
7776
78-
:type credentials: :class:`google.auth.credentials.Credentials` or
79-
:class:`NoneType`
80-
:param credentials: The OAuth2 Credentials to use for the connection
81-
owned by this client. If not passed (and if no ``http``
82-
object is passed), falls back to the default inferred
83-
from the environment.
77+
:type credentials: :class:`~google.auth.credentials.Credentials`
78+
:param credentials: (Optional) The OAuth2 Credentials to use for this
79+
client. If not passed (and if no ``http`` object is
80+
passed), falls back to the default inferred from the
81+
environment.
8482
85-
:type http: :class:`httplib2.Http` or class that defines ``request()``.
86-
:param http: An optional HTTP object to make requests. If not passed, an
83+
:type http: :class:`~httplib2.Http`
84+
:param http: (Optional) HTTP object to make requests. Can be any object
85+
that defines ``request()`` with the same interface as
86+
:meth:`~httplib2.Http.request`. If not passed, an
8787
``http`` object is created that is bound to the
8888
``credentials`` for the current object.
8989
"""
9090

91-
_connection_class = Connection
92-
9391
def __init__(self, credentials=None, http=None):
9492
if (credentials is not None and
9593
not isinstance(
9694
credentials, google.auth.credentials.Credentials)):
9795
raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
9896
if credentials is None and http is None:
9997
credentials = get_credentials()
100-
self._connection = self._connection_class(
101-
credentials=credentials, http=http)
98+
self._credentials = credentials
99+
self._http = http
102100

103101

104102
class _ClientProjectMixin(object):
@@ -142,15 +140,16 @@ class JSONClient(Client, _ClientProjectMixin):
142140
passed falls back to the default inferred from the
143141
environment.
144142
145-
:type credentials: :class:`google.auth.credentials.Credentials` or
146-
:class:`NoneType`
147-
:param credentials: The OAuth2 Credentials to use for the connection
148-
owned by this client. If not passed (and if no ``http``
149-
object is passed), falls back to the default inferred
150-
from the environment.
143+
:type credentials: :class:`~google.auth.credentials.Credentials`
144+
:param credentials: (Optional) The OAuth2 Credentials to use for this
145+
client. If not passed (and if no ``http`` object is
146+
passed), falls back to the default inferred from the
147+
environment.
151148
152-
:type http: :class:`httplib2.Http` or class that defines ``request()``.
153-
:param http: An optional HTTP object to make requests. If not passed, an
149+
:type http: :class:`~httplib2.Http`
150+
:param http: (Optional) HTTP object to make requests. Can be any object
151+
that defines ``request()`` with the same interface as
152+
:meth:`~httplib2.Http.request`. If not passed, an
154153
``http`` object is created that is bound to the
155154
``credentials`` for the current object.
156155

core/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ envlist =
44

55
[testing]
66
deps =
7-
grpcio >= 1.0.2rc0
7+
grpcio >= 1.0.2
88
mock
99
pytest
1010
covercmd =

core/unit_tests/test_client.py

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ def test_virtual(self):
3636

3737
class TestClient(unittest.TestCase):
3838

39-
def setUp(self):
40-
KLASS = self._get_target_class()
41-
self.original_cnxn_class = KLASS._connection_class
42-
KLASS._connection_class = _MockConnection
43-
44-
def tearDown(self):
45-
KLASS = self._get_target_class()
46-
KLASS._connection_class = self.original_cnxn_class
47-
4839
@staticmethod
4940
def _get_target_class():
5041
from google.cloud.client import Client
@@ -67,18 +58,17 @@ def mock_get_credentials():
6758
with _Monkey(client, get_credentials=mock_get_credentials):
6859
client_obj = self._make_one()
6960

70-
self.assertIsInstance(client_obj._connection, _MockConnection)
71-
self.assertIs(client_obj._connection.credentials, CREDENTIALS)
61+
self.assertIs(client_obj._credentials, CREDENTIALS)
62+
self.assertIsNone(client_obj._http)
7263
self.assertEqual(FUNC_CALLS, ['get_credentials'])
7364

7465
def test_ctor_explicit(self):
7566
CREDENTIALS = _make_credentials()
7667
HTTP = object()
7768
client_obj = self._make_one(credentials=CREDENTIALS, http=HTTP)
7869

79-
self.assertIsInstance(client_obj._connection, _MockConnection)
80-
self.assertIs(client_obj._connection.credentials, CREDENTIALS)
81-
self.assertIs(client_obj._connection.http, HTTP)
70+
self.assertIs(client_obj._credentials, CREDENTIALS)
71+
self.assertIs(client_obj._http, HTTP)
8272

8373
def test_ctor_bad_credentials(self):
8474
CREDENTIALS = object()
@@ -99,7 +89,8 @@ def test_from_service_account_json(self):
9989
mock.sentinel.filename)
10090

10191
self.assertIs(
102-
client_obj._connection.credentials, constructor.return_value)
92+
client_obj._credentials, constructor.return_value)
93+
self.assertIsNone(client_obj._http)
10394
constructor.assert_called_once_with(mock.sentinel.filename)
10495

10596
def test_from_service_account_json_bad_args(self):
@@ -112,15 +103,6 @@ def test_from_service_account_json_bad_args(self):
112103

113104
class TestJSONClient(unittest.TestCase):
114105

115-
def setUp(self):
116-
KLASS = self._get_target_class()
117-
self.original_cnxn_class = KLASS._connection_class
118-
KLASS._connection_class = _MockConnection
119-
120-
def tearDown(self):
121-
KLASS = self._get_target_class()
122-
KLASS._connection_class = self.original_cnxn_class
123-
124106
@staticmethod
125107
def _get_target_class():
126108
from google.cloud.client import JSONClient
@@ -150,8 +132,8 @@ def mock_get_credentials():
150132
client_obj = self._make_one()
151133

152134
self.assertEqual(client_obj.project, PROJECT)
153-
self.assertIsInstance(client_obj._connection, _MockConnection)
154-
self.assertIs(client_obj._connection.credentials, CREDENTIALS)
135+
self.assertIs(client_obj._credentials, CREDENTIALS)
136+
self.assertIsNone(client_obj._http)
155137
self.assertEqual(
156138
FUNC_CALLS,
157139
[(None, '_determine_default_project'), 'get_credentials'])
@@ -191,9 +173,8 @@ def _explicit_ctor_helper(self, project):
191173
self.assertEqual(client_obj.project, project.decode('utf-8'))
192174
else:
193175
self.assertEqual(client_obj.project, project)
194-
self.assertIsInstance(client_obj._connection, _MockConnection)
195-
self.assertIs(client_obj._connection.credentials, CREDENTIALS)
196-
self.assertIs(client_obj._connection.http, HTTP)
176+
self.assertIs(client_obj._credentials, CREDENTIALS)
177+
self.assertIs(client_obj._http, HTTP)
197178

198179
def test_ctor_explicit_bytes(self):
199180
PROJECT = b'PROJECT'
@@ -202,10 +183,3 @@ def test_ctor_explicit_bytes(self):
202183
def test_ctor_explicit_unicode(self):
203184
PROJECT = u'PROJECT'
204185
self._explicit_ctor_helper(PROJECT)
205-
206-
207-
class _MockConnection(object):
208-
209-
def __init__(self, credentials=None, http=None):
210-
self.credentials = credentials
211-
self.http = http

0 commit comments

Comments
 (0)