From ddf8696b5c185ee7acf66d62939449788afef1fd Mon Sep 17 00:00:00 2001 From: MohamedAssem Date: Tue, 16 Jan 2018 10:25:13 +0200 Subject: add test_rules unittests for moon_manager Change-Id: I5fd3e2e983c1ecba578ad43728b5f5b94ca17e48 Signed-off-by: MohamedAssem --- moon_manager/tests/unit_python/api/test_rules.py | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 moon_manager/tests/unit_python/api/test_rules.py (limited to 'moon_manager') diff --git a/moon_manager/tests/unit_python/api/test_rules.py b/moon_manager/tests/unit_python/api/test_rules.py new file mode 100644 index 00000000..86a3d390 --- /dev/null +++ b/moon_manager/tests/unit_python/api/test_rules.py @@ -0,0 +1,58 @@ +import api.utilities as utilities +import json + + +def get_rules(client, policy_id): + req = client.get("/policies/{}/rules".format(policy_id)) + rules = utilities.get_json(req.data) + return req, rules + + +def add_rules(client, policy_id): + data = { + "meta_rule_id": "meta_rule_id1", + "rule": ["subject_data_id2", "object_data_id2", "action_data_id2"], + "instructions": ( + {"decision": "grant"}, + ), + "enabled": True + } + req = client.post("/policies/{}/rules".format(policy_id), data=json.dumps(data), + headers={'Content-Type': 'application/json'}) + rules = utilities.get_json(req.data) + return req, rules + + +def delete_rules(client, policy_id, meta_rule_id): + req = client.delete("/policies/{}/rules/{}".format(policy_id, meta_rule_id)) + return req + + +def test_get_rules(): + policy_id = utilities.get_policy_id() + client = utilities.register_client() + req, rules = get_rules(client, policy_id) + assert req.status_code == 200 + assert isinstance(rules, dict) + assert "rules" in rules + + +def test_add_rules(): + policy_id = utilities.get_policy_id() + client = utilities.register_client() + req, rules = add_rules(client, policy_id) + assert req.status_code == 200 + assert isinstance(rules, dict) + value = rules["rules"] + assert "rules" in rules + id = list(value.keys())[0] + assert value[id]["meta_rule_id"] == "meta_rule_id1" + + +def test_delete_rules(): + client = utilities.register_client() + policy_id = utilities.get_policy_id() + req, added_rules = get_rules(client, policy_id) + id = added_rules["rules"]['rules'][0]['id'] + rules = delete_rules(client, policy_id, id) + assert rules.status_code == 200 -- cgit 1.2.3-korg