Merge "Remove multisite support"
[functest-xtesting.git] / functest / api / resources / v1 / testcases.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 #
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
9
10 """
11 Resources to handle testcase related requests
12 """
13
14 from flask import abort, jsonify
15
16 from functest.api.base import ApiResource
17 from functest.api.common import api_utils
18 from functest.cli.commands.cli_testcase import Testcase
19
20
21 class V1Testcases(ApiResource):
22     """ V1Testcases Resource class"""
23
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)
29
30
31 class V1Testcase(ApiResource):
32     """ V1Testcase Resource class"""
33
34     def get(self, testcase_name):  # pylint: disable=no-self-use
35         """ GET the info of one testcase"""
36         testcase = Testcase().show(testcase_name)
37         if not testcase:
38             abort(404, "The test case '%s' does not exist or is not supported"
39                   % testcase_name)
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)