aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager/tests/unit_python/api
diff options
context:
space:
mode:
Diffstat (limited to 'moon_manager/tests/unit_python/api')
-rw-r--r--moon_manager/tests/unit_python/api/meta_rules_test.py69
-rw-r--r--moon_manager/tests/unit_python/api/test_models.py67
-rw-r--r--moon_manager/tests/unit_python/api/test_policies.py69
3 files changed, 205 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
diff --git a/moon_manager/tests/unit_python/api/test_models.py b/moon_manager/tests/unit_python/api/test_models.py
new file mode 100644
index 00000000..3c205d1d
--- /dev/null
+++ b/moon_manager/tests/unit_python/api/test_models.py
@@ -0,0 +1,67 @@
+import json
+import api.utilities as utilities
+
+
+def get_models(client):
+ req = client.get("/models")
+ models = utilities.get_json(req.data)
+ return req, models
+
+
+def add_models(client, name):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name),
+ "meta_rules": ["meta_rule_id1", "meta_rule_id2"]
+ }
+ req = client.post("/models", data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ models = utilities.get_json(req.data)
+ return req, models
+
+
+def delete_models(client, name):
+ request, models = get_models(client)
+ for key, value in models['models'].items():
+ if value['name'] == name:
+ req = client.delete("/models/{}".format(key))
+ break
+ return req
+
+
+def delete_models_without_id(client):
+ req = client.delete("/models/{}".format(""))
+ return req
+
+
+def test_get_models():
+ client = utilities.register_client()
+ req, models= get_models(client)
+ assert req.status_code == 200
+ assert isinstance(models, dict)
+ assert "models" in models
+
+
+def test_add_models():
+ client = utilities.register_client()
+ req, models = add_models(client, "testuser")
+ assert req.status_code == 200
+ assert isinstance(models, dict)
+ value = list(models["models"].values())[0]
+ assert "models" in models
+ assert value['name'] == "testuser"
+ assert value["description"] == "description of {}".format("testuser")
+ assert value["meta_rules"][0] == "meta_rule_id1"
+
+
+def test_delete_models():
+ client = utilities.register_client()
+ req = delete_models(client, "testuser")
+ assert req.status_code == 200
+
+
+def test_delete_models_without_id():
+ client = utilities.register_client()
+ req = delete_models_without_id(client)
+ assert req.status_code == 500
+
diff --git a/moon_manager/tests/unit_python/api/test_policies.py b/moon_manager/tests/unit_python/api/test_policies.py
new file mode 100644
index 00000000..4d4e387e
--- /dev/null
+++ b/moon_manager/tests/unit_python/api/test_policies.py
@@ -0,0 +1,69 @@
+import json
+import api.utilities as utilities
+
+
+def get_policies(client):
+ req = client.get("/policies")
+ policies = utilities.get_json(req.data)
+ return req, policies
+
+
+def add_policies(client, name):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name),
+ "model_id": "modelId",
+ "genre": "genre"
+ }
+ req = client.post("/policies", data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ policies = utilities.get_json(req.data)
+ return req, policies
+
+
+def delete_policies(client, name):
+ request, policies = get_policies(client)
+ for key, value in policies['policies'].items():
+ if value['name'] == name:
+ req = client.delete("/policies/{}".format(key))
+ break
+ return req
+
+
+def delete_policies_without_id(client):
+ req = client.delete("/policies/{}".format(""))
+ return req
+
+
+def test_get_policies():
+ client = utilities.register_client()
+ req, policies = get_policies(client)
+ assert req.status_code == 200
+ assert isinstance(policies, dict)
+ assert "policies" in policies
+
+
+def test_add_policies():
+ client = utilities.register_client()
+ req, policies = add_policies(client, "testuser")
+ assert req.status_code == 200
+ assert isinstance(policies, dict)
+ value = list(policies["policies"].values())[0]
+ assert "policies" in policies
+ assert value['name'] == "testuser"
+ assert value["description"] == "description of {}".format("testuser")
+ assert value["model_id"] == "modelId"
+ assert value["genre"] == "genre"
+
+
+def test_delete_policies():
+ client = utilities.register_client()
+ req = delete_policies(client, "testuser")
+ assert req.status_code == 200
+
+
+def test_delete_policies_without_id():
+ client = utilities.register_client()
+ req = delete_policies_without_id(client)
+ assert req.status_code == 500
+