Skip to content

Commit 3bd6bd8

Browse files
committed
Merge pull request #194 from tseaver/140-connection.api_request-handle_path_none
Fix #140: make 'path' required for Connection.api_request.
2 parents d8b4e36 + ccd8a5e commit 3bd6bd8

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

gcloud/storage/connection.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def make_request(self, method, url, data=None, content_type=None,
162162
return self.http.request(uri=url, method=method, headers=headers,
163163
body=data)
164164

165-
def api_request(self, method, path=None, query_params=None,
165+
def api_request(self, method, path, query_params=None,
166166
data=None, content_type=None,
167167
api_base_url=None, api_version=None,
168168
expect_json=True):
@@ -174,32 +174,40 @@ def api_request(self, method, path=None, query_params=None,
174174
175175
:type method: string
176176
:param method: The HTTP method name (ie, ``GET``, ``POST``, etc).
177+
Required.
177178
178179
:type path: string
179180
:param path: The path to the resource (ie, ``'/b/bucket-name'``).
181+
Required.
180182
181183
:type query_params: dict
182184
:param query_params: A dictionary of keys and values to insert into
183-
the query string of the URL.
185+
the query string of the URL. Default is empty dict.
184186
185187
:type data: string
186-
:param data: The data to send as the body of the request.
188+
:param data: The data to send as the body of the request. Default is the
189+
empty string.
187190
188191
:type content_type: string
189-
:param content_type: The proper MIME type of the data provided.
192+
:param content_type: The proper MIME type of the data provided. Default
193+
is None.
190194
191195
:type api_base_url: string
192196
:param api_base_url: The base URL for the API endpoint.
193197
Typically you won't have to provide this.
198+
Default is the standard API base URL.
194199
195200
:type api_version: string
196201
:param api_version: The version of the API to call.
197202
Typically you shouldn't provide this and instead
198203
use the default for the library.
204+
Default is the latest API version supported by
205+
gcloud-python.
199206
200207
:type expect_json: bool
201208
:param expect_json: If True, this method will try to parse the response
202209
as JSON and raise an exception if that cannot be done.
210+
Default is True.
203211
204212
:raises: Exception if the response code is not 200 OK.
205213
"""

gcloud/storage/test_connection.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -203,38 +203,16 @@ def test_make_request_w_extra_headers(self):
203203

204204
def test_api_request_defaults(self):
205205
PROJECT = 'project'
206+
PATH = '/path/required'
206207
conn = self._makeOne(PROJECT)
207208
URI = '/'.join([conn.API_BASE_URL,
208209
'storage',
209210
conn.API_VERSION,
210-
# see https://github.com/GoogleCloudPlatform/
211-
# gcloud-python/issues/140
212-
#'?project=%s' % PROJECT,
213-
]) + 'None?project=%s' % PROJECT # XXX
211+
]) + '%s?project=%s' % (PATH, PROJECT)
214212
http = conn._http = Http({'status': '200',
215213
'content-type': 'application/json',
216214
}, '{}')
217-
self.assertEqual(conn.api_request('GET'), {})
218-
self.assertEqual(http._called_with['method'], 'GET')
219-
self.assertEqual(http._called_with['uri'], URI)
220-
self.assertEqual(http._called_with['body'], None)
221-
self.assertEqual(http._called_with['headers'],
222-
{'Accept-Encoding': 'gzip',
223-
'Content-Length': 0,
224-
})
225-
226-
def test_api_request_w_path(self):
227-
PROJECT = 'project'
228-
conn = self._makeOne(PROJECT)
229-
URI = '/'.join([conn.API_BASE_URL,
230-
'storage',
231-
conn.API_VERSION,
232-
'?project=%s' % PROJECT,
233-
])
234-
http = conn._http = Http({'status': '200',
235-
'content-type': 'application/json',
236-
}, '{}')
237-
self.assertEqual(conn.api_request('GET', '/'), {})
215+
self.assertEqual(conn.api_request('GET', PATH), {})
238216
self.assertEqual(http._called_with['method'], 'GET')
239217
self.assertEqual(http._called_with['uri'], URI)
240218
self.assertEqual(http._called_with['body'], None)

0 commit comments

Comments
 (0)