diff options
author | Liang Ke <lokyse@163.com> | 2018-03-23 02:19:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-23 02:19:34 +0000 |
commit | 82785fa1e968f8383af1d24acd6a06f0fe6ac55f (patch) | |
tree | 270016a569e1fdbe9be321777929c3f387da89b9 /multivimbroker | |
parent | a6db80a543d9516db0af29bcc0db9d3a0d813b0f (diff) | |
parent | 887f8f1071c7327b6e24546ee9fa33722463e064 (diff) |
Merge "Add test_check_capacity_invalid_input"
Diffstat (limited to 'multivimbroker')
-rw-r--r-- | multivimbroker/multivimbroker/forwarder/views.py | 4 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/tests/test_check_capacity.py | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/multivimbroker/multivimbroker/forwarder/views.py b/multivimbroker/multivimbroker/forwarder/views.py index c77fe94..83d3172 100644 --- a/multivimbroker/multivimbroker/forwarder/views.py +++ b/multivimbroker/multivimbroker/forwarder/views.py @@ -104,7 +104,7 @@ class CheckCapacity(BaseServer): def post(self, request): try: body = json.loads(request.body) - except json.JSONDecodeError as e: + except ValueError as e: return Response( data={'error': 'Invalidate request body %s.' % e}, status=status.HTTP_400_BAD_REQUEST) @@ -123,7 +123,7 @@ class CheckCapacity(BaseServer): continue try: resp_body = json.loads(resp.body) - except json.JSONDecodeError: + except ValueError: continue if not resp_body.get("result", False): continue diff --git a/multivimbroker/multivimbroker/tests/test_check_capacity.py b/multivimbroker/multivimbroker/tests/test_check_capacity.py index 63fc7dc..60035e0 100644 --- a/multivimbroker/multivimbroker/tests/test_check_capacity.py +++ b/multivimbroker/multivimbroker/tests/test_check_capacity.py @@ -78,3 +78,16 @@ class CheckCapacityTest(unittest.TestCase): } self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertDictEqual(expect_body, resp.data) + + def test_check_capacity_invalid_input(self): + req = mock.Mock() + req.body = "hello world" + req.get_full_path.return_value = ("http://msb.onap.org/api/multicloud" + "/v0/check_vim_capacity") + expect_body = { + "error": ("Invalidate request body " + "No JSON object could be decoded.") + } + resp = self.view.post(req) + self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code) + self.assertDictEqual(expect_body, resp.data) |