summaryrefslogtreecommitdiffstats
path: root/vio
diff options
context:
space:
mode:
authorEthan Lynn <ethanlynnl@vmware.com>2018-03-23 10:38:20 +0800
committerEthan Lynn <ethanlynnl@vmware.com>2018-03-23 10:42:45 +0800
commit13026f0b47655ffe9e60e1bbe34411bc34060926 (patch)
treebc1939f23b468bad68a2999df6f3e36a3e8e69ba /vio
parent4dd253b31c30a8d7b5cba554e1780c45018a76c8 (diff)
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 <ethanlynnl@vmware.com>
Diffstat (limited to 'vio')
-rw-r--r--vio/vio/swagger/views/capacity/views.py2
-rw-r--r--vio/vio/tests/test_capacity_view.py7
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)