aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2018-08-09 16:22:28 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2018-08-09 16:22:28 +0800
commitdfd932ec551c9636d3c5a3a931d6931b164434ec (patch)
treefa8cd47590c99cc4cac6393f5e7a1446e9439f34
parent8506177af6d637ff21e72af3aa1b1ec2a4208323 (diff)
Add unit test for ns create
Change-Id: If32920af59eb88b257f22a3a036d3574c53a3692 Issue-ID: VFC-1009 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/ns/tests/test_ns_create.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/lcm/ns/tests/test_ns_create.py b/lcm/ns/tests/test_ns_create.py
index 73ea2780..adddb47f 100644
--- a/lcm/ns/tests/test_ns_create.py
+++ b/lcm/ns/tests/test_ns_create.py
@@ -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)