diff options
author | Liang Ke <lokyse@163.com> | 2018-03-26 02:09:05 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-26 02:09:05 +0000 |
commit | a68fb456fe07603113d6494375dc9381b48d47ce (patch) | |
tree | 1c219b7ff0025cd884f6c9f4d83328882f7135bc /vio | |
parent | c2a1813c93e8a4026290a5c2d7c5bf2d27b542e4 (diff) | |
parent | 13026f0b47655ffe9e60e1bbe34411bc34060926 (diff) |
Merge "Add test_check_capacity_invalid_input"
Diffstat (limited to 'vio')
-rw-r--r-- | vio/vio/swagger/views/capacity/views.py | 2 | ||||
-rw-r--r-- | vio/vio/tests/test_capacity_view.py | 7 |
2 files changed, 8 insertions, 1 deletions
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) |