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
1 changed files with 26 additions and 13 deletions

View File

@ -366,26 +366,39 @@ class Base(object):
if optional_fields is None:
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())
ret = {}
for field in required_fields:
if field[1] not in headers:
for return_key, header in required_fields:
if header not in headers:
raise ValueError("%s was not found in response header" %
(field[1]))
(header,))
try:
ret[field[0]] = int(headers[field[1]])
except ValueError:
ret[field[0]] = headers[field[1]]
if is_int_header(header):
ret[return_key] = int(headers[header])
else:
ret[return_key] = headers[header]
for field in optional_fields:
if field[1] not in headers:
for return_key, header in optional_fields:
if header not in headers:
continue
try:
ret[field[0]] = int(headers[field[1]])
except ValueError:
ret[field[0]] = headers[field[1]]
if is_int_header(header):
ret[return_key] = int(headers[header])
else:
ret[return_key] = headers[header]
return ret