summaryrefslogtreecommitdiffstats
path: root/multivimbroker
diff options
context:
space:
mode:
Diffstat (limited to 'multivimbroker')
-rw-r--r--multivimbroker/multivimbroker/forwarder/views.py4
-rw-r--r--multivimbroker/multivimbroker/tests/test_check_capacity.py13
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)