diff options
author | asteroide <thomas.duval@orange.com> | 2017-06-10 10:58:38 +0200 |
---|---|---|
committer | asteroide <thomas.duval@orange.com> | 2017-06-10 10:58:38 +0200 |
commit | 75f7c79569597a1ca452701acb757fd26ec79114 (patch) | |
tree | 260d342d845cc874674f0acdaef77345627a0614 /moonv4/moon_interface/tests/apitests/utils | |
parent | cebfe74cfe858cb776b409aec737f70cbde767e1 (diff) |
Update models, policies and metarules if they already exist, create them otherwise
Change-Id: I8504dbf5b0080d12368ace7889f64a64f3ac0e48
Diffstat (limited to 'moonv4/moon_interface/tests/apitests/utils')
-rw-r--r-- | moonv4/moon_interface/tests/apitests/utils/models.py | 36 | ||||
-rw-r--r-- | moonv4/moon_interface/tests/apitests/utils/policies.py | 1 |
2 files changed, 21 insertions, 16 deletions
diff --git a/moonv4/moon_interface/tests/apitests/utils/models.py b/moonv4/moon_interface/tests/apitests/utils/models.py index 1ba6e440..8343f77e 100644 --- a/moonv4/moon_interface/tests/apitests/utils/models.py +++ b/moonv4/moon_interface/tests/apitests/utils/models.py @@ -23,7 +23,7 @@ meta_rule_template = { } -def check_model(model_id=None): +def check_model(model_id=None, check_model_name=True): req = requests.get(URL.format("/models")) assert req.status_code == 200 result = req.json() @@ -33,8 +33,9 @@ def check_model(model_id=None): assert result["models"] assert model_id in result['models'] assert "name" in result['models'][model_id] - assert model_template["name"] == result['models'][model_id]["name"] - return result['models'] + if check_model_name: + assert model_template["name"] == result['models'][model_id]["name"] + return result def add_model(name=None): @@ -224,6 +225,8 @@ def check_meta_rule(meta_rule_id, scat_id=None, ocat_id=None, acat_id=None): assert "meta_rules" in result if "result" in result: assert result["result"] + if not meta_rule_id: + return result assert meta_rule_id in result['meta_rules'] assert "name" in result['meta_rules'][meta_rule_id] if scat_id: @@ -244,17 +247,18 @@ def delete_meta_rule(meta_rule_id): def add_meta_rule_to_model(model_id, meta_rule_id): - model = check_model(model_id) + model = check_model(model_id, check_model_name=False)['models'] meta_rule_list = model[model_id]["meta_rules"] - meta_rule_list.append(meta_rule_id) - req = requests.patch(URL.format("/models/{}".format(model_id)), - json={"meta_rules": meta_rule_list}, - headers=HEADERS) - assert req.status_code == 200 - result = req.json() - assert type(result) is dict - model_id = list(result['models'].keys())[0] - if "result" in result: - assert result["result"] - assert "meta_rules" in result['models'][model_id] - assert meta_rule_list == result['models'][model_id]["meta_rules"] + if meta_rule_id not in meta_rule_list: + meta_rule_list.append(meta_rule_id) + req = requests.patch(URL.format("/models/{}".format(model_id)), + json={"meta_rules": meta_rule_list}, + headers=HEADERS) + assert req.status_code == 200 + result = req.json() + assert type(result) is dict + model_id = list(result['models'].keys())[0] + if "result" in result: + assert result["result"] + assert "meta_rules" in result['models'][model_id] + assert meta_rule_list == result['models'][model_id]["meta_rules"] diff --git a/moonv4/moon_interface/tests/apitests/utils/policies.py b/moonv4/moon_interface/tests/apitests/utils/policies.py index 7b345fad..e6df7f71 100644 --- a/moonv4/moon_interface/tests/apitests/utils/policies.py +++ b/moonv4/moon_interface/tests/apitests/utils/policies.py @@ -61,6 +61,7 @@ def check_policy(policy_id=None): assert policy_id in result['policies'] assert "name" in result['policies'][policy_id] assert policy_template["name"] == result['policies'][policy_id]["name"] + return result def add_policy(name="test_policy", genre="authz"): |