Add delimiter to get_account().
Exposes the delimiter parameter, which the Swift API supports for container listings. Change-Id: Id8dfce01a9b64de9d1222aab9a4a682ce9e0f2b7
This commit is contained in:
parent
8778c91c71
commit
edfeae3723
@ -757,7 +757,7 @@ def store_response(resp, response_dict):
|
|||||||
|
|
||||||
def get_account(url, token, marker=None, limit=None, prefix=None,
|
def get_account(url, token, marker=None, limit=None, prefix=None,
|
||||||
end_marker=None, http_conn=None, full_listing=False,
|
end_marker=None, http_conn=None, full_listing=False,
|
||||||
service_token=None, headers=None):
|
service_token=None, headers=None, delimiter=None):
|
||||||
"""
|
"""
|
||||||
Get a listing of containers for the account.
|
Get a listing of containers for the account.
|
||||||
|
|
||||||
@ -773,6 +773,7 @@ def get_account(url, token, marker=None, limit=None, prefix=None,
|
|||||||
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
|
:param headers: additional headers to include in the request
|
||||||
|
:param delimiter: delimiter query
|
||||||
:returns: a tuple of (response headers, a list of containers) The response
|
:returns: a tuple of (response headers, a list of containers) 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
|
||||||
@ -786,14 +787,14 @@ def get_account(url, token, marker=None, limit=None, prefix=None,
|
|||||||
if not http_conn:
|
if not http_conn:
|
||||||
http_conn = http_connection(url)
|
http_conn = http_connection(url)
|
||||||
if full_listing:
|
if full_listing:
|
||||||
rv = get_account(url, token, marker, limit, prefix,
|
rv = get_account(url, token, marker, limit, prefix, end_marker,
|
||||||
end_marker, http_conn, headers=req_headers)
|
http_conn, headers=req_headers, delimiter=delimiter)
|
||||||
listing = rv[1]
|
listing = rv[1]
|
||||||
while listing:
|
while listing:
|
||||||
marker = listing[-1]['name']
|
marker = listing[-1]['name']
|
||||||
listing = get_account(url, token, marker, limit, prefix,
|
listing = get_account(url, token, marker, limit, prefix,
|
||||||
end_marker, http_conn,
|
end_marker, http_conn, headers=req_headers,
|
||||||
headers=req_headers)[1]
|
delimiter=delimiter)[1]
|
||||||
if listing:
|
if listing:
|
||||||
rv[1].extend(listing)
|
rv[1].extend(listing)
|
||||||
return rv
|
return rv
|
||||||
@ -805,6 +806,8 @@ def get_account(url, token, marker=None, limit=None, prefix=None,
|
|||||||
qs += '&limit=%d' % limit
|
qs += '&limit=%d' % limit
|
||||||
if prefix:
|
if prefix:
|
||||||
qs += '&prefix=%s' % quote(prefix)
|
qs += '&prefix=%s' % quote(prefix)
|
||||||
|
if delimiter:
|
||||||
|
qs += '&delimiter=%s' % quote(delimiter)
|
||||||
if end_marker:
|
if end_marker:
|
||||||
qs += '&end_marker=%s' % quote(end_marker)
|
qs += '&end_marker=%s' % quote(end_marker)
|
||||||
full_path = '%s?%s' % (parsed.path, qs)
|
full_path = '%s?%s' % (parsed.path, qs)
|
||||||
@ -1779,14 +1782,16 @@ class Connection(object):
|
|||||||
return self._retry(None, head_account, headers=headers)
|
return self._retry(None, head_account, headers=headers)
|
||||||
|
|
||||||
def get_account(self, marker=None, limit=None, prefix=None,
|
def get_account(self, marker=None, limit=None, prefix=None,
|
||||||
end_marker=None, full_listing=False, headers=None):
|
end_marker=None, full_listing=False, headers=None,
|
||||||
|
delimiter=None):
|
||||||
"""Wrapper for :func:`get_account`"""
|
"""Wrapper for :func:`get_account`"""
|
||||||
# TODO(unknown): With full_listing=True this will restart the entire
|
# TODO(unknown): With full_listing=True this will restart the entire
|
||||||
# listing with each retry. Need to make a better version that just
|
# listing with each retry. Need to make a better version that just
|
||||||
# retries where it left off.
|
# retries where it left off.
|
||||||
return self._retry(None, get_account, marker=marker, limit=limit,
|
return self._retry(None, get_account, marker=marker, limit=limit,
|
||||||
prefix=prefix, end_marker=end_marker,
|
prefix=prefix, end_marker=end_marker,
|
||||||
full_listing=full_listing, headers=headers)
|
full_listing=full_listing, headers=headers,
|
||||||
|
delimiter=delimiter)
|
||||||
|
|
||||||
def post_account(self, headers, response_dict=None,
|
def post_account(self, headers, response_dict=None,
|
||||||
query_string=None, data=None):
|
query_string=None, data=None):
|
||||||
|
@ -154,6 +154,18 @@ class TestFunctional(unittest.TestCase):
|
|||||||
self.assertTrue(len(containers) >= 1)
|
self.assertTrue(len(containers) >= 1)
|
||||||
self.assertEqual(self.containername_2, containers[0].get('name'))
|
self.assertEqual(self.containername_2, containers[0].get('name'))
|
||||||
|
|
||||||
|
# Test prefix
|
||||||
|
_, containers = self.conn.get_account(prefix='dne')
|
||||||
|
self.assertEqual(0, len(containers))
|
||||||
|
|
||||||
|
# Test delimiter
|
||||||
|
_, containers = self.conn.get_account(
|
||||||
|
prefix=self.containername, delimiter='_')
|
||||||
|
self.assertEqual(2, len(containers))
|
||||||
|
self.assertEqual(self.containername, containers[0].get('name'))
|
||||||
|
self.assertTrue(
|
||||||
|
self.containername_2.startswith(containers[1].get('subdir')))
|
||||||
|
|
||||||
def _check_container_headers(self, headers):
|
def _check_container_headers(self, headers):
|
||||||
self.assertTrue(headers.get('content-length'))
|
self.assertTrue(headers.get('content-length'))
|
||||||
self.assertTrue(headers.get('x-container-object-count'))
|
self.assertTrue(headers.get('x-container-object-count'))
|
||||||
|
@ -704,6 +704,18 @@ class TestGetAccount(MockHttpTest):
|
|||||||
'x-auth-token': 'asdf'}),
|
'x-auth-token': 'asdf'}),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_param_delimiter(self):
|
||||||
|
c.http_connection = self.fake_http_connection(
|
||||||
|
204,
|
||||||
|
query_string="format=json&delimiter=-")
|
||||||
|
c.get_account('http://www.test.com/v1/acct', 'asdf',
|
||||||
|
delimiter='-')
|
||||||
|
self.assertRequests([
|
||||||
|
('GET', '/v1/acct?format=json&delimiter=-', '', {
|
||||||
|
'accept-encoding': 'gzip',
|
||||||
|
'x-auth-token': 'asdf'}),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class TestHeadAccount(MockHttpTest):
|
class TestHeadAccount(MockHttpTest):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user