Merge "Prevent error in _parse_resp when nullable list"

This commit is contained in:
Jenkins 2017-06-14 04:34:36 +00:00 committed by Gerrit Code Review
commit 5aad8e753a
3 changed files with 12 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
fixes:
- |
When receiving nullable list as a response body, tempest.lib
rest_client module raised an exception without valid json
deserialization. A new release fixes this bug.

View File

@ -474,7 +474,7 @@ class RestClient(object):
# Ensure there are not more than one top-level keys
# NOTE(freerunner): Ensure, that JSON is not nullable to
# to prevent StopIteration Exception
if len(body.keys()) != 1:
if not hasattr(body, "keys") or len(body.keys()) != 1:
return body
# Just return the "wrapped" element
first_key, first_item = six.next(six.iteritems(body))

View File

@ -276,6 +276,11 @@ class TestRestClientParseRespJSON(BaseRestClientTestClass):
body = self.rest_client._parse_resp(json.dumps(self.null_dict))
self.assertEqual(self.null_dict, body)
def test_parse_empty_list(self):
empty_list = []
body = self.rest_client._parse_resp(json.dumps(empty_list))
self.assertEqual(empty_list, body)
class TestRestClientErrorCheckerJSON(base.TestCase):
c_type = "application/json"