diff options
author | Ethan Lynn <ethanlynnl@vmware.com> | 2018-03-22 18:19:37 +0800 |
---|---|---|
committer | Ethan Lynn <ethanlynnl@vmware.com> | 2018-03-22 18:21:20 +0800 |
commit | 887f8f1071c7327b6e24546ee9fa33722463e064 (patch) | |
tree | 4d8d1c1003f28c0049ebb72ac0b9a1689b77178b /multivimbroker | |
parent | df7f13c5cfe0cf047d35775f11ac3a363e65ef1a (diff) |
Add test_check_capacity_invalid_input
Add test_check_capacity_invalid_input for check_vim_capacity API
Change-Id: I26ddf91b17597bfca9eb3bb424a6d9515071da6d
Issue-ID: MULTICLOUD-166
Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
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) |