aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager/tests
diff options
context:
space:
mode:
Diffstat (limited to 'moon_manager/tests')
-rw-r--r--moon_manager/tests/unit_python/api/test_data.py168
-rw-r--r--moon_manager/tests/unit_python/api/utilities.py16
2 files changed, 183 insertions, 1 deletions
diff --git a/moon_manager/tests/unit_python/api/test_data.py b/moon_manager/tests/unit_python/api/test_data.py
new file mode 100644
index 00000000..87a80c69
--- /dev/null
+++ b/moon_manager/tests/unit_python/api/test_data.py
@@ -0,0 +1,168 @@
+import api.utilities as utilities
+import json
+
+
+# subject_categories_test
+
+
+def get_subject_data(client, policy_id):
+ req = client.get("/policies/{}/subject_data".format(policy_id))
+ subject_data = utilities.get_json(req.data)
+ return req, subject_data
+
+
+def add_subject_data(client, name, policy_id, category_id):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name)
+ }
+ req = client.post("/policies/{}/subject_data/{}".format(policy_id, category_id), data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ subject_data = utilities.get_json(req.data)
+ return req, subject_data
+
+
+def delete_subject_data(client, policy_id):
+ req = client.delete("/policies/{}/subject_data".format(policy_id))
+ return req
+
+
+def test_get_subject_data():
+ policy_id = utilities.get_policy_id()
+ client = utilities.register_client()
+ req, subject_data = get_subject_data(client, policy_id)
+ assert req.status_code == 200
+ assert isinstance(subject_data, dict)
+ assert "subject_data" in subject_data
+
+
+def test_add_subject_data():
+ policy_id = utilities.get_policy_id()
+ client = utilities.register_client()
+ req, subject_data = add_subject_data(client, "testuser", policy_id, "111")
+ assert req.status_code == 200
+ assert isinstance(subject_data, dict)
+ value = subject_data["subject_data"]['data']
+ assert "subject_data" in subject_data
+ id = list(value.keys())[0]
+ assert value[id]['name'] == "testuser"
+ assert value[id]['description'] == "description of {}".format("testuser")
+
+
+def test_delete_subject_data():
+ client = utilities.register_client()
+ policy_id = utilities.get_policy_id()
+ success_req = delete_subject_data(client, policy_id)
+ assert success_req.status_code == 200
+
+# ---------------------------------------------------------------------------
+
+# object_categories_test
+
+
+def get_object_data(client, policy_id):
+ req = client.get("/policies/{}/object_data".format(policy_id))
+ object_data = utilities.get_json(req.data)
+ return req, object_data
+
+
+def add_object_data(client, name, policy_id, category_id):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name)
+ }
+ req = client.post("/policies/{}/object_data/{}".format(policy_id, category_id), data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ object_data = utilities.get_json(req.data)
+ return req, object_data
+
+
+def delete_object_data(client, policy_id):
+ req = client.delete("/policies/{}/object_data".format(policy_id))
+ return req
+
+
+def test_get_object_data():
+ policy_id = utilities.get_policy_id()
+ client = utilities.register_client()
+ req, object_data = get_object_data(client, policy_id)
+ assert req.status_code == 200
+ assert isinstance(object_data, dict)
+ assert "object_data" in object_data
+
+
+def test_add_object_data():
+ policy_id = utilities.get_policy_id()
+ client = utilities.register_client()
+ req, object_data = add_object_data(client, "testuser", policy_id, "111")
+ assert req.status_code == 200
+ assert isinstance(object_data, dict)
+ value = object_data["object_data"]['data']
+ assert "object_data" in object_data
+ id = list(value.keys())[0]
+ assert value[id]['value']['name'] == "testuser"
+ assert value[id]['value']['description'] == "description of {}".format("testuser")
+
+
+def test_delete_object_data():
+ client = utilities.register_client()
+ policy_id = utilities.get_policy_id()
+ success_req = delete_object_data(client, policy_id)
+ assert success_req.status_code == 200
+
+# ---------------------------------------------------------------------------
+
+# action_categories_test
+
+
+def get_action_data(client, policy_id):
+ req = client.get("/policies/{}/action_data".format(policy_id))
+ action_data = utilities.get_json(req.data)
+ return req, action_data
+
+
+def add_action_data(client, name, policy_id, category_id):
+ data = {
+ "name": name,
+ "description": "description of {}".format(name)
+ }
+ req = client.post("/policies/{}/action_data/{}".format(policy_id, category_id), data=json.dumps(data),
+ headers={'Content-Type': 'application/json'})
+ action_data = utilities.get_json(req.data)
+ return req, action_data
+
+
+def delete_action_data(client, policy_id):
+ req = client.delete("/policies/{}/action_data".format(policy_id))
+ return req
+
+
+def test_get_action_data():
+ policy_id = utilities.get_policy_id()
+ client = utilities.register_client()
+ req, action_data = get_action_data(client, policy_id)
+ assert req.status_code == 200
+ assert isinstance(action_data, dict)
+ assert "action_data" in action_data
+
+
+def test_add_action_data():
+ policy_id = utilities.get_policy_id()
+ client = utilities.register_client()
+ req, action_data = add_action_data(client, "testuser", policy_id, "111")
+ assert req.status_code == 200
+ assert isinstance(action_data, dict)
+ value = action_data["action_data"]['data']
+ assert "action_data" in action_data
+ id = list(value.keys())[0]
+ assert value[id]['value']['name'] == "testuser"
+ assert value[id]['value']['description'] == "description of {}".format("testuser")
+
+
+def test_delete_action_data():
+ client = utilities.register_client()
+ policy_id = utilities.get_policy_id()
+ success_req = delete_action_data(client, policy_id)
+ assert success_req.status_code == 200
+
+# --------------------------------------------------------------------------- \ No newline at end of file
diff --git a/moon_manager/tests/unit_python/api/utilities.py b/moon_manager/tests/unit_python/api/utilities.py
index a2b0689b..66ca30c5 100644
--- a/moon_manager/tests/unit_python/api/utilities.py
+++ b/moon_manager/tests/unit_python/api/utilities.py
@@ -9,4 +9,18 @@ def register_client():
import moon_manager.server
server = moon_manager.server.create_server()
client = server.app.test_client()
- return client \ No newline at end of file
+ return client
+
+
+def get_policy_id():
+ import api.test_policies as policies
+ client = register_client()
+ policy_id = ''
+ req, policy = policies.get_policies(client)
+ for id in policy['policies']:
+ if id:
+ policy_id = id
+ break
+ if not policy_id:
+ policies.add_policies(client, "testuser")
+ return policy_id