1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
12 from flask import request
13 from flask_restful import Resource
14 from flasgger.utils import swag_from
16 from api.utils import common as common_utils
17 from api.swagger import models
18 from api.actions import test as test_action
19 from api.actions import samples as samples_action
20 from api.actions import result as result_action
21 from api.actions import env as env_action
23 logger = logging.getLogger(__name__)
26 TestCaseActionModel = models.TestCaseActionModel
27 TestCaseActionArgsModel = models.TestCaseActionArgsModel
28 TestCaseActionArgsOptsModel = models.TestCaseActionArgsOptsModel
29 TestCaseActionArgsOptsTaskArgModel = models.TestCaseActionArgsOptsTaskArgModel
32 class Release(Resource):
33 @swag_from(os.getcwd() + '/swagger/docs/testcases.yaml')
35 action = common_utils.translate_to_str(request.json.get('action', ''))
36 args = common_utils.translate_to_str(request.json.get('args', {}))
37 logger.debug('Input args is: action: %s, args: %s', action, args)
40 return getattr(test_action, action)(args)
41 except AttributeError:
42 return common_utils.error_handler('Wrong action')
45 class Samples(Resource):
47 action = common_utils.translate_to_str(request.json.get('action', ''))
48 args = common_utils.translate_to_str(request.json.get('args', {}))
49 logger.debug('Input args is: action: %s, args: %s', action, args)
52 return getattr(samples_action, action)(args)
53 except AttributeError:
54 return common_utils.error_handler('Wrong action')
57 ResultModel = models.ResultModel
60 class Results(Resource):
61 @swag_from(os.getcwd() + '/swagger/docs/results.yaml')
63 args = common_utils.translate_to_str(request.args)
64 action = args.get('action', '')
65 logger.debug('Input args is: action: %s, args: %s', action, args)
68 return getattr(result_action, action)(args)
69 except AttributeError:
70 return common_utils.error_handler('Wrong action')
75 action = common_utils.translate_to_str(request.json.get('action', ''))
76 args = common_utils.translate_to_str(request.json.get('args', {}))
77 logger.debug('Input args is: action: %s, args: %s', action, args)
80 return getattr(env_action, action)(args)
81 except AttributeError:
82 return common_utils.error_handler('Wrong action')