summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorhongyuzhao <zhao.hongyu@zte.com.cn>2019-07-08 15:21:35 +0800
committerhongyuzhao <zhao.hongyu@zte.com.cn>2019-07-08 15:24:10 +0800
commit87ba2f52d9e649b48ca76be0d53f53010613709c (patch)
treea7ebea84212a5dc9209a9a80581c139be3c14ad9 /lcm
parentbda9286b8d1ff765d8379dd8874697c93dd14a9c (diff)
improve code coverage rate after vfclcm upgraded from python2 to python3
Change-Id: Icd7d3cec2831f68568697fc0c3eb329c3245df13 Issue-ID: VFC-1429 Signed-off-by: hongyuzhao <zhao.hongyu@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/tests/test_create_vnf.py52
-rw-r--r--lcm/lcm/nf/views/curd_vnf_views.py3
2 files changed, 54 insertions, 1 deletions
diff --git a/lcm/lcm/nf/tests/test_create_vnf.py b/lcm/lcm/nf/tests/test_create_vnf.py
index 39640b57..3ac414f9 100644
--- a/lcm/lcm/nf/tests/test_create_vnf.py
+++ b/lcm/lcm/nf/tests/test_create_vnf.py
@@ -25,6 +25,8 @@ from lcm.pub.database.models import NfInstModel
from lcm.pub.database.models import JobStatusModel
from lcm.pub.utils import restcall
from lcm.pub.utils.timeutil import now_time
+from lcm.pub.exceptions import NFLCMException
+from lcm.nf.biz.create_vnf import CreateVnf
class TestNFInstantiate(TestCase):
@@ -110,3 +112,53 @@ class TestNFInstantiate(TestCase):
}
self.assertEqual(status.HTTP_201_CREATED, response.status_code)
self.assertEqual(expect_data, response.data)
+
+ @mock.patch.object(restcall, 'call_req')
+ @mock.patch.object(uuid, 'uuid4')
+ def test_create_vnf_inner_error(self, mock_uuid4, mock_call_req):
+ mock_call_req.return_value = NFLCMException('Boom!')
+ mock_uuid4.return_value = "1"
+ data = {
+ "vnfdId": "111",
+ "vnfInstanceName": "vFW_01",
+ "vnfInstanceDescription": "vFW in Nanjing TIC Edge"
+ }
+ response = self.client.post(
+ "/api/vnflcm/v1/vnf_instances",
+ data=data,
+ format='json'
+ )
+ self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
+
+ def test_create_vnf_bad_req(self):
+ data = {
+ "vnfInstanceName": "vFW_01",
+ "vnfInstanceDescription": "vFW in Nanjing TIC Edge"
+ }
+ response = self.client.post(
+ "/api/vnflcm/v1/vnf_instances",
+ data=data,
+ format='json'
+ )
+ self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
+
+ @mock.patch.object(CreateVnf, 'do_biz')
+ def test_create_vnf_bad_response(self, moc_CreateVnf_do_biz):
+ moc_CreateVnf_do_biz.return_value = {
+ # "id": "1",
+ "vnfProvider": "huawei",
+ "vnfdVersion": "1.0",
+ "vnfPkgId": "111",
+ "instantiationState": "NOT_INSTANTIATED"
+ }
+ data = {
+ "vnfdId": "111",
+ "vnfInstanceName": "vFW_01",
+ "vnfInstanceDescription": "vFW in Nanjing TIC Edge"
+ }
+ response = self.client.post(
+ "/api/vnflcm/v1/vnf_instances",
+ data=data,
+ format='json'
+ )
+ self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
diff --git a/lcm/lcm/nf/views/curd_vnf_views.py b/lcm/lcm/nf/views/curd_vnf_views.py
index e8c19d67..f5c7a77a 100644
--- a/lcm/lcm/nf/views/curd_vnf_views.py
+++ b/lcm/lcm/nf/views/curd_vnf_views.py
@@ -33,6 +33,7 @@ from lcm.nf.const import OPERATION_TYPE
from .common import view_safe_call_with_log
from .common import deal_vnf_action
from .common import deal_indivdual_query
+from lcm.pub.exceptions import NFLCMExceptionBadRequest
logger = logging.getLogger(__name__)
@@ -68,7 +69,7 @@ class CreateVnfAndQueryVnfs(APIView):
logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
req_serializer = CreateVnfReqSerializer(data=request.data)
if not req_serializer.is_valid():
- raise NFLCMException(req_serializer.errors)
+ raise NFLCMExceptionBadRequest(req_serializer.errors)
nf_inst = CreateVnf(request.data).do_biz()
rsp_data = {"id": nf_inst.nfinstid,