3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
11 Resources to handle testcase related requests
14 from flask import abort, jsonify
16 from functest.api.base import ApiResource
17 from functest.api.common import api_utils
18 from functest.cli.commands.cli_testcase import Testcase
21 class V1Testcases(ApiResource):
22 """ V1Testcases Resource class"""
24 def get(self): # pylint: disable=no-self-use
25 """ GET all testcases """
26 testcases_list = Testcase().list()
27 result = {'testcases': testcases_list.split('\n')[:-1]}
28 return jsonify(result)
31 class V1Testcase(ApiResource):
32 """ V1Testcase Resource class"""
34 def get(self, testcase_name): # pylint: disable=no-self-use
35 """ GET the info of one testcase"""
36 testcase = Testcase().show(testcase_name)
38 abort(404, "The test case '%s' does not exist or is not supported"
40 testcase_info = api_utils.change_obj_to_dict(testcase)
41 dependency_dict = api_utils.change_obj_to_dict(
42 testcase_info.get('dependency'))
43 testcase_info.pop('name')
44 testcase_info.pop('dependency')
45 result = {'testcase': testcase_name}
46 result.update(testcase_info)
47 result.update({'dependency': dependency_dict})
48 return jsonify(result)