Add test_check_capacity_invalid_input 31/37731/1
authorEthan Lynn <ethanlynnl@vmware.com>
Thu, 22 Mar 2018 10:19:37 +0000 (18:19 +0800)
committerEthan Lynn <ethanlynnl@vmware.com>
Thu, 22 Mar 2018 10:21:20 +0000 (18:21 +0800)
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>
multivimbroker/multivimbroker/forwarder/views.py
multivimbroker/multivimbroker/tests/test_check_capacity.py

index c77fe94..83d3172 100644 (file)
@@ -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
index 63fc7dc..60035e0 100644 (file)
@@ -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)