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 ##############################################################################
9 from opnfv_testapi.common.constants import HTTP_FORBIDDEN
10 from opnfv_testapi.resources.handlers import GenericApiHandler
11 from opnfv_testapi.resources.testcase_models import Testcase
12 from opnfv_testapi.tornado_swagger import swagger
15 class GenericTestcaseHandler(GenericApiHandler):
16 def __init__(self, application, request, **kwargs):
17 super(GenericTestcaseHandler, self).__init__(application,
20 self.table = self.db_testcases
21 self.table_cls = Testcase
24 class TestcaseCLHandler(GenericTestcaseHandler):
25 @swagger.operation(nickname="list-all")
26 def get(self, project_name):
28 @description: list all testcases of a project by project_name
29 @return 200: return all testcases of this project,
30 empty list is no testcase exist in this project
34 query['project_name'] = project_name
37 @swagger.operation(nickname="create")
38 def post(self, project_name):
40 @description: create a testcase of a project by project_name
41 @param body: testcase to be created
42 @type body: L{TestcaseCreateRequest}
45 @return 200: testcase is created in this project.
46 @raise 403: project not exist
47 or testcase already exists in this project
48 @raise 400: body or name not provided
51 return {'name': data.project_name}
55 'project_name': data.project_name,
60 message = 'Could not find project [{}]'.format(data.project_name)
61 return HTTP_FORBIDDEN, message
64 message = '{} already exists as a testcase in project {}'\
65 .format(data.name, data.project_name)
66 return HTTP_FORBIDDEN, message
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='get-one')
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="update")
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='delete')
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}