aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShashank Kumar Shankar <shashank.kumar.shankar@intel.com>2017-09-14 16:06:16 -0700
committerShashank Kumar Shankar <shashank.kumar.shankar@intel.com>2017-09-14 16:11:34 -0700
commit485eca389e366c8478ab513249222a8cb6723402 (patch)
tree04ef7b7d6294df0f3677669326dc0cf7a33ff838
parent8fa86b9e82224b890a56292c2408e6b804e9bd00 (diff)
Add additional unit tests in NS tests
This patch adds additional unit tests in NS unit tests. Change-Id: Id29761c80196acdbf5091a49222968885f5a92e2 Issue-Id: VFC-358 Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com>
-rw-r--r--lcm/jobs/tests/tests.py8
-rw-r--r--lcm/ns/tests/test_ns_create.py30
-rw-r--r--lcm/ns/tests/test_ns_get.py11
-rw-r--r--lcm/ns/tests/test_ns_heal.py1
-rw-r--r--lcm/ns/tests/test_ns_manual_scale.py26
-rw-r--r--lcm/ns/tests/tests_ns_terminate.py14
6 files changed, 84 insertions, 6 deletions
diff --git a/lcm/jobs/tests/tests.py b/lcm/jobs/tests/tests.py
index 3c2b441d..7b97c724 100644
--- a/lcm/jobs/tests/tests.py
+++ b/lcm/jobs/tests/tests.py
@@ -30,3 +30,11 @@ class JobsViewTest(TestCase):
JobStatusModel(indexid=1, jobid=self.job_id, status='inst', progress=20, descp='inst').save()
response = self.client.get("/api/nslcm/v1/jobs/%s" % self.job_id)
self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+ def test_non_exiting_job(self):
+ job_id = 'test_new_job_id'
+ JobModel(jobid=self.job_id, jobtype='VNF', jobaction='INST', resid='1').save()
+ JobStatusModel(indexid=1, jobid=self.job_id, status='inst', progress=20, descp='inst').save()
+ response = self.client.get("/api/nslcm/v1/jobs/%s" % job_id)
+ self.assertIn('jobId', response.data)
+ self.assertNotIn('responseDescriptor', response.data)
diff --git a/lcm/ns/tests/test_ns_create.py b/lcm/ns/tests/test_ns_create.py
index c9e1e080..408d088e 100644
--- a/lcm/ns/tests/test_ns_create.py
+++ b/lcm/ns/tests/test_ns_create.py
@@ -12,16 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import json
+
import uuid
import mock
from django.test import TestCase, Client
from rest_framework import status
+from lcm.ns.ns_create import CreateNSService
+from lcm.pub.exceptions import NSLCMException
from lcm.pub.database.models import NSInstModel, NSDModel
from lcm.pub.utils import restcall
-
class TestNsInstantiate(TestCase):
def setUp(self):
self.client = Client()
@@ -43,3 +45,29 @@ class TestNsInstantiate(TestCase):
'description': 'description'}
response = self.client.post("/api/nslcm/v1/ns", data=data)
self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
+
+ @mock.patch.object(CreateNSService, "do_biz")
+ def test_create_ns_empty_data(self, mock_do_biz):
+ mock_do_biz.side_effect = Exception("Exception in CreateNS.")
+
+ data = {}
+
+ response = self.client.post("/api/nslcm/v1/ns", data=data)
+ self.assertEqual(response.data["error"], "Exception in CreateNS.")
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self.assertIn("error", response.data)
+
+ @mock.patch.object(CreateNSService, "do_biz")
+ def test_create_ns_non_existing_nsd(self, mock_do_biz):
+ mock_do_biz.side_effect = NSLCMException("nsd not exists.")
+ new_nsd_id = '1'
+
+ data = {
+ 'nsdid': new_nsd_id,
+ 'nsname': 'ns',
+ 'description': 'description'}
+
+ response = self.client.post("/api/nslcm/v1/ns", data=data)
+ self.assertEqual(response.data["error"], "nsd not exists.")
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self.assertIn("error", response.data)
diff --git a/lcm/ns/tests/test_ns_get.py b/lcm/ns/tests/test_ns_get.py
index 146ce459..1dad989d 100644
--- a/lcm/ns/tests/test_ns_get.py
+++ b/lcm/ns/tests/test_ns_get.py
@@ -31,13 +31,16 @@ class TestNsQuery(TestCase):
response = self.client.get("/api/nslcm/v1/ns?csarId=1")
self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
-
def test_query_ns_by_nsinstance_id(self):
response = self.client.get("/api/nslcm/v1/ns/1")
self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
-
def test_query_all_nsinstance(self):
response = self.client.get("/api/nslcm/v1/ns")
- print response
- self.failUnlessEqual(status.HTTP_200_OK, response.status_code) \ No newline at end of file
+ self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+ self.assertIsNotNone(response.data)
+ self.assertEqual(2, len(response.data))
+
+ def test_query_ns_by_non_existing_nsinstance_id(self):
+ response = self.client.get("/api/nslcm/v1/ns/200")
+ self.assertIsNone(response.data)
diff --git a/lcm/ns/tests/test_ns_heal.py b/lcm/ns/tests/test_ns_heal.py
index e47f5f45..46f13ce6 100644
--- a/lcm/ns/tests/test_ns_heal.py
+++ b/lcm/ns/tests/test_ns_heal.py
@@ -20,7 +20,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
diff --git a/lcm/ns/tests/test_ns_manual_scale.py b/lcm/ns/tests/test_ns_manual_scale.py
index 67c6f858..6d2097df 100644
--- a/lcm/ns/tests/test_ns_manual_scale.py
+++ b/lcm/ns/tests/test_ns_manual_scale.py
@@ -24,6 +24,7 @@ from lcm.ns.const import NS_INST_STATUS
from lcm.pub.utils import restcall
from lcm.pub.utils import toscautil
from lcm.ns.ns_manual_scale import NSManualScaleService
+from lcm.pub.exceptions import NSLCMException
class TestNsManualScale(TestCase):
def setUp(self):
@@ -91,3 +92,28 @@ class TestNsManualScale(TestCase):
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(NSManualScaleService, 'start')
+ def test_ns_manual_scale_empty_data(self, mock_start):
+ mock_start.side_effect = NSLCMException("NS scale failed.")
+
+ data = {}
+
+ response = self.client.post("/api/nslcm/v1/ns/%s/scale" % self.nsd_id, data=data)
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self.assertIn("error", response.data)
+
+ @mock.patch.object(NSManualScaleService, 'start')
+ def test_ns_manual_scale_non_existing_nsd_id(self, mock_start):
+ mock_start.side_effect = NSLCMException("NS scale failed.")
+
+ nsd_id = '1111'
+
+ data = {
+ 'nsdid': nsd_id,
+ 'nsname': 'ns',
+ 'description': 'description'}
+
+ response = self.client.post("/api/nslcm/v1/ns/%s/scale" % nsd_id, data=data)
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self.assertIn("error", response.data)
diff --git a/lcm/ns/tests/tests_ns_terminate.py b/lcm/ns/tests/tests_ns_terminate.py
index 5251c1da..a39cb6ee 100644
--- a/lcm/ns/tests/tests_ns_terminate.py
+++ b/lcm/ns/tests/tests_ns_terminate.py
@@ -97,3 +97,17 @@ class TestTerminateNsViews(TestCase):
self.assertTrue(1, 0)
else:
self.assertTrue(1, 1)
+
+ @mock.patch.object(TerminateNsService, 'run')
+ def test_terminate_non_existing_ns_inst_id(self, mock_run):
+ mock_run.re.return_value = None
+
+ ns_inst_id = '100'
+
+ req_data = {
+ "terminationType": "forceful",
+ "gracefulTerminationTimeout": "600"}
+ response = self.client.post("/api/nslcm/v1/ns/%s/terminate" % ns_inst_id, data=req_data)
+ self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
+
+ self.assertRaises(NSInstModel.DoesNotExist, NSInstModel.objects.get, id=ns_inst_id)