diff options
author | Serena Feng <feng.xiaowei@zte.com.cn> | 2018-01-04 08:59:41 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-01-04 08:59:41 +0000 |
commit | 8dbe224064851d439b18ad4254e119aff7f02e30 (patch) | |
tree | 939ff74837fe2593b532a455c65b06edba6ec957 /testapi/opnfv_testapi/models | |
parent | 6d98b992423084dd737e80322c9360e0712368a2 (diff) | |
parent | 8dd0bcd2e98d283619d12c9734c126b19757f065 (diff) |
Merge "simplify test_pod.py with eq"
Diffstat (limited to 'testapi/opnfv_testapi/models')
-rw-r--r-- | testapi/opnfv_testapi/models/base_models.py | 19 | ||||
-rw-r--r-- | testapi/opnfv_testapi/models/pod_models.py | 19 |
2 files changed, 17 insertions, 21 deletions
diff --git a/testapi/opnfv_testapi/models/base_models.py b/testapi/opnfv_testapi/models/base_models.py index 5017e85..efce0ad 100644 --- a/testapi/opnfv_testapi/models/base_models.py +++ b/testapi/opnfv_testapi/models/base_models.py @@ -42,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 diff --git a/testapi/opnfv_testapi/models/pod_models.py b/testapi/opnfv_testapi/models/pod_models.py index 15c2833..0eddfcc 100644 --- a/testapi/opnfv_testapi/models/pod_models.py +++ b/testapi/opnfv_testapi/models/pod_models.py @@ -18,7 +18,7 @@ from opnfv_testapi.tornado_swagger import swagger @swagger.model() class PodCreateRequest(base_models.ModelBase): - def __init__(self, name, mode='', details='', role=""): + def __init__(self, name='', mode='', details='', role=""): self.name = name self.mode = mode self.details = details @@ -26,17 +26,12 @@ class PodCreateRequest(base_models.ModelBase): @swagger.model() -class Pod(base_models.ModelBase): - def __init__(self, - name='', mode='', details='', - role="", _id='', create_date='', owner=''): - self.name = name - self.mode = mode - self.details = details - self.role = role - self._id = _id - self.creation_date = create_date - self.owner = owner +class Pod(PodCreateRequest): + def __init__(self, **kwargs): + self._id = kwargs.pop('_id', '') + self.creation_date = kwargs.pop('creation_date', '') + self.owner = kwargs.pop('owner', '') + super(Pod, self).__init__(**kwargs) @swagger.model() |