Skip to content

Commit bd981b1

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 ef0ae73 + 8d7e76c commit bd981b1

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

packages/google-cloud-resource-manager/google/cloud/resource_manager/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"""Create / interact with Google Cloud Resource Manager connections."""
1616

1717

18-
from google.cloud import connection as base_connection
18+
from google.cloud import _http
1919

2020

21-
class Connection(base_connection.JSONConnection):
21+
class Connection(_http.JSONConnection):
2222
"""A connection to Google Cloud Resource Manager via the JSON REST API.
2323
2424
:type credentials: :class:`oauth2client.client.OAuth2Credentials`

packages/google-cloud-resource-manager/google/cloud/resource_manager/project.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def create(self, client=None):
131131
'name': self.name,
132132
'labels': self.labels,
133133
}
134-
resp = client.connection.api_request(method='POST', path='/projects',
135-
data=data)
134+
resp = client._connection.api_request(method='POST', path='/projects',
135+
data=data)
136136
self.set_properties_from_api_repr(resource=resp)
137137

138138
def reload(self, client=None):
@@ -161,7 +161,7 @@ def reload(self, client=None):
161161

162162
# We assume the project exists. If it doesn't it will raise a NotFound
163163
# exception.
164-
resp = client.connection.api_request(method='GET', path=self.path)
164+
resp = client._connection.api_request(method='GET', path=self.path)
165165
self.set_properties_from_api_repr(resource=resp)
166166

167167
def exists(self, client=None):
@@ -183,7 +183,7 @@ def exists(self, client=None):
183183
try:
184184
# Note that we have to request the entire resource as the API
185185
# doesn't provide a way tocheck for existence only.
186-
client.connection.api_request(method='GET', path=self.path)
186+
client._connection.api_request(method='GET', path=self.path)
187187
except NotFound:
188188
return False
189189
else:
@@ -203,8 +203,8 @@ def update(self, client=None):
203203
client = self._require_client(client)
204204

205205
data = {'name': self.name, 'labels': self.labels}
206-
resp = client.connection.api_request(method='PUT', path=self.path,
207-
data=data)
206+
resp = client._connection.api_request(
207+
method='PUT', path=self.path, data=data)
208208
self.set_properties_from_api_repr(resp)
209209

210210
def delete(self, client=None, reload_data=False):
@@ -232,7 +232,7 @@ def delete(self, client=None, reload_data=False):
232232
Default: :data:`False`.
233233
"""
234234
client = self._require_client(client)
235-
client.connection.api_request(method='DELETE', path=self.path)
235+
client._connection.api_request(method='DELETE', path=self.path)
236236

237237
# If the reload flag is set, reload the project.
238238
if reload_data:
@@ -262,8 +262,8 @@ def undelete(self, client=None, reload_data=False):
262262
Default: :data:`False`.
263263
"""
264264
client = self._require_client(client)
265-
client.connection.api_request(method='POST',
266-
path=self.path + ':undelete')
265+
client._connection.api_request(
266+
method='POST', path=self.path + ':undelete')
267267

268268
# If the reload flag is set, reload the project.
269269
if reload_data:

packages/google-cloud-resource-manager/unit_tests/test_client.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def test_constructor(self):
3131
http = object()
3232
credentials = _Credentials()
3333
client = self._make_one(credentials=credentials, http=http)
34-
self.assertIsInstance(client.connection, Connection)
35-
self.assertEqual(client.connection._credentials, credentials)
36-
self.assertEqual(client.connection._http, http)
34+
self.assertIsInstance(client._connection, Connection)
35+
self.assertEqual(client._connection._credentials, credentials)
36+
self.assertEqual(client._connection._http, http)
3737

3838
def test_new_project_factory(self):
3939
from google.cloud.resource_manager.project import Project
@@ -69,7 +69,7 @@ def test_fetch_project(self):
6969
credentials = _Credentials()
7070
client = self._make_one(credentials=credentials)
7171
# Patch the connection with one we can easily control.
72-
client.connection = _Connection(project_resource)
72+
client._connection = _Connection(project_resource)
7373

7474
project = client.fetch_project(project_id)
7575
self.assertIsInstance(project, Project)
@@ -84,7 +84,7 @@ def test_list_projects_return_type(self):
8484
credentials = _Credentials()
8585
client = self._make_one(credentials=credentials)
8686
# Patch the connection with one we can easily control.
87-
client.connection = _Connection({})
87+
client._connection = _Connection({})
8888

8989
results = client.list_projects()
9090
self.assertIsInstance(results, HTTPIterator)
@@ -106,7 +106,7 @@ def test_list_projects_no_paging(self):
106106
],
107107
}
108108
# Patch the connection with one we can easily control.
109-
client.connection = _Connection(PROJECTS_RESOURCE)
109+
client._connection = _Connection(PROJECTS_RESOURCE)
110110
# Make sure there will be no paging.
111111
self.assertFalse('nextPageToken' in PROJECTS_RESOURCE)
112112

@@ -147,8 +147,8 @@ def test_list_projects_with_paging(self):
147147
],
148148
}
149149
# Patch the connection with one we can easily control.
150-
client.connection = _Connection(FIRST_PROJECTS_RESOURCE,
151-
SECOND_PROJECTS_RESOURCE)
150+
client._connection = _Connection(FIRST_PROJECTS_RESOURCE,
151+
SECOND_PROJECTS_RESOURCE)
152152

153153
# Page size = 1 with two response means we'll have two requests.
154154
results = list(client.list_projects(page_size=1))
@@ -163,7 +163,7 @@ def test_list_projects_with_paging(self):
163163
self.assertEqual(project2.status, STATUS)
164164

165165
# Check that two requests were required since page_size=1.
166-
request1, request2 = client.connection._requested
166+
request1, request2 = client._connection._requested
167167
self.assertEqual(request1, {
168168
'path': '/projects',
169169
'method': 'GET',
@@ -197,7 +197,7 @@ def test_list_projects_with_filter(self):
197197
],
198198
}
199199
# Patch the connection with one we can easily control.
200-
client.connection = _Connection(PROJECTS_RESOURCE)
200+
client._connection = _Connection(PROJECTS_RESOURCE)
201201

202202
FILTER_PARAMS = {'id': 'project-id'}
203203
results = list(client.list_projects(filter_params=FILTER_PARAMS))
@@ -208,7 +208,7 @@ def test_list_projects_with_filter(self):
208208
self.assertEqual(project.status, STATUS)
209209

210210
# Check that the filter made it in the request.
211-
request, = client.connection._requested
211+
request, = client._connection._requested
212212
self.assertEqual(request, {
213213
'path': '/projects',
214214
'method': 'GET',

packages/google-cloud-resource-manager/unit_tests/test_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,4 @@ def api_request(self, **kw):
338338
class _Client(object):
339339

340340
def __init__(self, connection=None):
341-
self.connection = connection
341+
self._connection = connection

0 commit comments

Comments
 (0)