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

Change-Id: I675d05d65b9c3c3ef18684c175d227f662b38f67
Closes-Bug: #1641216
This commit is contained in:
Tim Burke 2017-07-20 00:30:40 +00:00
parent 3c11f6b8a8
commit 708fdec831

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