1 from common.constants import HTTP_FORBIDDEN
2 from resources.handlers import GenericApiHandler
3 from resources.testcase_models import Testcase
4 from 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: post without body
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 db_checks = [(self.db_projects, True, p_query, p_error),
61 (self.db_testcases, False, tc_query, tc_error)]
62 self._create(db_checks, project_name=project_name)
65 class TestcaseGURHandler(GenericTestcaseHandler):
66 @swagger.operation(nickname='get-one')
67 def get(self, project_name, case_name):
69 @description: get a single testcase
70 by case_name and project_name
72 @return 200: testcase exist
73 @raise 404: testcase not exist
76 query['project_name'] = project_name
77 query["name"] = case_name
80 @swagger.operation(nickname="update")
81 def put(self, project_name, case_name):
83 @description: update a single testcase
84 by project_name and case_name
85 @param body: testcase to be updated
86 @type body: L{TestcaseUpdateRequest}
89 @return 200: update success
90 @raise 404: testcase or project not exist
91 @raise 403: new testcase name already exist in project
94 query = {'project_name': project_name, 'name': case_name}
95 db_keys = ['name', 'project_name']
96 self._update(query, db_keys)
98 @swagger.operation(nickname='delete')
99 def delete(self, project_name, case_name):
101 @description: delete a testcase by project_name and case_name
102 @return 200: delete success
103 @raise 404: testcase not exist
105 query = {'project_name': project_name, 'name': case_name}