aboutsummaryrefslogtreecommitdiffstats
path: root/ci/tier_handler.py
blob: 0b7559498660bc613ef70d76782f0662d055435e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
#
# jose.lausuch@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
#


import re


class Tier:
    def __init__(self, name, order, ci, description=""):
        self.tests_array = []
        self.name = name
        self.order = order
        self.ci = ci
        self.description = description

    def add_test(self, testcase):
        self.tests_array.append(testcase)

    def get_tests(self):
        array_str = []
        for test in self.tests_array:
            array_str.append(test.name)
        return array_str

    def __str__(self):
        return ("Tier info:\n"
                "    Name: " + self.name + "\n"
                "    Description: " + self.description + "\n"
                "    Order: " + str(self.order) + "\n"
                "    Test cases: " + str(self.get_tests()) + "\n")


class TestCase:
    def __init__(self, name, dependency, description=""):
        self.name = name
        self.dependency = dependency
        self.description = description

    def is_compatible(self, ci_installer, ci_scenario):
        if re.search(self.dependency.get_installer(), ci_installer) is None:
            return False

        if re.search(self.dependency.get_scenario(), ci_scenario) is None:
            return False

        return True

    def __str__(self):
        return ("Testcase info:\n"
                "    Name: " + self.name + "\n"
                "    Description: " + self.description + "\n"
                "    " + str(self.dependency) + "\n")


class Dependency:
    def __init__(self, installer, scenario):
        self.installer = installer
        self.scenario = scenario

    def get_installer(self):
        return self.installer

    def get_scenario(self):
        return self.scenario

    def __str__(self):
        return ("Dependency info:\n"
                "        installer: " + self.installer + "\n"
                "        scenario:  " + self.scenario + "\n")