Skip to content

Commit

Permalink
Fix #140: make 'path' required for Connection.api_request.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Sep 26, 2014
1 parent 1823b0f commit ccd8a5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
16 changes: 12 additions & 4 deletions gcloud/storage/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def make_request(self, method, url, data=None, content_type=None,
return self.http.request(uri=url, method=method, headers=headers,
body=data)

def api_request(self, method, path=None, query_params=None,
def api_request(self, method, path, query_params=None,
data=None, content_type=None,
api_base_url=None, api_version=None,
expect_json=True):
Expand All @@ -174,32 +174,40 @@ def api_request(self, method, path=None, query_params=None,
:type method: string
:param method: The HTTP method name (ie, ``GET``, ``POST``, etc).
Required.
:type path: string
:param path: The path to the resource (ie, ``'/b/bucket-name'``).
Required.
:type query_params: dict
:param query_params: A dictionary of keys and values to insert into
the query string of the URL.
the query string of the URL. Default is empty dict.
:type data: string
:param data: The data to send as the body of the request.
:param data: The data to send as the body of the request. Default is the
empty string.
:type content_type: string
:param content_type: The proper MIME type of the data provided.
:param content_type: The proper MIME type of the data provided. Default
is None.
:type api_base_url: string
:param api_base_url: The base URL for the API endpoint.
Typically you won't have to provide this.
Default is the standard API base URL.
:type api_version: string
:param api_version: The version of the API to call.
Typically you shouldn't provide this and instead
use the default for the library.
Default is the latest API version supported by
gcloud-python.
:type expect_json: bool
:param expect_json: If True, this method will try to parse the response
as JSON and raise an exception if that cannot be done.
Default is True.
:raises: Exception if the response code is not 200 OK.
"""
Expand Down
28 changes: 3 additions & 25 deletions gcloud/storage/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,38 +203,16 @@ def test_make_request_w_extra_headers(self):

def test_api_request_defaults(self):
PROJECT = 'project'
PATH = '/path/required'
conn = self._makeOne(PROJECT)
URI = '/'.join([conn.API_BASE_URL,
'storage',
conn.API_VERSION,
# see https://github.com/GoogleCloudPlatform/
# gcloud-python/issues/140
#'?project=%s' % PROJECT,
]) + 'None?project=%s' % PROJECT # XXX
]) + '%s?project=%s' % (PATH, PROJECT)
http = conn._http = Http({'status': '200',
'content-type': 'application/json',
}, '{}')
self.assertEqual(conn.api_request('GET'), {})
self.assertEqual(http._called_with['method'], 'GET')
self.assertEqual(http._called_with['uri'], URI)
self.assertEqual(http._called_with['body'], None)
self.assertEqual(http._called_with['headers'],
{'Accept-Encoding': 'gzip',
'Content-Length': 0,
})

def test_api_request_w_path(self):
PROJECT = 'project'
conn = self._makeOne(PROJECT)
URI = '/'.join([conn.API_BASE_URL,
'storage',
conn.API_VERSION,
'?project=%s' % PROJECT,
])
http = conn._http = Http({'status': '200',
'content-type': 'application/json',
}, '{}')
self.assertEqual(conn.api_request('GET', '/'), {})
self.assertEqual(conn.api_request('GET', PATH), {})
self.assertEqual(http._called_with['method'], 'GET')
self.assertEqual(http._called_with['uri'], URI)
self.assertEqual(http._called_with['body'], None)
Expand Down

0 comments on commit ccd8a5e

Please sign in to comment.