ec262aa2f9c8b1ba53a2b9b0c6c320185f9f4fc4
[releng.git] / utils / test / testapi / opnfv_testapi / resources / scenario_models.py
1 from opnfv_testapi.resources import models
2 from opnfv_testapi.tornado_swagger import swagger
3
4
5 def list_default(value):
6     return value if value else list()
7
8
9 def dict_default(value):
10     return value if value else dict()
11
12
13 @swagger.model()
14 class ScenarioTI(models.ModelBase):
15     def __init__(self, date=None, status='silver'):
16         self.date = date
17         self.status = status
18
19     def __eq__(self, other):
20         return (self.date == other.date and
21                 self.status == other.status)
22
23     def __ne__(self, other):
24         return not self.__eq__(other)
25
26
27 @swagger.model()
28 class ScenarioScore(models.ModelBase):
29     def __init__(self, date=None, score='0'):
30         self.date = date
31         self.score = score
32
33     def __eq__(self, other):
34         return (self.date == other.date and
35                 self.score == other.score)
36
37     def __ne__(self, other):
38         return not self.__eq__(other)
39
40
41 @swagger.model()
42 class ScenarioProject(models.ModelBase):
43     """
44         @property customs:
45         @ptype customs: C{list} of L{string}
46         @property scores:
47         @ptype scores: C{list} of L{ScenarioScore}
48         @property trust_indicators:
49         @ptype trust_indicators: C{list} of L{ScenarioTI}
50     """
51     def __init__(self,
52                  project='',
53                  customs=None,
54                  scores=None,
55                  trust_indicators=None):
56         self.project = project
57         self.customs = list_default(customs)
58         self.scores = list_default(scores)
59         self.trust_indicators = list_default(trust_indicators)
60
61     @staticmethod
62     def attr_parser():
63         return {'scores': ScenarioScore,
64                 'trust_indicators': ScenarioTI}
65
66     def __eq__(self, other):
67         return (self.project == other.project and
68                 self._customs_eq(other) and
69                 self._scores_eq(other) and
70                 self._ti_eq(other))
71
72     def __ne__(self, other):
73         return not self.__eq__(other)
74
75     def _customs_eq(self, other):
76         return set(self.customs) == set(other.customs)
77
78     def _scores_eq(self, other):
79         return self.scores == other.scores
80
81     def _ti_eq(self, other):
82         return self.trust_indicators == other.trust_indicators
83
84
85 @swagger.model()
86 class ScenarioVersion(models.ModelBase):
87     """
88         @property projects:
89         @ptype projects: C{list} of L{ScenarioProject}
90     """
91     def __init__(self, owner=None, version=None, projects=None):
92         self.owner = owner
93         self.version = version
94         self.projects = list_default(projects)
95
96     @staticmethod
97     def attr_parser():
98         return {'projects': ScenarioProject}
99
100     def __eq__(self, other):
101         return (self.version == other.version and
102                 self.owner == other.owner and
103                 self._projects_eq(other))
104
105     def __ne__(self, other):
106         return not self.__eq__(other)
107
108     def _projects_eq(self, other):
109         for s_project in self.projects:
110             for o_project in other.projects:
111                 if s_project.project == o_project.project:
112                     if s_project != o_project:
113                         return False
114
115         return True
116
117
118 @swagger.model()
119 class ScenarioInstaller(models.ModelBase):
120     """
121         @property versions:
122         @ptype versions: C{list} of L{ScenarioVersion}
123     """
124     def __init__(self, installer=None, versions=None):
125         self.installer = installer
126         self.versions = list_default(versions)
127
128     @staticmethod
129     def attr_parser():
130         return {'versions': ScenarioVersion}
131
132     def __eq__(self, other):
133         return (self.installer == other.installer and self._versions_eq(other))
134
135     def __ne__(self, other):
136         return not self.__eq__(other)
137
138     def _versions_eq(self, other):
139         for s_version in self.versions:
140             for o_version in other.versions:
141                 if s_version.version == o_version.version:
142                     if s_version != o_version:
143                         return False
144
145         return True
146
147
148 @swagger.model()
149 class ScenarioCreateRequest(models.ModelBase):
150     """
151         @property installers:
152         @ptype installers: C{list} of L{ScenarioInstaller}
153     """
154     def __init__(self, name='', installers=None):
155         self.name = name
156         self.installers = list_default(installers)
157
158     @staticmethod
159     def attr_parser():
160         return {'installers': ScenarioInstaller}
161
162
163 @swagger.model()
164 class Scenario(models.ModelBase):
165     """
166         @property installers:
167         @ptype installers: C{list} of L{ScenarioInstaller}
168     """
169     def __init__(self, name='', create_date='', _id='', installers=None):
170         self.name = name
171         self._id = _id
172         self.creation_date = create_date
173         self.installers = list_default(installers)
174
175     @staticmethod
176     def attr_parser():
177         return {'installers': ScenarioInstaller}
178
179     def __ne__(self, other):
180         return not self.__eq__(other)
181
182     def __eq__(self, other):
183         return (self.name == other.name and self._installers_eq(other))
184
185     def _installers_eq(self, other):
186         for s_install in self.installers:
187             for o_install in other.installers:
188                 if s_install.installer == o_install.installer:
189                     if s_install != o_install:
190                         return False
191
192         return True
193
194
195 @swagger.model()
196 class Scenarios(models.ModelBase):
197     """
198         @property scenarios:
199         @ptype scenarios: C{list} of L{Scenario}
200     """
201     def __init__(self):
202         self.scenarios = list()
203
204     @staticmethod
205     def attr_parser():
206         return {'scenarios': Scenario}