diff options
author | maopengzhang <zhang.maopeng1@zte.com.cn> | 2019-07-08 14:13:06 +0800 |
---|---|---|
committer | maopengzhang <zhang.maopeng1@zte.com.cn> | 2019-07-08 15:18:30 +0800 |
commit | 93e2fe207d57a020fee332b16675062f25699401 (patch) | |
tree | d8d6073fbf421206dd28dae27b2c307b2f620174 | |
parent | a2034b62ab086f2bd459695401af4901ffb3ff96 (diff) |
refactor ns job test code
refactor ns job test code
Change-Id: I1009730ca9b83b000324edad1921e4015fd1c0ba
Issue-ID: VFC-1431
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r-- | lcm/jobs/tests/__init__.py | 1 | ||||
-rw-r--r-- | lcm/jobs/tests/tests.py | 94 | ||||
-rw-r--r-- | lcm/jobs/tests/update_job_bad_req.json | 5 |
3 files changed, 82 insertions, 18 deletions
diff --git a/lcm/jobs/tests/__init__.py b/lcm/jobs/tests/__init__.py index ecbf03a5..7310df45 100644 --- a/lcm/jobs/tests/__init__.py +++ b/lcm/jobs/tests/__init__.py @@ -17,3 +17,4 @@ from lcm.pub.utils import fileutil cur_path = os.path.dirname(os.path.abspath(__file__)) UPDATE_JOB_DICT = fileutil.read_json_file(cur_path + '/update_job.json') +UPDATE_JOB_BAD_REQ_DICT = fileutil.read_json_file(cur_path + '/update_job_bad_req.json') diff --git a/lcm/jobs/tests/tests.py b/lcm/jobs/tests/tests.py index 38587018..2de0c2c5 100644 --- a/lcm/jobs/tests/tests.py +++ b/lcm/jobs/tests/tests.py @@ -13,7 +13,8 @@ # limitations under the License. from django.test import TestCase -from lcm.jobs.tests import UPDATE_JOB_DICT +from lcm.jobs.enum import JOB_ACTION, JOB_STATUS, JOB_TYPE +from lcm.jobs.tests import UPDATE_JOB_DICT, UPDATE_JOB_BAD_REQ_DICT from lcm.pub.database.models import JobModel, JobStatusModel from rest_framework import status from rest_framework.test import APIClient @@ -22,8 +23,6 @@ from rest_framework.test import APIClient class JobsViewTest(TestCase): def setUp(self): self.job_id = 'test_job_id' - self.job_type = 'NS' - self.job_type = '' self.client = APIClient() JobModel.objects.all().delete() JobStatusModel.objects.all().delete() @@ -32,30 +31,59 @@ class JobsViewTest(TestCase): JobModel.objects.all().delete() JobStatusModel.objects.all().delete() - def test_job(self): - 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', errcode="0").save() + def test_query_ns_job(self): + JobModel(jobid=self.job_id, + jobtype=JOB_TYPE.NS, + jobaction=JOB_ACTION.INSTANTIATE, + resid='1').save() + JobStatusModel(indexid=1, + jobid=self.job_id, + status=JOB_STATUS.PROCESSING, + progress=20, + descp='Finish to instantiate NS.', + errcode="0").save() response = self.client.get("/api/nslcm/v1/jobs/%s" % self.job_id) self.assertEqual(status.HTTP_200_OK, response.status_code, response.data) self.assertIn('jobId', response.data) self.assertIn('responseDescriptor', response.data) self.assertEqual(20, response.data['responseDescriptor']['progress']) - 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', errcode="0").save() + def test_query_ns_job_not_existed(self): + job_id = 'test_job_id_not_existed' response = self.client.get("/api/nslcm/v1/jobs/%s" % job_id) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertIn('jobId', response.data) self.assertNotIn('responseDescriptor', response.data) def test_query_job_with_response_id(self): - 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', errcode="0").save() - JobStatusModel(indexid=2, jobid=self.job_id, status='inst', progress=50, descp='inst', errcode="0").save() - JobStatusModel(indexid=3, jobid=self.job_id, status='inst', progress=80, descp='inst', errcode="0").save() - JobStatusModel(indexid=4, jobid=self.job_id, status='inst', progress=100, descp='inst', errcode="0").save() + JobModel(jobid=self.job_id, + jobtype=JOB_TYPE.NS, + jobaction=JOB_ACTION.INSTANTIATE, + resid='1').save() + JobStatusModel(indexid=1, + jobid=self.job_id, + status=JOB_STATUS.PROCESSING, + progress=20, + descp='NS instantiation progress is 20%.', + errcode="0").save() + JobStatusModel(indexid=2, + jobid=self.job_id, + status=JOB_STATUS.PROCESSING, + progress=50, + descp='NS instantiation progress is 50%.', + errcode="0").save() + JobStatusModel(indexid=3, + jobid=self.job_id, + status=JOB_STATUS.PROCESSING, + progress=80, + descp='NS instantiation progress is 80%.', + errcode="0").save() + JobStatusModel(indexid=4, + jobid=self.job_id, + status=JOB_STATUS.FINISH, + progress=100, + descp='Finish to instantiate NS.', + errcode="0").save() response = self.client.get("/api/nslcm/v1/jobs/%s?responseId=2" % self.job_id) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.job_id, response.data.get('jobId')) @@ -63,8 +91,38 @@ class JobsViewTest(TestCase): self.assertEqual(100, response.data['responseDescriptor']['progress']) self.assertEqual(1, len(response.data['responseDescriptor']['responseHistoryList'])) - def test_up_job(self): - 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', errcode="0").save() + def test_update_job(self): + JobModel( + jobid=self.job_id, + jobtype=JOB_TYPE.NS, + jobaction=JOB_ACTION.INSTANTIATE, + resid='1').save() + JobStatusModel( + indexid=1, + jobid=self.job_id, + status=JOB_STATUS.PROCESSING, + progress=20, + descp='NS instantiation progress is 20%.', + errcode="0").save() response = self.client.post("/api/nslcm/v1/jobs/%s" % self.job_id, format='json', data=UPDATE_JOB_DICT) self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) + + def test_update_job_not_existed(self): + response = self.client.post("/api/nslcm/v1/jobs/%s" % self.job_id, format='json', data=UPDATE_JOB_DICT) + self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) + + def test_update_job_with_bad_req(self): + JobModel( + jobid=self.job_id, + jobtype=JOB_TYPE.NS, + jobaction=JOB_ACTION.INSTANTIATE, + resid='1').save() + JobStatusModel( + indexid=1, + jobid=self.job_id, + status=JOB_STATUS.PROCESSING, + progress=20, + descp='NS instantiation progress is 20%.', + errcode="0").save() + response = self.client.post("/api/nslcm/v1/jobs/%s" % self.job_id, format='json', data=UPDATE_JOB_BAD_REQ_DICT) + self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) diff --git a/lcm/jobs/tests/update_job_bad_req.json b/lcm/jobs/tests/update_job_bad_req.json new file mode 100644 index 00000000..f90e3a8a --- /dev/null +++ b/lcm/jobs/tests/update_job_bad_req.json @@ -0,0 +1,5 @@ +{ + "progressing": "100", + "desc": "completed", + "errcode": "0" +} |