diff options
-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(): |