From 13026f0b47655ffe9e60e1bbe34411bc34060926 Mon Sep 17 00:00:00 2001 From: Ethan Lynn Date: Fri, 23 Mar 2018 10:38:20 +0800 Subject: Add test_check_capacity_invalid_input Add unit tests test_check_capacity_invalid_input for capacity_check API Change-Id: If048b49d7644d2b400b3ce9fae8f5ac0f4fb51cb Issue-ID: MULTICLOUD-156 Signed-off-by: Ethan Lynn --- vio/vio/swagger/views/capacity/views.py | 2 +- vio/vio/tests/test_capacity_view.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'vio') diff --git a/vio/vio/swagger/views/capacity/views.py b/vio/vio/swagger/views/capacity/views.py index ce5d854..1fdc481 100644 --- a/vio/vio/swagger/views/capacity/views.py +++ b/vio/vio/swagger/views/capacity/views.py @@ -72,7 +72,7 @@ class CapacityCheck(APIView): def post(self, request, vimid): try: requirement = json.loads(request.body) - except json.JSONDecodeError as ex: + except ValueError as ex: return Response(data={'error': str(ex)}, status=status.HTTP_400_BAD_REQUEST) try: diff --git a/vio/vio/tests/test_capacity_view.py b/vio/vio/tests/test_capacity_view.py index 174d73e..d27efba 100644 --- a/vio/vio/tests/test_capacity_view.py +++ b/vio/vio/tests/test_capacity_view.py @@ -102,3 +102,10 @@ class CapacityCheckTest(unittest.TestCase): resp = self.view.post(req, "openstack_regionone") self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertEqual({"result": False}, resp.data) + + def test_check_capacity_invalid_input(self): + req = mock.Mock() + req.body = "hello world" + + resp = self.view.post(req, "openstack_regionone") + self.assertEqual(status.HTTP_400_BAD_REQUEST, resp.status_code) -- cgit 1.2.3-korg