1 from opnfv_testapi.common.constants import HTTP_FORBIDDEN
2 from opnfv_testapi.resources.handlers import GenericApiHandler
3 from opnfv_testapi.resources.testcase_models import Testcase
4 from opnfv_testapi.tornado_swagger_ui.tornado_swagger import swagger
7 class GenericTestcaseHandler(GenericApiHandler):
8 def __init__(self, application, request, **kwargs):
9 super(GenericTestcaseHandler, self).__init__(application,
12 self.table = self.db_testcases
13 self.table_cls = Testcase
16 class TestcaseCLHandler(GenericTestcaseHandler):
17 @swagger.operation(nickname="list-all")
18 def get(self, project_name):
20 @description: list all testcases of a project by project_name
21 @return 200: return all testcases of this project,
22 empty list is no testcase exist in this project
26 query['project_name'] = project_name
29 @swagger.operation(nickname="create")
30 def post(self, project_name):
32 @description: create a testcase of a project by project_name
33 @param body: testcase to be created
34 @type body: L{TestcaseCreateRequest}
37 @return 200: testcase is created in this project.
38 @raise 403: project not exist
39 or testcase already exists in this project
40 @raise 400: body or name not provided
43 return {'name': data.project_name}
47 'project_name': data.project_name,
52 message = 'Could not find project [{}]'.format(data.project_name)
53 return HTTP_FORBIDDEN, message
56 message = '{} already exists as a testcase in project {}'\
57 .format(data.name, data.project_name)
58 return HTTP_FORBIDDEN, message
60 miss_checks = ['name']
61 db_checks = [(self.db_projects, True, p_query, p_error),
62 (self.db_testcases, False, tc_query, tc_error)]
63 self._create(miss_checks, db_checks, project_name=project_name)
66 class TestcaseGURHandler(GenericTestcaseHandler):
67 @swagger.operation(nickname='get-one')
68 def get(self, project_name, case_name):
70 @description: get a single testcase
71 by case_name and project_name
73 @return 200: testcase exist
74 @raise 404: testcase not exist
77 query['project_name'] = project_name
78 query["name"] = case_name
81 @swagger.operation(nickname="update")
82 def put(self, project_name, case_name):
84 @description: update a single testcase
85 by project_name and case_name
86 @param body: testcase to be updated
87 @type body: L{TestcaseUpdateRequest}
90 @return 200: update success
91 @raise 404: testcase or project not exist
92 @raise 403: new testcase name already exist in project
95 query = {'project_name': project_name, 'name': case_name}
96 db_keys = ['name', 'project_name']
97 self._update(query, db_keys)
99 @swagger.operation(nickname='delete')
100 def delete(self, project_name, case_name):
102 @description: delete a testcase by project_name and case_name
103 @return 200: delete success
104 @raise 404: testcase not exist
106 query = {'project_name': project_name, 'name': case_name}