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>
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)
# 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()
'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)
response = self.client.get("/api/nslcm/v1/ns?csarId=1")\r
self.failUnlessEqual(status.HTTP_200_OK, response.status_code)\r
\r
-\r
def test_query_ns_by_nsinstance_id(self):\r
response = self.client.get("/api/nslcm/v1/ns/1")\r
self.failUnlessEqual(status.HTTP_200_OK, response.status_code)\r
\r
-\r
def test_query_all_nsinstance(self):\r
response = self.client.get("/api/nslcm/v1/ns")\r
- print response\r
- self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
\ No newline at end of file
+ self.failUnlessEqual(status.HTTP_200_OK, response.status_code)\r
+ self.assertIsNotNone(response.data)\r
+ self.assertEqual(2, len(response.data))\r
+\r
+ def test_query_ns_by_non_existing_nsinstance_id(self):\r
+ response = self.client.get("/api/nslcm/v1/ns/200")\r
+ self.assertIsNone(response.data)\r
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
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):
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)
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)