diff options
author | fengyuanxing <feng.yuanxing@zte.com.cn> | 2018-01-25 15:08:34 +0800 |
---|---|---|
committer | yunlong ying <ying.yunlong@zte.com.cn> | 2018-01-25 09:36:30 +0000 |
commit | 45035b552946928d4573ff8e86c03392f88471f4 (patch) | |
tree | 08b78ae53ecc60087d5123f9af41a19317fb6c88 | |
parent | 18cbe1ff803192aacd880efb001982c6da916339 (diff) |
Add validataion code of swagger code
Change-Id: I5e829afc6fe55ccfc44b8ef8d2fae9db888f28ac
Issue-ID: VFC-677
Signed-off-by: fengyuanxing <feng.yuanxing@zte.com.cn>
-rw-r--r-- | catalog/jobs/tests/tests.py | 2 | ||||
-rw-r--r-- | catalog/jobs/views.py | 20 |
2 files changed, 16 insertions, 6 deletions
diff --git a/catalog/jobs/tests/tests.py b/catalog/jobs/tests/tests.py index 37996a05..0411c186 100644 --- a/catalog/jobs/tests/tests.py +++ b/catalog/jobs/tests/tests.py @@ -27,7 +27,7 @@ class JobsViewTest(TestCase): def test_job_normal(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').save() + JobStatusModel(indexid=1, jobid=self.job_id, status='inst', errcode='0', progress=20, descp='inst').save() response = self.client.get("/api/catalog/v1/jobs/%s" % self.job_id) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) diff --git a/catalog/jobs/views.py b/catalog/jobs/views.py index c52b8a2b..34391068 100644 --- a/catalog/jobs/views.py +++ b/catalog/jobs/views.py @@ -37,11 +37,21 @@ class JobView(APIView): @swagger_auto_schema( operation_description="Get job status", manual_parameters=[input_job_id, input_response_id], - responses={status.HTTP_200_OK: JobResponseSerializer()}) + responses={ + status.HTTP_200_OK: JobResponseSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: PostJobResponseResultSerializer() + }) def get(self, request, job_id): response_id = ignore_case_get(request.META, 'responseId') ret = GetJobInfoService(job_id, response_id).do_biz() - return Response(data=ret, status=status.HTTP_200_OK) + response_serializer = JobResponseSerializer(data=ret) + isValid = response_serializer.is_valid() + if not isValid: + message = 'Invalid resposne' + logger.error(response_serializer.errors) + return Response(data={'result': 'error', 'msg': message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + return Response(data=response_serializer.data, status=status.HTTP_200_OK) @swagger_auto_schema( request_body=PostJobRequestSerializer(), @@ -74,14 +84,14 @@ class JobView(APIView): JobUtil.add_job_status(job_id, progress, desc, error_code=errcode) response = Response(data={'result': 'ok'}, status=status.HTTP_202_ACCEPTED) - responseSerializer = PostJobResponseResultSerializer(response.data) - isValid = responseSerializer.is_valid() + response_serializer = PostJobResponseResultSerializer(data=response.data) + isValid = response_serializer.is_valid() if not isValid: message = 'Invalid resposne' logger.error(message) return Response(data={'result': 'error', 'msg': message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - return Response(data=responseSerializer.data, status=status.HTTP_202_ACCEPTED) + return Response(data=response_serializer.data, status=status.HTTP_202_ACCEPTED) except Exception as e: logger.error(e.message) logger.error(traceback.format_exc()) |