1 ##############################################################################
2 # Copyright (c) 2015 Orange
3 # guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from opnfv_testapi.common import message
12 from opnfv_testapi.resources import handlers
13 from opnfv_testapi.resources import testcase_models
14 from opnfv_testapi.tornado_swagger import swagger
17 class GenericTestcaseHandler(handlers.GenericApiHandler):
18 def __init__(self, application, request, **kwargs):
19 super(GenericTestcaseHandler, self).__init__(application,
22 self.table = self.db_testcases
23 self.table_cls = testcase_models.Testcase
26 class TestcaseCLHandler(GenericTestcaseHandler):
27 @swagger.operation(nickname="listAllTestCases")
28 def get(self, project_name):
30 @description: list all testcases of a project by project_name
31 @return 200: return all testcases of this project,
32 empty list is no testcase exist in this project
36 query['project_name'] = project_name
39 @swagger.operation(nickname="createTestCase")
40 def post(self, project_name):
42 @description: create a testcase of a project by project_name
43 @param body: testcase to be created
44 @type body: L{TestcaseCreateRequest}
46 @rtype: L{CreateResponse}
47 @return 200: testcase is created in this project.
48 @raise 403: project not exist
49 or testcase already exists in this project
50 @raise 400: body or name not provided
53 return {'name': data.project_name}
57 'project_name': data.project_name,
62 return httplib.FORBIDDEN, message.not_found('project',
66 return httplib.FORBIDDEN, message.exist('testcase', data.name)
68 miss_checks = ['name']
69 db_checks = [(self.db_projects, True, p_query, p_error),
70 (self.db_testcases, False, tc_query, tc_error)]
71 self._create(miss_checks, db_checks, project_name=project_name)
74 class TestcaseGURHandler(GenericTestcaseHandler):
75 @swagger.operation(nickname='getTestCaseByName')
76 def get(self, project_name, case_name):
78 @description: get a single testcase
79 by case_name and project_name
81 @return 200: testcase exist
82 @raise 404: testcase not exist
85 query['project_name'] = project_name
86 query["name"] = case_name
89 @swagger.operation(nickname="updateTestCaseByName")
90 def put(self, project_name, case_name):
92 @description: update a single testcase
93 by project_name and case_name
94 @param body: testcase to be updated
95 @type body: L{TestcaseUpdateRequest}
98 @return 200: update success
99 @raise 404: testcase or project not exist
100 @raise 403: new testcase name already exist in project
103 query = {'project_name': project_name, 'name': case_name}
104 db_keys = ['name', 'project_name']
105 self._update(query, db_keys)
107 @swagger.operation(nickname='deleteTestCaseByName')
108 def delete(self, project_name, case_name):
110 @description: delete a testcase by project_name and case_name
111 @return 200: delete success
112 @raise 404: testcase not exist
114 query = {'project_name': project_name, 'name': case_name}