1 from opnfv_testapi.resources import models
2 from opnfv_testapi.tornado_swagger import swagger
5 def list_default(value):
6 return value if value else list()
9 def dict_default(value):
10 return value if value else dict()
14 class ScenarioTI(models.ModelBase):
15 def __init__(self, date=None, status='silver'):
21 class ScenarioScore(models.ModelBase):
22 def __init__(self, date=None, score='0'):
28 class ScenarioProject(models.ModelBase):
31 @ptype customs: C{list} of L{string}
33 @ptype scores: C{list} of L{ScenarioScore}
34 @property trust_indicators:
35 @ptype trust_indicators: C{list} of L{ScenarioTI}
41 trust_indicators=None):
42 self.project = project
43 self.customs = list_default(customs)
44 self.scores = list_default(scores)
45 self.trust_indicators = list_default(trust_indicators)
49 return {'scores': ScenarioScore,
50 'trust_indicators': ScenarioTI}
52 def __eq__(self, other):
53 return [self.project == other.project and
54 self._customs_eq(other) and
55 self._scores_eq(other) and
58 def __ne__(self, other):
59 return not self.__eq__(other)
61 def _customs_eq(self, other):
62 return set(self.customs) == set(other.customs)
64 def _scores_eq(self, other):
65 return set(self.scores) == set(other.scores)
67 def _ti_eq(self, other):
68 return set(self.trust_indicators) == set(other.trust_indicators)
72 class ScenarioVersion(models.ModelBase):
75 @ptype projects: C{list} of L{ScenarioProject}
77 def __init__(self, version=None, projects=None):
78 self.version = version
79 self.projects = list_default(projects)
83 return {'projects': ScenarioProject}
85 def __eq__(self, other):
86 return [self.version == other.version and self._projects_eq(other)]
88 def __ne__(self, other):
89 return not self.__eq__(other)
91 def _projects_eq(self, other):
92 for s_project in self.projects:
93 for o_project in other.projects:
94 if s_project.project == o_project.project:
95 if s_project != o_project:
102 class ScenarioInstaller(models.ModelBase):
105 @ptype versions: C{list} of L{ScenarioVersion}
107 def __init__(self, installer=None, versions=None):
108 self.installer = installer
109 self.versions = list_default(versions)
113 return {'versions': ScenarioVersion}
115 def __eq__(self, other):
116 return [self.installer == other.installer and self._versions_eq(other)]
118 def __ne__(self, other):
119 return not self.__eq__(other)
121 def _versions_eq(self, other):
122 for s_version in self.versions:
123 for o_version in other.versions:
124 if s_version.version == o_version.version:
125 if s_version != o_version:
132 class ScenarioCreateRequest(models.ModelBase):
134 @property installers:
135 @ptype installers: C{list} of L{ScenarioInstaller}
137 def __init__(self, name='', installers=None):
139 self.installers = list_default(installers)
143 return {'installers': ScenarioInstaller}
147 class Scenario(models.ModelBase):
149 @property installers:
150 @ptype installers: C{list} of L{ScenarioInstaller}
152 def __init__(self, name='', create_date='', _id='', installers=None):
155 self.creation_date = create_date
156 self.installers = list_default(installers)
160 return {'installers': ScenarioInstaller}
162 def __ne__(self, other):
163 return not self.__eq__(other)
165 def __eq__(self, other):
166 return [self.name == other.name and self._installers_eq(other)]
168 def _installers_eq(self, other):
169 for s_install in self.installers:
170 for o_install in other.installers:
171 if s_install.installer == o_install.installer:
172 if s_install != o_install:
179 class Scenarios(models.ModelBase):
182 @ptype scenarios: C{list} of L{Scenario}
185 self.scenarios = list()
189 return {'scenarios': Scenario}