X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Ftest%2Ftestapi%2Fopnfv_testapi%2Fresources%2Fresult_handlers.py;h=3e78057cec29c2979a56a93231494184b79b5426;hb=b9e0948256af817e63f901ec5277d3ef9fe36fdd;hp=400b84ac1d1466d754f492093b765edbd9a026f2;hpb=b31e0d80dda6dd6a346acb9d422dc80eb0c1de1c;p=releng.git diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py index 400b84ac1..3e78057ce 100644 --- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py @@ -6,30 +6,31 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from datetime import datetime, timedelta +from datetime import datetime +from datetime import timedelta +import httplib -from bson.objectid import ObjectId -from tornado.web import HTTPError +from bson import objectid -from opnfv_testapi.common.constants import HTTP_BAD_REQUEST, HTTP_NOT_FOUND -from opnfv_testapi.resources.handlers import GenericApiHandler -from opnfv_testapi.resources.result_models import TestResult +from opnfv_testapi.common import raises +from opnfv_testapi.resources import handlers +from opnfv_testapi.resources import result_models from opnfv_testapi.tornado_swagger import swagger -class GenericResultHandler(GenericApiHandler): +class GenericResultHandler(handlers.GenericApiHandler): def __init__(self, application, request, **kwargs): super(GenericResultHandler, self).__init__(application, request, **kwargs) self.table = self.db_results - self.table_cls = TestResult + self.table_cls = result_models.TestResult def get_int(self, key, value): try: value = int(value) except: - raise HTTPError(HTTP_BAD_REQUEST, '{} must be int'.format(key)) + raises.BadRequest('{} must be int'.format(key)) return value def set_query(self): @@ -52,7 +53,7 @@ class GenericResultHandler(GenericApiHandler): class ResultsCLHandler(GenericResultHandler): - @swagger.operation(nickname="list-all") + @swagger.operation(nickname="queryTestResults") def get(self): """ @description: Retrieve result(s) for a test project @@ -127,7 +128,7 @@ class ResultsCLHandler(GenericResultHandler): self._list(self.set_query(), sort=[('start_date', -1)], last=last) - @swagger.operation(nickname="create") + @swagger.operation(nickname="createTestResult") def post(self): """ @description: create a test result @@ -144,14 +145,14 @@ class ResultsCLHandler(GenericResultHandler): def pod_error(data): message = 'Could not find pod [{}]'.format(data.pod_name) - return HTTP_NOT_FOUND, message + return httplib.NOT_FOUND, message def project_query(data): return {'name': data.project_name} def project_error(data): message = 'Could not find project [{}]'.format(data.project_name) - return HTTP_NOT_FOUND, message + return httplib.NOT_FOUND, message def testcase_query(data): return {'project_name': data.project_name, 'name': data.case_name} @@ -159,7 +160,7 @@ class ResultsCLHandler(GenericResultHandler): def testcase_error(data): message = 'Could not find testcase [{}] in project [{}]'\ .format(data.case_name, data.project_name) - return HTTP_NOT_FOUND, message + return httplib.NOT_FOUND, message miss_checks = ['pod_name', 'project_name', 'case_name'] db_checks = [('pods', True, pod_query, pod_error), @@ -169,7 +170,7 @@ class ResultsCLHandler(GenericResultHandler): class ResultsGURHandler(GenericResultHandler): - @swagger.operation(nickname='get-one') + @swagger.operation(nickname='getTestResultById') def get(self, result_id): """ @description: get a single result by result_id @@ -178,10 +179,10 @@ class ResultsGURHandler(GenericResultHandler): @raise 404: test result not exist """ query = dict() - query["_id"] = ObjectId(result_id) + query["_id"] = objectid.ObjectId(result_id) self._get_one(query) - @swagger.operation(nickname="update") + @swagger.operation(nickname="updateTestResultById") def put(self, result_id): """ @description: update a single result by _id @@ -193,6 +194,6 @@ class ResultsGURHandler(GenericResultHandler): @raise 404: result not exist @raise 403: nothing to update """ - query = {'_id': ObjectId(result_id)} + query = {'_id': objectid.ObjectId(result_id)} db_keys = [] self._update(query, db_keys)