Add unit test for ns create 03/59803/1
authorfujinhua <fu.jinhua@zte.com.cn>
Thu, 9 Aug 2018 08:22:28 +0000 (16:22 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Thu, 9 Aug 2018 08:22:28 +0000 (16:22 +0800)
Change-Id: If32920af59eb88b257f22a3a036d3574c53a3692
Issue-ID: VFC-1009
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/ns/tests/test_ns_create.py

index 73ea278..adddb47 100644 (file)
@@ -80,7 +80,7 @@ class TestNsInstantiate(TestCase):
         self.assertIn("error", response.data)
 
     @mock.patch.object(restcall, 'call_req')
-    def test_create_ns_when_nsdid_not_exist(self, mock_call_req):
+    def test_create_ns_when_fail_to_get_nsd(self, mock_call_req):
         mock_call_req.return_value = [1, "Failed to get nsd.", '500']
         data = {
             'csarId': '1',
@@ -90,3 +90,20 @@ class TestNsInstantiate(TestCase):
         response = self.client.post("/api/nslcm/v1/ns", data=data)
         self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
         self.assertIn("error", response.data)
+
+    @mock.patch.object(restcall, 'call_req')
+    def test_create_ns_when_ns_name_exist(self, mock_call_req):
+        nspackage_info = json.JSONEncoder().encode({
+            "csarId": self.ns_package_id,
+            "packageInfo": {}
+        })
+        mock_call_req.return_value = [0, nspackage_info, '200']
+        NSInstModel(id="1", name="ns1").save()
+        data = {
+            'csarId': '1',
+            'nsName': 'ns1',
+            'description': 'description'
+        }
+        response = self.client.post("/api/nslcm/v1/ns", data=data)
+        self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+        self.assertIn("error", response.data)