diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2018-08-21 11:45:51 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2018-08-21 14:17:53 +0800 |
commit | 69defa08462cb4aab5de6d6bee2b4b11705ac57d (patch) | |
tree | 952e69fb8cf83914463f4f9cc4ebdf733df0a4e6 | |
parent | a39731252723f9d9f411aa17e7b65c0685b4489e (diff) |
Add unit test for job query of nslcm
Change-Id: I1e40c33d137e6e56fc12098d23227f3813d97487
Issue-ID: VFC-1009
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/jobs/tests/tests.py | 21 | ||||
-rw-r--r-- | lcm/jobs/views.py | 3 |
2 files changed, 20 insertions, 4 deletions
diff --git a/lcm/jobs/tests/tests.py b/lcm/jobs/tests/tests.py index fb260742..0e2f0c49 100644 --- a/lcm/jobs/tests/tests.py +++ b/lcm/jobs/tests/tests.py @@ -11,7 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from django.test import TestCase, Client +from django.test import TestCase +from rest_framework.test import APIClient from rest_framework import status from lcm.pub.database.models import JobModel, JobStatusModel @@ -20,10 +21,13 @@ from lcm.pub.database.models import JobModel, JobStatusModel class JobsViewTest(TestCase): def setUp(self): self.job_id = 'test_job_id' - self.client = Client() + self.client = APIClient() + JobModel.objects.all().delete() + JobStatusModel.objects.all().delete() def tearDown(self): JobModel.objects.all().delete() + JobStatusModel.objects.all().delete() def test_job(self): JobModel(jobid=self.job_id, jobtype='VNF', jobaction='INST', resid='1').save() @@ -42,3 +46,16 @@ class JobsViewTest(TestCase): 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() + 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')) + self.assertIn('responseDescriptor', response.data) + self.assertEqual(100, response.data['responseDescriptor']['progress']) + self.assertEqual(1, len(response.data['responseDescriptor']['responseHistoryList'])) diff --git a/lcm/jobs/views.py b/lcm/jobs/views.py index 9ba19f3a..9f403930 100644 --- a/lcm/jobs/views.py +++ b/lcm/jobs/views.py @@ -22,7 +22,6 @@ from drf_yasg.utils import swagger_auto_schema from lcm.jobs.job_get import GetJobInfoService from lcm.pub.utils.jobutil import JobUtil -from lcm.pub.utils.values import ignore_case_get from lcm.jobs.serializers import JobUpdReqSerializer, JobUpdRespSerializer from lcm.jobs.serializers import JobQueryRespSerializer from lcm.pub.exceptions import NSLCMException @@ -46,7 +45,7 @@ class JobView(APIView): ) def get(self, request, job_id): try: - response_id = ignore_case_get(request.META, 'responseId') + response_id = int(request.GET.get('responseId', 0)) ret = GetJobInfoService(job_id, response_id).do_biz() # resp_serializer = JobQueryRespSerializer(data=ret) # if not resp_serializer.is_valid(): |