summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2017-03-02 12:40:58 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-03-02 12:40:58 +0000
commit6a10e916010638b5edf223d9f112d0d269b25717 (patch)
tree05f969a8ec6bda34becd55e370c0b04b0daad451 /utils/test/testapi
parent7a8a2592e4feae43e91d8ca6835c29b72e9fcc53 (diff)
parentddcb4fa5ac0a98185a2cde5b10671c573704e0a7 (diff)
Merge "bugfix unittest test_queryProject occasionally failed in TestAPI"
Diffstat (limited to 'utils/test/testapi')
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_models.py63
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py8
2 files changed, 67 insertions, 4 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
index 73bcbe99e..b84accf4d 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
@@ -49,6 +49,24 @@ class ScenarioProject(models.ModelBase):
return {'scores': ScenarioScore,
'trust_indicators': ScenarioTI}
+ def __eq__(self, other):
+ return [self.project == other.project and
+ self._customs_eq(other) and
+ self._scores_eq(other) and
+ self._ti_eq(other)]
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def _customs_eq(self, other):
+ return set(self.customs) == set(other.customs)
+
+ def _scores_eq(self, other):
+ return set(self.scores) == set(other.scores)
+
+ def _ti_eq(self, other):
+ return set(self.trust_indicators) == set(other.trust_indicators)
+
@swagger.model()
class ScenarioVersion(models.ModelBase):
@@ -64,6 +82,21 @@ class ScenarioVersion(models.ModelBase):
def attr_parser():
return {'projects': ScenarioProject}
+ def __eq__(self, other):
+ return [self.version == other.version and self._projects_eq(other)]
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def _projects_eq(self, other):
+ for s_project in self.projects:
+ for o_project in other.projects:
+ if s_project.project == o_project.project:
+ if s_project != o_project:
+ return False
+
+ return True
+
@swagger.model()
class ScenarioInstaller(models.ModelBase):
@@ -79,6 +112,21 @@ class ScenarioInstaller(models.ModelBase):
def attr_parser():
return {'versions': ScenarioVersion}
+ def __eq__(self, other):
+ return [self.installer == other.installer and self._versions_eq(other)]
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def _versions_eq(self, other):
+ for s_version in self.versions:
+ for o_version in other.versions:
+ if s_version.version == o_version.version:
+ if s_version != o_version:
+ return False
+
+ return True
+
@swagger.model()
class ScenarioCreateRequest(models.ModelBase):
@@ -126,6 +174,21 @@ class Scenario(models.ModelBase):
def attr_parser():
return {'installers': ScenarioInstaller}
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __eq__(self, other):
+ return [self.name == other.name and self._installers_eq(other)]
+
+ def _installers_eq(self, other):
+ for s_install in self.installers:
+ for o_install in other.installers:
+ if s_install.installer == o_install.installer:
+ if s_install != o_install:
+ return False
+
+ return True
+
@swagger.model()
class Scenarios(models.ModelBase):
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py
index f604c5750..7a6e94a93 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py
@@ -39,10 +39,10 @@ class TestScenarioBase(base.TestBase):
self.assertEqual(code, constants.HTTP_OK)
if req is None:
req = self.req_d
- scenario_dict = scenario.format_http()
- self.assertIsNotNone(scenario_dict['_id'])
- self.assertIsNotNone(scenario_dict['creation_date'])
- self.assertDictContainsSubset(req, scenario_dict)
+ self.assertIsNotNone(scenario._id)
+ self.assertIsNotNone(scenario.creation_date)
+
+ scenario == models.Scenario.from_dict(req)
@staticmethod
def _set_query(*args):