Skip to content

Commit 35a0a1e

Browse files
authored
Merge pull request #2703 from dhermes/connection-non-public
Making base connection module non-public and making connection attribute non-public
2 parents fb6e5c8 + f078e17 commit 35a0a1e

8 files changed

Lines changed: 24 additions & 22 deletions

File tree

File renamed without changes.

packages/google-cloud-core/google/cloud/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import six
1919

2020
from google.cloud._helpers import _determine_default_project
21-
from google.cloud.connection import Connection
21+
from google.cloud._http import Connection
2222
from google.cloud.credentials import get_credentials
2323

2424

@@ -120,7 +120,7 @@ class Client(_ClientFactoryMixin):
120120
def __init__(self, credentials=None, http=None):
121121
if credentials is None and http is None:
122122
credentials = get_credentials()
123-
self.connection = self._connection_class(
123+
self._connection = self._connection_class(
124124
credentials=credentials, http=http)
125125

126126

packages/google-cloud-core/google/cloud/iterator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,12 @@ def _get_next_page_response(self):
382382
"""
383383
params = self._get_query_params()
384384
if self._HTTP_METHOD == 'GET':
385-
return self.client.connection.api_request(
385+
return self.client._connection.api_request(
386386
method=self._HTTP_METHOD,
387387
path=self.path,
388388
query_params=params)
389389
elif self._HTTP_METHOD == 'POST':
390-
return self.client.connection.api_request(
390+
return self.client._connection.api_request(
391391
method=self._HTTP_METHOD,
392392
path=self.path,
393393
data=params)

packages/google-cloud-core/google/cloud/operation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Operation(object):
104104
:type client: :class:`~google.cloud.client.Client`
105105
:param client: The client used to poll for the status of the operation.
106106
If the operation was created via JSON/HTTP, the client
107-
must own a :class:`~google.cloud.connection.Connection`
107+
must own a :class:`~google.cloud._http.Connection`
108108
to send polling requests. If created via protobuf, the
109109
client must have a gRPC stub in the ``_operations_stub``
110110
attribute.
@@ -218,7 +218,7 @@ def _get_operation_http(self):
218218
:returns: The latest status of the current operation.
219219
"""
220220
path = 'operations/%s' % (self.name,)
221-
api_response = self.client.connection.api_request(
221+
api_response = self.client._connection.api_request(
222222
method='GET', path=path)
223223
return json_format.ParseDict(
224224
api_response, operations_pb2.Operation())

packages/google-cloud-core/unit_tests/test_connection.py renamed to packages/google-cloud-core/unit_tests/test__http.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class TestConnection(unittest.TestCase):
1919

2020
@staticmethod
2121
def _get_target_class():
22-
from google.cloud.connection import Connection
22+
from google.cloud._http import Connection
23+
2324
return Connection
2425

2526
def _make_one(self, *args, **kw):
@@ -111,7 +112,8 @@ class TestJSONConnection(unittest.TestCase):
111112

112113
@staticmethod
113114
def _get_target_class():
114-
from google.cloud.connection import JSONConnection
115+
from google.cloud._http import JSONConnection
116+
115117
return JSONConnection
116118

117119
def _make_one(self, *args, **kw):

packages/google-cloud-core/unit_tests/test_client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ def mock_get_credentials():
6060
with _Monkey(client, get_credentials=mock_get_credentials):
6161
client_obj = self._make_one()
6262

63-
self.assertIsInstance(client_obj.connection, _MockConnection)
64-
self.assertIs(client_obj.connection.credentials, CREDENTIALS)
63+
self.assertIsInstance(client_obj._connection, _MockConnection)
64+
self.assertIs(client_obj._connection.credentials, CREDENTIALS)
6565
self.assertEqual(FUNC_CALLS, ['get_credentials'])
6666

6767
def test_ctor_explicit(self):
6868
CREDENTIALS = object()
6969
HTTP = object()
7070
client_obj = self._make_one(credentials=CREDENTIALS, http=HTTP)
7171

72-
self.assertIsInstance(client_obj.connection, _MockConnection)
73-
self.assertIs(client_obj.connection.credentials, CREDENTIALS)
74-
self.assertIs(client_obj.connection.http, HTTP)
72+
self.assertIsInstance(client_obj._connection, _MockConnection)
73+
self.assertIs(client_obj._connection.credentials, CREDENTIALS)
74+
self.assertIs(client_obj._connection.http, HTTP)
7575

7676
def test_from_service_account_json(self):
7777
from google.cloud._testing import _Monkey
@@ -83,7 +83,7 @@ def test_from_service_account_json(self):
8383
with _Monkey(client, ServiceAccountCredentials=mock_creds):
8484
client_obj = KLASS.from_service_account_json(MOCK_FILENAME)
8585

86-
self.assertIs(client_obj.connection.credentials, mock_creds._result)
86+
self.assertIs(client_obj._connection.credentials, mock_creds._result)
8787
self.assertEqual(mock_creds.json_called, [MOCK_FILENAME])
8888

8989
def test_from_service_account_json_fail(self):
@@ -104,7 +104,7 @@ def test_from_service_account_p12(self):
104104
client_obj = KLASS.from_service_account_p12(CLIENT_EMAIL,
105105
MOCK_FILENAME)
106106

107-
self.assertIs(client_obj.connection.credentials, mock_creds._result)
107+
self.assertIs(client_obj._connection.credentials, mock_creds._result)
108108
self.assertEqual(mock_creds.p12_called,
109109
[(CLIENT_EMAIL, MOCK_FILENAME)])
110110

@@ -155,8 +155,8 @@ def mock_get_credentials():
155155
client_obj = self._make_one()
156156

157157
self.assertEqual(client_obj.project, PROJECT)
158-
self.assertIsInstance(client_obj.connection, _MockConnection)
159-
self.assertIs(client_obj.connection.credentials, CREDENTIALS)
158+
self.assertIsInstance(client_obj._connection, _MockConnection)
159+
self.assertIs(client_obj._connection.credentials, CREDENTIALS)
160160
self.assertEqual(
161161
FUNC_CALLS,
162162
[(None, '_determine_default_project'), 'get_credentials'])
@@ -196,9 +196,9 @@ def _explicit_ctor_helper(self, project):
196196
self.assertEqual(client_obj.project, project.decode('utf-8'))
197197
else:
198198
self.assertEqual(client_obj.project, project)
199-
self.assertIsInstance(client_obj.connection, _MockConnection)
200-
self.assertIs(client_obj.connection.credentials, CREDENTIALS)
201-
self.assertIs(client_obj.connection.http, HTTP)
199+
self.assertIsInstance(client_obj._connection, _MockConnection)
200+
self.assertIs(client_obj._connection.credentials, CREDENTIALS)
201+
self.assertIs(client_obj._connection.http, HTTP)
202202

203203
def test_ctor_explicit_bytes(self):
204204
PROJECT = b'PROJECT'

packages/google-cloud-core/unit_tests/test_iterator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def api_request(self, **kw):
591591
class _Client(object):
592592

593593
def __init__(self, connection):
594-
self.connection = connection
594+
self._connection = connection
595595

596596

597597
class SimpleIter(object):

packages/google-cloud-core/unit_tests/test_operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,4 @@ class _Client(object):
419419

420420
def __init__(self, connection=None):
421421
self._operations_stub = _OperationsStub()
422-
self.connection = connection
422+
self._connection = connection

0 commit comments

Comments
 (0)