diff options
author | MohamedAssem <mmagraby.ext@orange.com> | 2018-01-04 14:08:59 +0200 |
---|---|---|
committer | MohamedAssem <mmagraby.ext@orange.com> | 2018-01-04 14:08:59 +0200 |
commit | bb86c23b2b634b855d743e2b005b50391051372b (patch) | |
tree | 0160c2e739b16bd1241704eb6981ff0e49cf47ce /moon_manager/tests/unit_python | |
parent | 919c393275bd60e830abda64fd9585ef2bc64e3f (diff) |
add meta_rules unittest for moon_manager
Change-Id: I6eee8a45adaa9df526bbc109fa232f04c75ca72f
Signed-off-by: MohamedAssem <mmagraby.ext@orange.com>
Diffstat (limited to 'moon_manager/tests/unit_python')
-rw-r--r-- | moon_manager/tests/unit_python/api/meta_rules_test.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/moon_manager/tests/unit_python/api/meta_rules_test.py b/moon_manager/tests/unit_python/api/meta_rules_test.py new file mode 100644 index 00000000..b5b1ecf8 --- /dev/null +++ b/moon_manager/tests/unit_python/api/meta_rules_test.py @@ -0,0 +1,69 @@ +import json +import api.utilities as utilities + + +def get_meta_rules(client): + req = client.get("/meta_rules") + meta_rules = utilities.get_json(req.data) + return req, meta_rules + + +def add_meta_rules(client, name): + data = { + "name": name, + "subject_categories": ["subject_category_id1", + "subject_category_id2"], + "object_categories": ["object_category_id1"], + "action_categories": ["action_category_id1"] + } + req = client.post("/meta_rules", data=json.dumps(data), + headers={'Content-Type': 'application/json'}) + meta_rules = utilities.get_json(req.data) + return req, meta_rules + + +def delete_meta_rules(client, name): + request, meta_rules = get_meta_rules(client) + for key, value in meta_rules['meta_rules'].items(): + if value['name'] == name: + req = client.delete("/meta_rules/{}".format(key)) + break + return req + + +def delete_meta_rules_without_id(client): + req = client.delete("/meta_rules/{}".format("")) + return req + + +def test_get_meta_rules(): + client = utilities.register_client() + req, meta_rules = get_meta_rules(client) + assert req.status_code == 200 + assert isinstance(meta_rules, dict) + assert "meta_rules" in meta_rules + + +def test_add_meta_rules(): + client = utilities.register_client() + req, meta_rules = add_meta_rules(client, "testuser") + assert req.status_code == 200 + assert isinstance(meta_rules, dict) + value = list(meta_rules["meta_rules"].values())[0] + assert "meta_rules" in meta_rules + assert value['name'] == "testuser" + assert value["subject_categories"][0] == "subject_category_id1" + assert value["object_categories"][0] == "object_category_id1" + assert value["action_categories"][0] == "action_category_id1" + + +def test_delete_meta_rules(): + client = utilities.register_client() + req = delete_meta_rules(client, "testuser") + assert req.status_code == 200 + + +def test_delete_meta_rules_without_id(): + client = utilities.register_client() + req = delete_meta_rules_without_id(client) + assert req.status_code == 500 |