diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-01-07 17:59:26 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-01-07 17:59:26 +0000 |
commit | 01370766a9199506a02e3af1eb9bd6a12c1a5afe (patch) | |
tree | 56a5bd01713b18ba8f4beefe2150c9ab22ee4d10 | |
parent | 4594a8a10cdd443a9504e9c411f8c5206b3a3795 (diff) | |
parent | 6910813552025e28031d80c7b8a09c7a0869d38c (diff) | |
download | tempest-lib-01370766a9199506a02e3af1eb9bd6a12c1a5afe.tar.gz |
Merge "Prevent StopIteration exception during parse response"
-rw-r--r-- | tempest_lib/common/rest_client.py | 4 | ||||
-rw-r--r-- | tempest_lib/tests/test_rest_client.py | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/tempest_lib/common/rest_client.py b/tempest_lib/common/rest_client.py index d833d5f..c5886e6 100644 --- a/tempest_lib/common/rest_client.py +++ b/tempest_lib/common/rest_client.py @@ -461,7 +461,9 @@ class RestClient(object): # } try: # Ensure there are not more than one top-level keys - if len(body.keys()) > 1: + # NOTE(freerunner): Ensure, that JSON is not nullable to + # to prevent StopIteration Exception + if len(body.keys()) != 1: return body # Just return the "wrapped" element first_key, first_item = six.next(six.iteritems(body)) diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py index 0875092..452cef5 100644 --- a/tempest_lib/tests/test_rest_client.py +++ b/tempest_lib/tests/test_rest_client.py @@ -244,6 +244,7 @@ class TestRestClientParseRespJSON(BaseRestClientTestClass): keys[0]: values[0], keys[1]: values[1], }} + null_dict = {} def setUp(self): self.fake_http = fake_http.fake_httplib2() @@ -273,6 +274,10 @@ class TestRestClientParseRespJSON(BaseRestClientTestClass): body = self.rest_client._parse_resp(json.dumps(data)) self.assertEqual(data, body) + def test_parse_nullable_dict(self): + body = self.rest_client._parse_resp(json.dumps(self.null_dict)) + self.assertEqual(self.null_dict, body) + class TestRestClientErrorCheckerJSON(base.TestCase): c_type = "application/json" |