diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-08-18 18:01:14 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-08-21 17:18:51 +0800 |
commit | 13b7ba7e2976ddbafb0dfa7b8bee6a3351c1f187 (patch) | |
tree | f1d6922bdabd3b4adabe999230438139bf21b36c /utils/test/testapi/opnfv_testapi/resources/models.py | |
parent | d9950c167886a2df6684de313d95f5aa3f8d89ed (diff) |
update projects in scenario
1. post, add one or more new projects
2. update, replace existed projects wholly
3. delete, delete one or more projects by name
4. in post&update, if schema is not consistent with ScenarioProject model,
BadRequest will be raised(only extra keys will be detected currently)
5. in post, if project already exist, return Conflict with already exist
message
Change-Id: Iead585f787a4acc61abce6c9d38a036739b498d6
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/resources/models.py')
-rw-r--r-- | utils/test/testapi/opnfv_testapi/resources/models.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/models.py b/utils/test/testapi/opnfv_testapi/resources/models.py index e8fc532b7..6f04cc236 100644 --- a/utils/test/testapi/opnfv_testapi/resources/models.py +++ b/utils/test/testapi/opnfv_testapi/resources/models.py @@ -48,6 +48,29 @@ class ModelBase(object): return t + @classmethod + def from_dict_with_raise(cls, a_dict): + if a_dict is None: + return None + + attr_parser = cls.attr_parser() + t = cls() + for k, v in a_dict.iteritems(): + if k not in t.__dict__: + raise AttributeError( + '{} has no attribute {}'.format(cls.__name__, k)) + 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 + @staticmethod def attr_parser(): return {} |