Merge "functests: Only convert headers that should be ints to be ints"

This commit is contained in:
Jenkins 2017-08-18 07:54:17 +00:00 committed by Gerrit Code Review
commit c9acb0a717

View File

@ -366,26 +366,39 @@ class Base(object):
if optional_fields is None: if optional_fields is None:
optional_fields = () optional_fields = ()
def is_int_header(header):
if header.startswith('x-account-storage-policy-') and \
header.endswith(('-bytes-used', '-object-count')):
return True
return header in (
'content-length',
'x-account-container-count',
'x-account-object-count',
'x-account-bytes-used',
'x-container-object-count',
'x-container-bytes-used',
)
headers = dict(self.conn.response.getheaders()) headers = dict(self.conn.response.getheaders())
ret = {} ret = {}
for field in required_fields: for return_key, header in required_fields:
if field[1] not in headers: if header not in headers:
raise ValueError("%s was not found in response header" % raise ValueError("%s was not found in response header" %
(field[1])) (header,))
try: if is_int_header(header):
ret[field[0]] = int(headers[field[1]]) ret[return_key] = int(headers[header])
except ValueError: else:
ret[field[0]] = headers[field[1]] ret[return_key] = headers[header]
for field in optional_fields: for return_key, header in optional_fields:
if field[1] not in headers: if header not in headers:
continue continue
try: if is_int_header(header):
ret[field[0]] = int(headers[field[1]]) ret[return_key] = int(headers[header])
except ValueError: else:
ret[field[0]] = headers[field[1]] ret[return_key] = headers[header]
return ret return ret