diff options
Diffstat (limited to 'testapi/opnfv_testapi/models/base_models.py')
-rw-r--r-- | testapi/opnfv_testapi/models/base_models.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/testapi/opnfv_testapi/models/base_models.py b/testapi/opnfv_testapi/models/base_models.py index 27396d1..efce0ad 100644 --- a/testapi/opnfv_testapi/models/base_models.py +++ b/testapi/opnfv_testapi/models/base_models.py @@ -22,6 +22,12 @@ from opnfv_testapi.tornado_swagger import swagger class ModelBase(object): + def __eq__(self, other): + res = all(getattr(self, k) == getattr(other, k) + for k in self.format().keys() + if k not in ['_id', 'creation_date']) + return res + def format(self): return self._format(['_id']) @@ -36,15 +42,16 @@ class ModelBase(object): attr_parser = cls.attr_parser() t = cls() for k, v in a_dict.iteritems(): - value = v - if isinstance(v, dict) and k in attr_parser: - value = attr_parser[k].from_dict(v) - elif isinstance(v, list) and k in attr_parser: - value = [] - for item in v: - value.append(attr_parser[k].from_dict(item)) - - t.__setattr__(k, value) + if k in t.__dict__: + value = v + if isinstance(v, dict) and k in attr_parser: + value = attr_parser[k].from_dict(v) + elif isinstance(v, list) and k in attr_parser: + value = [] + for item in v: + value.append(attr_parser[k].from_dict(item)) + + t.__setattr__(k, value) return t |