Merge "Add tests and param definitions for headers parameter"
This commit is contained in:
commit
ad5656020c
@ -653,6 +653,7 @@ def get_container(url, token, container, marker=None, limit=None,
|
|||||||
:param full_listing: if True, return a full listing, else returns a max
|
:param full_listing: if True, return a full listing, else returns a max
|
||||||
of 10000 listings
|
of 10000 listings
|
||||||
:param service_token: service auth token
|
:param service_token: service auth token
|
||||||
|
:param headers: additional headers to include in the request
|
||||||
:returns: a tuple of (response headers, a list of objects) The response
|
:returns: a tuple of (response headers, a list of objects) The response
|
||||||
headers will be a dict and all header names will be lowercase.
|
headers will be a dict and all header names will be lowercase.
|
||||||
:raises ClientException: HTTP GET request failed
|
:raises ClientException: HTTP GET request failed
|
||||||
@ -732,6 +733,7 @@ def head_container(url, token, container, http_conn=None, headers=None,
|
|||||||
:param container: container name to get stats for
|
:param container: container name to get stats for
|
||||||
:param http_conn: HTTP connection object (If None, it will create the
|
:param http_conn: HTTP connection object (If None, it will create the
|
||||||
conn object)
|
conn object)
|
||||||
|
:param headers: additional headers to include in the request
|
||||||
:param service_token: service auth token
|
:param service_token: service auth token
|
||||||
:returns: a dict containing the response's headers (all header names will
|
:returns: a dict containing the response's headers (all header names will
|
||||||
be lowercase)
|
be lowercase)
|
||||||
@ -971,6 +973,7 @@ def head_object(url, token, container, name, http_conn=None,
|
|||||||
:param http_conn: HTTP connection object (If None, it will create the
|
:param http_conn: HTTP connection object (If None, it will create the
|
||||||
conn object)
|
conn object)
|
||||||
:param service_token: service auth token
|
:param service_token: service auth token
|
||||||
|
:param headers: additional headers to include in the request
|
||||||
:returns: a dict containing the response's headers (all header names will
|
:returns: a dict containing the response's headers (all header names will
|
||||||
be lowercase)
|
be lowercase)
|
||||||
:raises ClientException: HTTP HEAD request failed
|
:raises ClientException: HTTP HEAD request failed
|
||||||
@ -1454,9 +1457,9 @@ class Connection(object):
|
|||||||
return self._retry(None, post_account, headers,
|
return self._retry(None, post_account, headers,
|
||||||
response_dict=response_dict)
|
response_dict=response_dict)
|
||||||
|
|
||||||
def head_container(self, container):
|
def head_container(self, container, headers=None):
|
||||||
"""Wrapper for :func:`head_container`"""
|
"""Wrapper for :func:`head_container`"""
|
||||||
return self._retry(None, head_container, container)
|
return self._retry(None, head_container, container, headers=headers)
|
||||||
|
|
||||||
def get_container(self, container, marker=None, limit=None, prefix=None,
|
def get_container(self, container, marker=None, limit=None, prefix=None,
|
||||||
delimiter=None, end_marker=None, path=None,
|
delimiter=None, end_marker=None, path=None,
|
||||||
@ -1485,9 +1488,9 @@ class Connection(object):
|
|||||||
return self._retry(None, delete_container, container,
|
return self._retry(None, delete_container, container,
|
||||||
response_dict=response_dict)
|
response_dict=response_dict)
|
||||||
|
|
||||||
def head_object(self, container, obj):
|
def head_object(self, container, obj, headers=None):
|
||||||
"""Wrapper for :func:`head_object`"""
|
"""Wrapper for :func:`head_object`"""
|
||||||
return self._retry(None, head_object, container, obj)
|
return self._retry(None, head_object, container, obj, headers=headers)
|
||||||
|
|
||||||
def get_object(self, container, obj, resp_chunk_size=None,
|
def get_object(self, container, obj, resp_chunk_size=None,
|
||||||
query_string=None, response_dict=None, headers=None):
|
query_string=None, response_dict=None, headers=None):
|
||||||
|
@ -1804,6 +1804,59 @@ class TestConnection(MockHttpTest):
|
|||||||
self.assertEqual(str(exc), "put_object('c', 'o', ...) failure "
|
self.assertEqual(str(exc), "put_object('c', 'o', ...) failure "
|
||||||
"and no ability to reset contents for reupload.")
|
"and no ability to reset contents for reupload.")
|
||||||
|
|
||||||
|
def test_get_container(self):
|
||||||
|
headers = {'X-Favourite-Pet': 'Aardvark'}
|
||||||
|
with mock.patch('swiftclient.client.http_connection',
|
||||||
|
self.fake_http_connection(200, body=b'{}')):
|
||||||
|
with mock.patch('swiftclient.client.get_auth',
|
||||||
|
lambda *a, **k: ('http://url:8080/v1/a', 'token')):
|
||||||
|
conn = c.Connection()
|
||||||
|
conn.get_container('c1', prefix='p', limit=5,
|
||||||
|
headers=headers)
|
||||||
|
self.assertEqual(1, len(self.request_log), self.request_log)
|
||||||
|
self.assertRequests([
|
||||||
|
('GET', '/v1/a/c1?format=json&limit=5&prefix=p', '', {
|
||||||
|
'x-auth-token': 'token',
|
||||||
|
'X-Favourite-Pet': 'Aardvark',
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
self.assertEqual(conn.attempts, 1)
|
||||||
|
|
||||||
|
def test_head_container(self):
|
||||||
|
headers = {'X-Favourite-Pet': 'Aardvark'}
|
||||||
|
with mock.patch('swiftclient.client.http_connection',
|
||||||
|
self.fake_http_connection(200, body=b'{}')):
|
||||||
|
with mock.patch('swiftclient.client.get_auth',
|
||||||
|
lambda *a, **k: ('http://url:8080/v1/a', 'token')):
|
||||||
|
conn = c.Connection()
|
||||||
|
conn.head_container('c1', headers=headers)
|
||||||
|
self.assertEqual(1, len(self.request_log), self.request_log)
|
||||||
|
self.assertRequests([
|
||||||
|
('HEAD', '/v1/a/c1', '', {
|
||||||
|
'x-auth-token': 'token',
|
||||||
|
'X-Favourite-Pet': 'Aardvark',
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
self.assertEqual(conn.attempts, 1)
|
||||||
|
|
||||||
|
def test_head_object(self):
|
||||||
|
headers = {'X-Favourite-Pet': 'Aardvark'}
|
||||||
|
with mock.patch('swiftclient.client.http_connection',
|
||||||
|
self.fake_http_connection(200)):
|
||||||
|
with mock.patch('swiftclient.client.get_auth',
|
||||||
|
lambda *a, **k: ('http://url:8080/v1/a', 'token')):
|
||||||
|
conn = c.Connection()
|
||||||
|
conn.head_object('c1', 'o1',
|
||||||
|
headers=headers)
|
||||||
|
self.assertEqual(1, len(self.request_log), self.request_log)
|
||||||
|
self.assertRequests([
|
||||||
|
('HEAD', '/v1/a/c1/o1', '', {
|
||||||
|
'x-auth-token': 'token',
|
||||||
|
'X-Favourite-Pet': 'Aardvark',
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
self.assertEqual(conn.attempts, 1)
|
||||||
|
|
||||||
|
|
||||||
class TestResponseDict(MockHttpTest):
|
class TestResponseDict(MockHttpTest):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user