Refactor unit test for vnf heal
[vfc/nfvo/lcm.git] / lcm / ns / tests / test_ns_heal.py
index 0d77dbc..8d2f93a 100644 (file)
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 import mock
+import json
 
 from rest_framework import status
 from django.test import TestCase
@@ -20,7 +21,6 @@ from django.test import Client
 from lcm.pub.database.models import NSInstModel, NfInstModel
 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
 from lcm.ns.const import NS_INST_STATUS
-from lcm.pub.utils import restcall
 from lcm.pub.exceptions import NSLCMException
 from lcm.ns.ns_heal import NSHealService
 
@@ -36,19 +36,40 @@ class TestHealNsViews(TestCase):
 
         self.client = Client()
 
-        model = '{"metadata": {"vnfdId": "1","vnfdName": "PGW001","vnfProvider": "zte","vnfdVersion": "V00001",' \
-                '"vnfVersion": "V5.10.20","productType": "CN","vnfType": "PGW",' \
-                '"description": "PGW VNFD description","isShared":true,"vnfExtendType":"driver"}}'
+        model = json.dumps({
+            "metadata": {
+                "vnfdId": "1",
+                "vnfdName": "PGW001",
+                "vnfProvider": "zte",
+                "vnfdVersion": "V00001",
+                "vnfVersion": "V5.10.20",
+                "productType": "CN",
+                "vnfType": "PGW",
+                "description": "PGW VNFD description",
+                "isShared": True,
+                "vnfExtendType": "driver"
+            }
+        })
+        NSInstModel.objects.filter().delete()
+        NfInstModel.objects.filter().delete()
         NSInstModel(id=self.ns_inst_id, name="ns_name", status='null').save()
-        NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
-                                   vnfm_inst_id='1', ns_inst_id=self.ns_inst_id,
-                                   max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
-                                   status='null', mnfinstid=self.nf_uuid, package_id='pkg1',
+        NfInstModel.objects.create(nfinstid=self.nf_inst_id,
+                                   nf_name='name_1',
+                                   vnf_id='1',
+                                   vnfm_inst_id='1',
+                                   ns_inst_id=self.ns_inst_id,
+                                   max_cpu='14',
+                                   max_ram='12296',
+                                   max_hd='101',
+                                   max_shd="20",
+                                   max_net=10,
+                                   status='null',
+                                   mnfinstid=self.nf_uuid,
+                                   package_id='pkg1',
                                    vnfd_model=model)
 
     def tearDown(self):
-        NSInstModel.objects.filter().delete()
-        NfInstModel.objects.filter().delete()
+        pass
 
     @mock.patch.object(NSHealService, 'run')
     def test_heal_vnf_url(self, mock_run):
@@ -67,7 +88,7 @@ class TestHealNsViews(TestCase):
         }
 
         response = self.client.post("/api/nslcm/v1/ns/%s/heal" % self.ns_inst_id, data=data)
-        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
+        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.data)
         self.assertIsNotNone(response.data)
         self.assertIn("jobId", response.data)
         self.assertNotIn("error", response.data)
@@ -97,10 +118,6 @@ class TestHealNsViews(TestCase):
         NSHealService(self.ns_inst_id, data, self.job_id).run()
         self.assertEqual(NSInstModel.objects.get(id=self.ns_inst_id).status, NS_INST_STATUS.HEALING)
 
-    def test_swagger_ok(self):
-        resp = self.client.get("/api/nslcm/v1/swagger.json", format='json')
-        self.assertEqual(resp.status_code, status.HTTP_200_OK)
-
     @mock.patch.object(NSHealService, "start")
     def test_ns_heal_non_existing_ns(self, mock_start):
         mock_start.side_effect = NSLCMException("NS Not Found")
@@ -133,6 +150,5 @@ class TestHealNsViews(TestCase):
         data = {}
 
         response = self.client.post("/api/nslcm/v1/ns/%s/heal" % self.ns_inst_id, data=data)
-        self.assertEqual(response.data["error"], "healVnfData parameter does not exist or value is incorrect.")
         self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
         self.assertIn("error", response.data)