diff options
author | Asteroide <thomas.duval@orange.com> | 2018-10-05 15:01:17 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-10-05 15:01:17 +0000 |
commit | cbea4e360e9bfaa9698cf7c61c83c96a1ba89b8c (patch) | |
tree | a8bf6a7bfb06605ed5bfab77570afbe1e46cff4b /python_moonclient/python_moonclient/core/check_tools.py | |
parent | a3f68df52836676b23ac0f5e3d8c40c957ee80a7 (diff) | |
parent | 2e35a7e46f0929438c1c206e3116caa829f07dc6 (diff) |
Merge "Update code to 4.6 official version"
Diffstat (limited to 'python_moonclient/python_moonclient/core/check_tools.py')
-rw-r--r-- | python_moonclient/python_moonclient/core/check_tools.py | 127 |
1 files changed, 87 insertions, 40 deletions
diff --git a/python_moonclient/python_moonclient/core/check_tools.py b/python_moonclient/python_moonclient/core/check_tools.py index 8138f54e..381e92c7 100644 --- a/python_moonclient/python_moonclient/core/check_tools.py +++ b/python_moonclient/python_moonclient/core/check_tools.py @@ -10,16 +10,19 @@ def check_optionnal_result(result): def check_result(result): if type(result) is not dict or "result" not in result: - raise MoonCliException("Unexpected request result. It should be a dictionnary with a 'result' entry") + raise MoonCliException( + "Unexpected request result. It should be a dictionnary with a 'result' entry") if result["result"] is None: raise MoonCliException("Unexpected request result. The 'result' entry shall not be null") def _check_generic_in_result(field, result, check_not_null=False): if type(field) is not str or type(result) is not dict or field not in result: - raise MoonCliException("Unexpected request result. It should be a dictionnary with a '{}' entry".format(field)) + raise MoonCliException( + "Unexpected request result. It should be a dictionnary with a '{}' entry".format(field)) if check_not_null is True and result[field] is None: - raise MoonCliException("Unexpected request result. The '{}' entry shall not be null".format(field)) + raise MoonCliException( + "Unexpected request result. The '{}' entry shall not be null".format(field)) def check_slaves_in_result(result): @@ -93,13 +96,17 @@ def check_pdp_id(pdp_id, result): def _check_generic_name(field, name, field_elt_id, result, do_check_name=True): if type(field) is str: if result[field] is None: - raise MoonCliException("Unexpected request result : {} shall not be empty".format(field)) + raise MoonCliException( + "Unexpected request result : {} shall not be empty".format(field)) if field_elt_id not in result[field]: raise MoonCliException("Unexpected request result. Unknown {} id".format(field)) if "name" not in result[field][field_elt_id]: - raise MoonCliException("Unexpected request result : {} with id {} has no name".format(field, field_elt_id)) + raise MoonCliException( + "Unexpected request result : {} with id {} has no name".format(field, field_elt_id)) if do_check_name and name != result[field][field_elt_id]["name"]: - raise MoonCliException("Unexpected request result : {} with id {} has a bad name. Expected {}".format(field, field_elt_id, name)) + raise MoonCliException( + "Unexpected request result : {} with id {} has a bad name. Expected {}".format( + field, field_elt_id, name)) def check_model_name(name, model_id, result, do_check_name): @@ -159,7 +166,9 @@ def check_acat_id_in_dict(acat_id, in_dict): def check_policy_id_in_pipeline(policy_id, pipeline): if policy_id not in pipeline: - raise MoonCliException("Unexpected request result. The policy id {} shall be in the pipeline".format(policy_id)) + raise MoonCliException( + "Unexpected request result. The policy id {} shall be in the pipeline".format( + policy_id)) def _check_generic_policy_in_dict(field, policy_id, in_dict): @@ -167,10 +176,12 @@ def _check_generic_policy_in_dict(field, policy_id, in_dict): if policy_id is not None: if "policy_list" not in in_dict: raise MoonCliException( - "Unexpected request result. The policy list of the {} shall not be empty".format(field)) + "Unexpected request result. The policy list of the {} shall not be empty".format( + field)) if policy_id not in in_dict["policy_list"]: raise MoonCliException( - "Unexpected request result. The policy with id {} shall be in the {}".format(policy_id, field)) + "Unexpected request result. The policy with id {} shall be in the {}".format( + policy_id, field)) def check_subject_policy(policy_id, in_dict): @@ -188,14 +199,19 @@ def check_action_policy(policy_id, in_dict): def _check_generic_elt_id(field1, field1_id, field2, field2_id, result): if type(field1) is str and type(field2) is str: if result[field1] is None: - raise MoonCliException("Unexpected request result: {} shall not be empty".format(field1)) + raise MoonCliException( + "Unexpected request result: {} shall not be empty".format(field1)) if field1_id not in result[field1]: raise MoonCliException("Unexpected request result. Unknown {} with id".format(field1)) if field2 not in result[field1][field1_id]: - raise MoonCliException("Unexpected request result. {} element with id {} has no {} field".format(field1, field1_id, field2)) + raise MoonCliException( + "Unexpected request result. {} element with id {} has no {} field".format(field1, + field1_id, + field2)) if field2_id != result[field1][field1_id][field2]: raise MoonCliException( - "Unexpected request result. {} element with id {} has a bad {} id. Expected {}".format(field1, field1_id, field2, field2_id)) + "Unexpected request result. {} element with id {} has a bad {} id. Expected {}".format( + field1, field1_id, field2, field2_id)) def check_policy_model_id(model_id, policy_id, result): @@ -213,7 +229,8 @@ def check_subject_description(description, in_dict): "Unexpected request result. The description of the subject shall not be empty") if description not in in_dict["description"]: raise MoonCliException( - "Unexpected request result. The description {} shall be in the subject".format(description)) + "Unexpected request result. The description {} shall be in the subject".format( + description)) def check_meta_rules_list_in_model(meta_rule_list, model_id, result): @@ -222,9 +239,13 @@ def check_meta_rules_list_in_model(meta_rule_list, model_id, result): if model_id not in result['models']: raise MoonCliException("Unexpected request result. Unknown Model id") if "meta_rules" not in result['models'][model_id]: - raise MoonCliException("Unexpected request result. Meta rules related to model with id {} are empty".format(model_id)) + raise MoonCliException( + "Unexpected request result. Meta rules related to model with id {} are empty".format( + model_id)) if meta_rule_list != result['models'][model_id]["meta_rules"]: - raise MoonCliException("Unexpected request result. Meta rule of model with id {} are different from those expected".format(model_id)) + raise MoonCliException( + "Unexpected request result. Meta rule of model with id {} are different from those expected".format( + model_id)) def check_name_in_slaves(name, slaves): @@ -235,10 +256,11 @@ def check_name_in_slaves(name, slaves): raise MoonCliException("The slave '{}' was not found !".format(name)) -def _check_generic_data_data(field,result): +def _check_generic_data_data(field, result): if type(field) is str: if field not in result: - raise MoonCliException("Unexpected request result. The {} field shall be in result".format(field)) + raise MoonCliException( + "Unexpected request result. The {} field shall be in result".format(field)) # if "data" not in resulti[field]: # raise MoonCliException("Unexpected request result. The data field shall be in result['{}']".format(field)) @@ -248,7 +270,8 @@ def _check_id_in_generic_data_data(field, data_id, result): _check_generic_data_data(field, result) for _data in result[field]: if data_id not in list(_data['data'].keys()): - raise MoonCliException("Unexpected request result. Data id {} not in {}".format(data_id, field)) + raise MoonCliException( + "Unexpected request result. Data id {} not in {}".format(data_id, field)) def _check_id_not_in_generic_data_data(field, data_id, result): @@ -256,14 +279,18 @@ def _check_id_not_in_generic_data_data(field, data_id, result): _check_generic_data_data(field, result) for _data in result[field]: if data_id in list(_data['data'].keys()): - raise MoonCliException("Unexpected request result. Data id {} shall not be in {}".format(data_id, field)) + raise MoonCliException( + "Unexpected request result. Data id {} shall not be in {}".format(data_id, + field)) def _check_category_in_generic_data_data(field, category_id, result): _check_generic_data_data(field, result) for _data in result[field]: if category_id != _data["category_id"]: - raise MoonCliException("Unexpected request result. Category id {} not in {} data".format(category_id, field)) + raise MoonCliException( + "Unexpected request result. Category id {} not in {} data".format(category_id, + field)) def check_subject_data_data(result): @@ -314,74 +341,92 @@ def check_category_id_in_action_data_data(category_id, result): _check_category_in_generic_data_data('action_data', category_id, result) -def _check_generic_assignments(field, field_id_name, field_id, field_cat_id, field_data_id, result): +def _check_generic_assignments(field, field_id_name, field_id, field_cat_id, field_data_id, result): if type(field) is str and type(field_id_name) is str: for key in result[field]: if field_id_name not in result[field][key]: - raise MoonCliException("Unexpected request result. subject_id not in result[{}] data".format(field)) + raise MoonCliException( + "Unexpected request result. subject_id not in result[{}] data".format(field)) if "category_id" not in result[field][key]: - raise MoonCliException("Unexpected request result. category_id not in result[{}] data".format(field)) + raise MoonCliException( + "Unexpected request result. category_id not in result[{}] data".format(field)) if "assignments" not in result[field][key]: - raise MoonCliException("Unexpected request result. assignments not in result[{}] data".format(field)) + raise MoonCliException( + "Unexpected request result. assignments not in result[{}] data".format(field)) if result[field][key][field_id_name] == field_id and \ result[field][key]["category_id"] == field_cat_id: if field_data_id not in result[field][key]["assignments"]: raise MoonCliException( - "Unexpected request result. {} data with id {} not in result[{}][]['assignements'] data".format(field, field_data_id, field)) + "Unexpected request result. {} data with id {} not in result[{}][]['assignements'] data".format( + field, field_data_id, field)) def check_subject_assignements(subject_id, subject_act_id, subject_data_id, result): - _check_generic_assignments("subject_assignments", "subject_id", subject_id, subject_act_id, subject_data_id, result) + _check_generic_assignments("subject_assignments", "subject_id", subject_id, subject_act_id, + subject_data_id, result) def check_object_assignements(object_id, object_act_id, object_data_id, result): - _check_generic_assignments("object_assignments", "object_id", object_id, object_act_id, object_data_id, result) + _check_generic_assignments("object_assignments", "object_id", object_id, object_act_id, + object_data_id, result) def check_action_assignements(action_id, action_act_id, action_data_id, result): - _check_generic_assignments("action_assignments", "action_id", action_id, action_act_id, action_data_id, result) + _check_generic_assignments("action_assignments", "action_id", action_id, action_act_id, + action_data_id, result) -def _check_not_generic_assignments(field, field_id_name, field_id, field_cat_id, field_data_id, result): +def _check_not_generic_assignments(field, field_id_name, field_id, field_cat_id, field_data_id, + result): if type(field) is str and type(field_id_name) is str: for key in result[field]: if field_id_name not in result[field][key]: - raise MoonCliException("Unexpected request result. subject_id not in result[{}] data".format(field)) + raise MoonCliException( + "Unexpected request result. subject_id not in result[{}] data".format(field)) if "category_id" not in result[field][key]: - raise MoonCliException("Unexpected request result. category_id not in result[{}] data".format(field)) + raise MoonCliException( + "Unexpected request result. category_id not in result[{}] data".format(field)) if "assignments" not in result[field][key]: - raise MoonCliException("Unexpected request result. assignments not in result[{}] data".format(field)) + raise MoonCliException( + "Unexpected request result. assignments not in result[{}] data".format(field)) if result[field][key]['subject_id'] == field_id and \ result[field][key]["category_id"] == field_cat_id: if field_data_id in result[field][key]["assignments"]: raise MoonCliException( - "Unexpected request result. {} data with id {} shall not be in result[{}][]['assignements'] data".format(field, field_data_id, field)) + "Unexpected request result. {} data with id {} shall not be in result[{}][]['assignements'] data".format( + field, field_data_id, field)) def check_not_subject_assignements(subject_id, subject_act_id, subject_data_id, result): - _check_not_generic_assignments("subject_assignments", "subject_id", subject_id, subject_act_id, subject_data_id, result) + _check_not_generic_assignments("subject_assignments", "subject_id", subject_id, subject_act_id, + subject_data_id, result) def check_not_object_assignements(object_id, object_act_id, object_data_id, result): - _check_not_generic_assignments("object_assignments", "object_id", object_id, object_act_id, object_data_id, result) + _check_not_generic_assignments("object_assignments", "object_id", object_id, object_act_id, + object_data_id, result) def check_not_action_assignements(action_id, action_act_id, action_data_id, result): - _check_not_generic_assignments("action_assignments", "action_id", action_id, action_act_id, action_data_id, result) + _check_not_generic_assignments("action_assignments", "action_id", action_id, action_act_id, + action_data_id, result) def check_policy_id_in_dict(policy_id, in_dict): if "policy_id" not in in_dict: raise MoonCliException("Unexpected request result. policy_id not in result") if policy_id != in_dict["policy_id"]: - raise MoonCliException("Unexpected request result. Bad policy id in result, expected {}".format(policy_id)) + raise MoonCliException( + "Unexpected request result. Bad policy id in result, expected {}".format(policy_id)) def check_meta_rule_id_in_dict(meta_rule_id, in_dict): if "meta_rule_id" not in in_dict: raise MoonCliException("Unexpected request result. meta_rule_id not in result") if meta_rule_id != in_dict["meta_rule_id"]: - raise MoonCliException("Unexpected request result. Bad meta rule id in result, expected {}".format(meta_rule_id)) + raise MoonCliException( + "Unexpected request result. Bad meta rule id in result, expected {}".format( + meta_rule_id)) def check_rule_in_dict(rule, in_dict): @@ -399,7 +444,8 @@ def check_rule_id_in_list(meta_rule_id, rule_id, rule, in_dict): if meta_rule_id == item["meta_rule_id"]: if rule_id == item["id"]: if rule != item["rule"]: - raise MoonCliException("Unexpected request result. Bad rule in result, expected {}".format(rule)) + raise MoonCliException( + "Unexpected request result. Bad rule in result, expected {}".format(rule)) def check_rule_id_not_in_list(rule_id, in_dict): @@ -408,4 +454,5 @@ def check_rule_id_not_in_list(rule_id, in_dict): if rule_id == item["id"]: found_rule = True if found_rule is True: - raise MoonCliException("Unexpected request result. Rule with id {} shall not be in result".format(rule_id))
\ No newline at end of file + raise MoonCliException( + "Unexpected request result. Rule with id {} shall not be in result".format(rule_id)) |