aboutsummaryrefslogtreecommitdiffstats
path: root/python_moondb/tests/unit_python/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'python_moondb/tests/unit_python/helpers')
-rw-r--r--python_moondb/tests/unit_python/helpers/__init__.py0
-rw-r--r--python_moondb/tests/unit_python/helpers/assignment_helper.py49
-rw-r--r--python_moondb/tests/unit_python/helpers/category_helper.py54
-rw-r--r--python_moondb/tests/unit_python/helpers/data_helper.py98
-rw-r--r--python_moondb/tests/unit_python/helpers/meta_rule_helper.py48
-rw-r--r--python_moondb/tests/unit_python/helpers/mock_data.py156
-rw-r--r--python_moondb/tests/unit_python/helpers/model_helper.py47
-rw-r--r--python_moondb/tests/unit_python/helpers/pdp_helper.py23
-rw-r--r--python_moondb/tests/unit_python/helpers/policy_helper.py72
9 files changed, 0 insertions, 547 deletions
diff --git a/python_moondb/tests/unit_python/helpers/__init__.py b/python_moondb/tests/unit_python/helpers/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/python_moondb/tests/unit_python/helpers/__init__.py
+++ /dev/null
diff --git a/python_moondb/tests/unit_python/helpers/assignment_helper.py b/python_moondb/tests/unit_python/helpers/assignment_helper.py
deleted file mode 100644
index 22a56e38..00000000
--- a/python_moondb/tests/unit_python/helpers/assignment_helper.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-
-def get_action_assignments(policy_id, action_id=None, category_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_action_assignments("", policy_id, action_id, category_id)
-
-
-def add_action_assignment(policy_id, action_id, category_id, data_id):
- from python_moondb.core import PolicyManager
- return PolicyManager.add_action_assignment("", policy_id, action_id, category_id, data_id)
-
-
-def delete_action_assignment(policy_id, action_id, category_id, data_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_action_assignment("", policy_id, action_id, category_id, data_id)
-
-
-def get_object_assignments(policy_id, object_id=None, category_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_object_assignments("", policy_id, object_id, category_id)
-
-
-def add_object_assignment(policy_id, object_id, category_id, data_id):
- from python_moondb.core import PolicyManager
- return PolicyManager.add_object_assignment("", policy_id, object_id, category_id, data_id)
-
-
-def delete_object_assignment(policy_id, object_id, category_id, data_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_object_assignment("", policy_id, object_id, category_id, data_id)
-
-
-def get_subject_assignments(policy_id, subject_id=None, category_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_subject_assignments("", policy_id, subject_id, category_id)
-
-
-def add_subject_assignment(policy_id, subject_id, category_id, data_id):
- from python_moondb.core import PolicyManager
- return PolicyManager.add_subject_assignment("", policy_id, subject_id, category_id, data_id)
-
-
-def delete_subject_assignment(policy_id, subject_id, category_id, data_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_subject_assignment("", policy_id, subject_id, category_id, data_id)
-
diff --git a/python_moondb/tests/unit_python/helpers/category_helper.py b/python_moondb/tests/unit_python/helpers/category_helper.py
deleted file mode 100644
index 55e95d91..00000000
--- a/python_moondb/tests/unit_python/helpers/category_helper.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-
-def add_subject_category(cat_id=None, value=None):
- from python_moondb.core import ModelManager
- category = ModelManager.add_subject_category(user_id=None, category_id=cat_id, value=value)
- return category
-
-
-def get_subject_category(cat_id=None):
- from python_moondb.core import ModelManager
- category = ModelManager.get_subject_categories(user_id=None, category_id=cat_id)
- return category
-
-
-def add_object_category(cat_id=None, value=None):
- from python_moondb.core import ModelManager
- category = ModelManager.add_object_category(user_id=None, category_id=cat_id, value=value)
- return category
-
-
-def get_object_category(cat_id=None):
- from python_moondb.core import ModelManager
- category = ModelManager.get_object_categories(user_id=None, category_id=cat_id)
- return category
-
-
-def add_action_category(cat_id=None, value=None):
- from python_moondb.core import ModelManager
- category = ModelManager.add_action_category(user_id=None, category_id=cat_id, value=value)
- return category
-
-
-def get_action_category(cat_id=None):
- from python_moondb.core import ModelManager
- category = ModelManager.get_action_categories(user_id=None, category_id=cat_id)
- return category
-
-
-def delete_subject_category(category_id=None):
- from python_moondb.core import ModelManager
- return ModelManager.delete_subject_category("", category_id=category_id)
-
-
-def delete_object_category(category_id=None):
- from python_moondb.core import ModelManager
- return ModelManager.delete_object_category("", category_id=category_id)
-
-
-def delete_action_category(category_id=None):
- from python_moondb.core import ModelManager
- return ModelManager.delete_action_category("", category_id=category_id)
diff --git a/python_moondb/tests/unit_python/helpers/data_helper.py b/python_moondb/tests/unit_python/helpers/data_helper.py
deleted file mode 100644
index 8a8238f5..00000000
--- a/python_moondb/tests/unit_python/helpers/data_helper.py
+++ /dev/null
@@ -1,98 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-
-def get_action_data(policy_id, data_id=None, category_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_action_data("", policy_id, data_id, category_id)
-
-
-def add_action_data(policy_id, data_id=None, category_id=None, value=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.add_action_data("", policy_id, data_id, category_id, value)
-
-
-def delete_action_data(policy_id, data_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_action_data("",policy_id=policy_id, data_id=data_id)
-
-
-def get_object_data(policy_id, data_id=None, category_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_object_data("", policy_id, data_id, category_id)
-
-
-def add_object_data(policy_id, data_id=None, category_id=None, value=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.add_object_data("", policy_id, data_id, category_id, value)
-
-
-def delete_object_data(policy_id, data_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_object_data("", policy_id=policy_id, data_id=data_id)
-
-
-def get_subject_data(policy_id, data_id=None, category_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_subject_data("", policy_id, data_id, category_id)
-
-
-def add_subject_data(policy_id, data_id=None, category_id=None, value=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.set_subject_data("", policy_id, data_id, category_id, value)
-
-
-def delete_subject_data(policy_id, data_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_subject_data("", policy_id=policy_id, data_id=data_id)
-
-
-def get_actions(policy_id, perimeter_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_actions("", policy_id, perimeter_id)
-
-
-def add_action(policy_id, perimeter_id=None, value=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.add_action("", policy_id, perimeter_id, value)
-
-
-def delete_action(policy_id, perimeter_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_action("", policy_id, perimeter_id)
-
-
-def get_objects(policy_id, perimeter_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_objects("", policy_id, perimeter_id)
-
-
-def add_object(policy_id, perimeter_id=None, value=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.add_object("", policy_id, perimeter_id, value)
-
-
-def delete_object(policy_id, perimeter_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_object("", policy_id, perimeter_id)
-
-
-def get_subjects(policy_id, perimeter_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_subjects("", policy_id, perimeter_id)
-
-
-def add_subject(policy_id, perimeter_id=None, value=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.add_subject("", policy_id, perimeter_id, value)
-
-
-def delete_subject(policy_id, perimeter_id):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_subject("", policy_id, perimeter_id)
-
-
-def get_available_metadata(policy_id):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_available_metadata("", policy_id)
diff --git a/python_moondb/tests/unit_python/helpers/meta_rule_helper.py b/python_moondb/tests/unit_python/helpers/meta_rule_helper.py
deleted file mode 100644
index 87af250a..00000000
--- a/python_moondb/tests/unit_python/helpers/meta_rule_helper.py
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-
-from helpers import mock_data
-
-
-def update_meta_rule(meta_rule_id, value=None):
- from python_moondb.core import ModelManager
- if not value:
- action_category_id = mock_data.create_action_category("action_category_id1")
- subject_category_id = mock_data.create_subject_category("subject_category_id1")
- object_category_id = mock_data.create_object_category("object_category_id1")
- value = {
- "name": "MLS_meta_rule",
- "description": "test",
- "subject_categories": [subject_category_id],
- "object_categories": [object_category_id],
- "action_categories": [action_category_id]
- }
- return ModelManager.update_meta_rule(user_id=None, meta_rule_id=meta_rule_id, value=value)
-
-
-def add_meta_rule(meta_rule_id=None, value=None):
- from python_moondb.core import ModelManager
- if not value:
- action_category_id = mock_data.create_action_category("action_category_id1")
- subject_category_id = mock_data.create_subject_category("subject_category_id1")
- object_category_id = mock_data.create_object_category("object_category_id1")
- value = {
- "name": "MLS_meta_rule",
- "description": "test",
- "subject_categories": [subject_category_id],
- "object_categories": [object_category_id],
- "action_categories": [action_category_id]
- }
- return ModelManager.add_meta_rule(user_id=None, meta_rule_id=meta_rule_id, value=value)
-
-
-def get_meta_rules(meta_rule_id=None):
- from python_moondb.core import ModelManager
- return ModelManager.get_meta_rules(user_id=None, meta_rule_id=meta_rule_id)
-
-
-def delete_meta_rules(meta_rule_id=None):
- from python_moondb.core import ModelManager
- ModelManager.delete_meta_rule(user_id=None, meta_rule_id=meta_rule_id)
diff --git a/python_moondb/tests/unit_python/helpers/mock_data.py b/python_moondb/tests/unit_python/helpers/mock_data.py
deleted file mode 100644
index 0d65ea02..00000000
--- a/python_moondb/tests/unit_python/helpers/mock_data.py
+++ /dev/null
@@ -1,156 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-
-from .category_helper import *
-from .policy_helper import *
-from .data_helper import *
-from .model_helper import *
-from .meta_rule_helper import *
-from uuid import uuid4
-
-
-def create_subject_category(name):
- subject_category = add_subject_category(
- value={"name": name, "description": "description 1"})
- return list(subject_category.keys())[0]
-
-
-def create_object_category(name):
- object_category = add_object_category(
- value={"name": name, "description": "description 1"})
- return list(object_category.keys())[0]
-
-
-def create_action_category(name):
- action_category = add_action_category(
- value={"name": name, "description": "description 1"})
- return list(action_category.keys())[0]
-
-
-def create_model(meta_rule_id, model_name="test_model"):
- value = {
- "name": model_name,
- "description": "test",
- "meta_rules": [meta_rule_id]
-
- }
- return value
-
-
-def create_policy(model_id, policy_name="policy_1"):
- value = {
- "name": policy_name,
- "model_id": model_id,
- "genre": "authz",
- "description": "test",
- }
- return value
-
-
-def create_pdp(policies_ids):
- value = {
- "name": "test_pdp",
- "security_pipeline": policies_ids,
- "keystone_project_id": "keystone_project_id1",
- "description": "...",
- }
- return value
-
-
-def create_new_policy(subject_category_name="subjectCategory", object_category_name="objectCategory",
- action_category_name="actionCategory",
- model_name="test_model", policy_name="policy_name",
- meta_rule_name="meta_rule_"):
- if policy_name == "policy_name":
- policy_name = "policy_name_" + uuid4().hex
-
- subject_category_id, object_category_id, action_category_id, meta_rule_id = create_new_meta_rule(
- subject_category_name=subject_category_name + uuid4().hex,
- object_category_name=object_category_name + uuid4().hex,
- action_category_name=action_category_name + uuid4().hex,
- meta_rule_name=meta_rule_name + uuid4().hex
- )
- model = add_model(value=create_model(meta_rule_id, model_name))
- model_id = list(model.keys())[0]
- value = create_policy(model_id, policy_name)
- policy = add_policies(value=value)
- assert policy
- policy_id = list(policy.keys())[0]
- return subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id
-
-
-def create_new_meta_rule(subject_category_name="subject_category" + uuid4().hex,
- object_category_name="object_category" + uuid4().hex,
- action_category_name="action_category" + uuid4().hex,
- meta_rule_name="meta_rule" + uuid4().hex):
- from python_moondb.core import ModelManager
-
- subject_category_id = create_subject_category(subject_category_name)
- object_category_id = create_object_category(object_category_name)
- action_category_id = create_action_category(action_category_name)
- value = {"name": meta_rule_name,
- "algorithm": "name of the meta rule algorithm",
- "subject_categories": [subject_category_id],
- "object_categories": [object_category_id],
- "action_categories": [action_category_id]
- }
- # meta_rule = add_meta_rule(value=value)
- meta_rule = ModelManager.add_meta_rule(user_id=None, meta_rule_id=None, value=value)
- return subject_category_id, object_category_id, action_category_id, list(meta_rule.keys())[0]
-
-
-def create_subject(policy_id):
- value = {
- "name": "testuser",
- "description": "test",
- }
- subject = add_subject(policy_id=policy_id, value=value)
- return list(subject.keys())[0]
-
-
-def create_object(policy_id):
- value = {
- "name": "testobject",
- "description": "test",
- }
- object = add_object(policy_id=policy_id, value=value)
- return list(object.keys())[0]
-
-
-def create_action(policy_id):
- value = {
- "name": "testaction",
- "description": "test",
- }
- action = add_action(policy_id=policy_id, value=value)
- return list(action.keys())[0]
-
-
-def create_subject_data(policy_id, category_id):
- value = {
- "name": uuid4().hex,
- "description": {uuid4().hex: "", uuid4().hex: "", uuid4().hex: ""},
- }
- subject_data = add_subject_data(policy_id=policy_id, category_id=category_id, value=value).get('data')
- assert subject_data
- return list(subject_data.keys())[0]
-
-
-def create_object_data(policy_id, category_id):
- value = {
- "name": uuid4().hex,
- "description": {uuid4().hex: "", uuid4().hex: "", uuid4().hex: ""},
- }
- object_data = add_object_data(policy_id=policy_id, category_id=category_id, value=value).get('data')
- return list(object_data.keys())[0]
-
-
-def create_action_data(policy_id, category_id):
- value = {
- "name": uuid4().hex,
- "description": {uuid4().hex: "", uuid4().hex: "", uuid4().hex: ""},
- }
- action_data = add_action_data(policy_id=policy_id, category_id=category_id, value=value).get('data')
- return list(action_data.keys())[0]
diff --git a/python_moondb/tests/unit_python/helpers/model_helper.py b/python_moondb/tests/unit_python/helpers/model_helper.py
deleted file mode 100644
index 98a6271d..00000000
--- a/python_moondb/tests/unit_python/helpers/model_helper.py
+++ /dev/null
@@ -1,47 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-
-from helpers import mock_data
-from uuid import uuid4
-
-def get_models(model_id=None):
- from python_moondb.core import ModelManager
- return ModelManager.get_models(user_id=None, model_id=model_id)
-
-
-def add_model(model_id=None, value=None):
- from python_moondb.core import ModelManager
- if not value:
- subject_category_id, object_category_id, action_category_id, meta_rule_id = mock_data.create_new_meta_rule()
- name = "MLS" if model_id is None else "MLS " + model_id
- value = {
- "name": name,
- "description": "test",
- "meta_rules": [meta_rule_id]
- }
- return ModelManager.add_model(user_id=None, model_id=model_id, value=value)
-
-
-def delete_models(uuid=None, name=None):
- from python_moondb.core import ModelManager
- if not uuid:
- for model_id, model_value in get_models():
- if name == model_value['name']:
- uuid = model_id
- break
- ModelManager.delete_model(user_id=None, model_id=uuid)
-
-
-def delete_all_models():
- from python_moondb.core import ModelManager
- models_values = get_models()
- print(models_values)
- for model_id, model_value in models_values.items():
- ModelManager.delete_model(user_id=None, model_id=model_id)
-
-
-def update_model(model_id=None, value=None):
- from python_moondb.core import ModelManager
- return ModelManager.update_model(user_id=None, model_id=model_id, value=value)
diff --git a/python_moondb/tests/unit_python/helpers/pdp_helper.py b/python_moondb/tests/unit_python/helpers/pdp_helper.py
deleted file mode 100644
index 3d169b06..00000000
--- a/python_moondb/tests/unit_python/helpers/pdp_helper.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-
-def update_pdp(pdp_id, value):
- from python_moondb.core import PDPManager
- return PDPManager.update_pdp("", pdp_id, value)
-
-
-def delete_pdp(pdp_id):
- from python_moondb.core import PDPManager
- PDPManager.delete_pdp("", pdp_id)
-
-
-def add_pdp(pdp_id=None, value=None):
- from python_moondb.core import PDPManager
- return PDPManager.add_pdp("", pdp_id, value)
-
-
-def get_pdp(pdp_id=None):
- from python_moondb.core import PDPManager
- return PDPManager.get_pdp("", pdp_id)
diff --git a/python_moondb/tests/unit_python/helpers/policy_helper.py b/python_moondb/tests/unit_python/helpers/policy_helper.py
deleted file mode 100644
index 93d81c62..00000000
--- a/python_moondb/tests/unit_python/helpers/policy_helper.py
+++ /dev/null
@@ -1,72 +0,0 @@
-# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
-# This software is distributed under the terms and conditions of the 'Apache-2.0'
-# license which can be found in the file 'LICENSE' in this package distribution
-# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
-from helpers import mock_data as mock_data
-from helpers import meta_rule_helper
-
-def get_policies():
- from python_moondb.core import PolicyManager
- return PolicyManager.get_policies("admin")
-
-
-def add_policies(policy_id=None, value=None):
- from python_moondb.core import PolicyManager
- if not value:
- value = {
- "name": "test_policy",
- "model_id": "",
- "genre": "authz",
- "description": "test",
- }
- return PolicyManager.add_policy("admin", policy_id=policy_id, value=value)
-
-
-def delete_policies(uuid=None, name=None):
- from python_moondb.core import PolicyManager
- if not uuid:
- for policy_id, policy_value in get_policies():
- if name == policy_value['name']:
- uuid = policy_id
- break
- PolicyManager.delete_policy("admin", uuid)
-
-
-def update_policy(policy_id, value):
- from python_moondb.core import PolicyManager
- return PolicyManager.update_policy("admin", policy_id, value)
-
-
-def get_policy_from_meta_rules(meta_rule_id):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_policy_from_meta_rules("admin", meta_rule_id)
-
-
-def get_rules(policy_id=None, meta_rule_id=None, rule_id=None):
- from python_moondb.core import PolicyManager
- return PolicyManager.get_rules("", policy_id, meta_rule_id, rule_id)
-
-
-def add_rule(policy_id, meta_rule_id, value=None):
- from python_moondb.core import PolicyManager
- if not value:
- meta_rule = meta_rule_helper.get_meta_rules(meta_rule_id)
- sub_cat_id = meta_rule[meta_rule_id]['subject_categories'][0]
- ob_cat_id = meta_rule[meta_rule_id]['object_categories'][0]
- act_cat_id = meta_rule[meta_rule_id]['action_categories'][0]
-
- subject_data_id = mock_data.create_subject_data(policy_id=policy_id, category_id=sub_cat_id)
- object_data_id = mock_data.create_object_data(policy_id=policy_id, category_id=ob_cat_id)
- action_data_id = mock_data.create_action_data(policy_id=policy_id, category_id=act_cat_id)
-
- value = {
- "rule": (subject_data_id, object_data_id, action_data_id),
- "instructions": ({"decision": "grant"}),
- "enabled": "",
- }
- return PolicyManager.add_rule("", policy_id, meta_rule_id, value)
-
-
-def delete_rule(policy_id=None, rule_id=None):
- from python_moondb.core import PolicyManager
- PolicyManager.delete_rule("", policy_id, rule_id)