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 tier related requests
17 from flask import jsonify
18 from flasgger.utils import swag_from
20 from functest.api.base import ApiResource
21 from functest.api.common import api_utils
22 from functest.cli.commands.cli_tier import Tier
25 class V1Tiers(ApiResource):
26 """ V1Tiers Resource class """
28 @swag_from(pkg_resources.resource_filename(
29 'functest', 'api/swagger/tiers.yaml'))
31 # pylint: disable=no-self-use
33 tiers_list = Tier().list()
34 data = re.split("[\n\t]", tiers_list)
35 data = [i.strip() for i in data if i != '']
37 for i in range(len(data) / 2):
38 one_data = {data[i * 2].lstrip('- ').rstrip(':'): data[i * 2 + 1]}
42 data_dict.update(one_data)
43 result = {'tiers': data_dict}
44 return jsonify(result)
47 class V1Tier(ApiResource):
48 """ V1Tier Resource class """
50 @swag_from(pkg_resources.resource_filename(
51 'functest', 'api/swagger/tier.yaml'))
52 def get(self, tier_name): # pylint: disable=no-self-use
53 """ GET the info of one tier """
54 tier_info = Tier().show(tier_name)
56 return api_utils.result_handler(
58 data="The tier with name '%s' does not exist." % tier_name)
59 tier_info.__dict__.pop('name')
60 tier_info.__dict__.pop('tests_array')
61 tier_info.__dict__.pop('skipped_tests_array')
62 testcases = Tier().gettests(tier_name)
63 result = {'tier': tier_name, 'testcases': testcases}
64 result.update(tier_info.__dict__)
65 return jsonify(result)
68 class V1TestcasesinTier(ApiResource):
69 """ V1TestcasesinTier Resource class """
71 @swag_from(pkg_resources.resource_filename(
72 'functest', 'api/swagger/testcases_in_tier.yaml'))
73 def get(self, tier_name): # pylint: disable=no-self-use
74 """ GET all testcases within given tier """
75 tier_info = Tier().show(tier_name)
77 return api_utils.result_handler(
79 data="The tier with name '%s' does not exist." % tier_name)
80 testcases = Tier().gettests(tier_name)
81 result = {'tier': tier_name, 'testcases': testcases}
82 return jsonify(result)