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
16 from flask import jsonify
18 from functest.api.base import ApiResource
19 from functest.api.common import api_utils
20 from functest.cli.commands.cli_tier import Tier
23 class V1Tiers(ApiResource):
24 """ V1Tiers Resource class """
27 # pylint: disable=no-self-use
29 tiers_list = Tier().list()
30 data = re.split("[\n\t]", tiers_list)
31 data = [i.strip() for i in data if i != '']
33 for i in range(len(data) / 2):
34 one_data = {data[i * 2].lstrip('- ').rstrip(':'): data[i * 2 + 1]}
38 data_dict.update(one_data)
39 result = {'tiers': data_dict}
40 return jsonify(result)
43 class V1Tier(ApiResource):
44 """ V1Tier Resource class """
46 def get(self, tier_name): # pylint: disable=no-self-use
47 """ GET the info of one tier """
48 tier_info = Tier().show(tier_name)
50 return api_utils.result_handler(
52 data="The tier with name '%s' does not exist." % tier_name)
53 tier_info.__dict__.pop('name')
54 tier_info.__dict__.pop('tests_array')
55 tier_info.__dict__.pop('skipped_tests_array')
56 testcases = Tier().gettests(tier_name)
57 result = {'tier': tier_name, 'testcases': testcases}
58 result.update(tier_info.__dict__)
59 return jsonify(result)
62 class V1TestcasesinTier(ApiResource):
63 """ V1TestcasesinTier Resource class """
65 def get(self, tier_name): # pylint: disable=no-self-use
66 """ GET all testcases within given tier """
67 tier_info = Tier().show(tier_name)
69 return api_utils.result_handler(
71 data="The tier with name '%s' does not exist." % tier_name)
72 testcases = Tier().gettests(tier_name)
73 result = {'tier': tier_name, 'testcases': testcases}
74 return jsonify(result)