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.resources import handlers
12 from opnfv_testapi.resources import testcase_models
13 from opnfv_testapi.tornado_swagger import swagger
16 class GenericTestcaseHandler(handlers.GenericApiHandler):
17 def __init__(self, application, request, **kwargs):
18 super(GenericTestcaseHandler, self).__init__(application,
21 self.table = self.db_testcases
22 self.table_cls = testcase_models.Testcase
25 class TestcaseCLHandler(GenericTestcaseHandler):
26 @swagger.operation(nickname="listAllTestCases")
27 def get(self, project_name):
29 @description: list all testcases of a project by project_name
30 @return 200: return all testcases of this project,
31 empty list is no testcase exist in this project
35 query['project_name'] = project_name
38 @swagger.operation(nickname="createTestCase")
39 def post(self, project_name):
41 @description: create a testcase of a project by project_name
42 @param body: testcase to be created
43 @type body: L{TestcaseCreateRequest}
45 @rtype: L{CreateResponse}
46 @return 200: testcase is created in this project.
47 @raise 403: project not exist
48 or testcase already exists in this project
49 @raise 400: body or name not provided
52 return {'name': data.project_name}
56 'project_name': data.project_name,
61 message = 'Could not find project [{}]'.format(data.project_name)
62 return httplib.FORBIDDEN, message
65 message = '{} already exists as a testcase in project {}'\
66 .format(data.name, data.project_name)
67 return httplib.FORBIDDEN, message
69 miss_checks = ['name']
70 db_checks = [(self.db_projects, True, p_query, p_error),
71 (self.db_testcases, False, tc_query, tc_error)]
72 self._create(miss_checks, db_checks, project_name=project_name)
75 class TestcaseGURHandler(GenericTestcaseHandler):
76 @swagger.operation(nickname='getTestCaseByName')
77 def get(self, project_name, case_name):
79 @description: get a single testcase
80 by case_name and project_name
82 @return 200: testcase exist
83 @raise 404: testcase not exist
86 query['project_name'] = project_name
87 query["name"] = case_name
90 @swagger.operation(nickname="updateTestCaseByName")
91 def put(self, project_name, case_name):
93 @description: update a single testcase
94 by project_name and case_name
95 @param body: testcase to be updated
96 @type body: L{TestcaseUpdateRequest}
99 @return 200: update success
100 @raise 404: testcase or project not exist
101 @raise 403: new testcase name already exist in project
104 query = {'project_name': project_name, 'name': case_name}
105 db_keys = ['name', 'project_name']
106 self._update(query, db_keys)
108 @swagger.operation(nickname='deleteTestCaseByName')
109 def delete(self, project_name, case_name):
111 @description: delete a testcase by project_name and case_name
112 @return 200: delete success
113 @raise 404: testcase not exist
115 query = {'project_name': project_name, 'name': case_name}