1 from opnfv_testapi.common.constants import HTTP_FORBIDDEN
2 from opnfv_testapi.resources.handlers import GenericApiHandler
3 from opnfv_testapi.resources.scenario_models import Scenario
4 from opnfv_testapi.tornado_swagger import swagger
7 class GenericScenarioHandler(GenericApiHandler):
8 def __init__(self, application, request, **kwargs):
9 super(GenericScenarioHandler, self).__init__(application,
12 self.table = self.db_scenarios
13 self.table_cls = Scenario
16 class ScenariosCLHandler(GenericScenarioHandler):
17 @swagger.operation(nickname="List scenarios by queries")
20 @description: Retrieve scenario(s).
21 @notes: Retrieve scenario(s)
22 @return 200: all scenarios consist with query,
23 empty list if no scenario is found
28 @swagger.operation(nickname="Create a new scenario")
31 @description: create a new scenario by name
32 @param body: scenario to be created
33 @type body: L{ScenarioCreateRequest}
35 @rtype: L{CreateResponse}
36 @return 200: scenario is created.
37 @raise 403: scenario already exists
38 @raise 400: body or name not provided
41 return {'name': data.name}
44 message = '{} already exists as a scenario'.format(data.name)
45 return HTTP_FORBIDDEN, message
47 miss_checks = ['name']
48 db_checks = [(self.table, False, query, error)]
49 self._create(miss_checks=miss_checks, db_checks=db_checks)
52 class ScenarioGURHandler(GenericScenarioHandler):
53 @swagger.operation(nickname='Get the scenario by name')
56 @description: get a single scenario by name
58 @return 200: scenario exist
59 @raise 404: scenario not exist
63 @swagger.operation(nickname="Update the scenario by name")
66 @description: update a single scenario by name
67 @param body: fields to be updated
71 @return 200: update success
72 @raise 404: scenario not exist
73 @raise 403: nothing to update