aboutsummaryrefslogtreecommitdiffstats
path: root/python_moondb/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python_moondb/tests')
-rw-r--r--python_moondb/tests/unit_python/models/test_categories.py39
-rw-r--r--python_moondb/tests/unit_python/models/test_meta_rules.py20
-rw-r--r--python_moondb/tests/unit_python/models/test_models.py14
-rwxr-xr-xpython_moondb/tests/unit_python/policies/test_policies.py13
-rwxr-xr-xpython_moondb/tests/unit_python/test_pdp.py13
5 files changed, 88 insertions, 11 deletions
diff --git a/python_moondb/tests/unit_python/models/test_categories.py b/python_moondb/tests/unit_python/models/test_categories.py
index cdcf6bcb..8782f172 100644
--- a/python_moondb/tests/unit_python/models/test_categories.py
+++ b/python_moondb/tests/unit_python/models/test_categories.py
@@ -17,11 +17,18 @@ def add_subject_category(cat_id=None, value=None):
def test_add_subject_category_twice():
- category = add_subject_category(value={"name":"category name", "description":"description 1"})
+ category = add_subject_category(value={"name": "category name", "description": "description 1"})
category_id = list(category.keys())[0]
assert category is not None
with pytest.raises(SubjectCategoryExisting):
- add_subject_category(category_id, value={"name":"category name", "description":"description 2"})
+ add_subject_category(category_id, value={"name": "category name", "description": "description 2"})
+
+
+def test_add_subject_category_twice_with_same_name():
+ category = add_subject_category(value={"name": "category name", "description": "description 1"})
+ assert category is not None
+ with pytest.raises(SubjectCategoryExisting):
+ add_subject_category(value={"name": "category name", "description": "description 2"})
def get_subject_category(cat_id=None):
@@ -31,7 +38,7 @@ def get_subject_category(cat_id=None):
def test_get_subject_categories():
- added_category = add_subject_category(value={"name":"category name", "description":"description 1"})
+ added_category = add_subject_category(value={"name": "category name", "description": "description 1"})
category_id = list(added_category.keys())[0]
subject_category = get_subject_category(category_id)
assert subject_category == added_category
@@ -99,11 +106,18 @@ def add_object_category(cat_id=None, value=None):
def test_add_object_category_twice():
- category = add_object_category(value={"name":"category name", "description":"description 1"})
+ category = add_object_category(value={"name": "category name", "description": "description 1"})
category_id = list(category.keys())[0]
assert category is not None
with pytest.raises(ObjectCategoryExisting):
- add_object_category(category_id, value={"name":"category name", "description":"description 2"})
+ add_object_category(category_id, value={"name": "category name", "description": "description 2"})
+
+
+def test_add_object_category_twice_with_same_name():
+ category = add_object_category(value={"name": "category name", "description": "description 1"})
+ assert category is not None
+ with pytest.raises(ObjectCategoryExisting):
+ add_object_category(value={"name": "category name", "description": "description 2"})
def get_object_category(cat_id=None):
@@ -113,7 +127,7 @@ def get_object_category(cat_id=None):
def test_get_object_categories():
- added_category = add_object_category(value={"name":"category name", "description":"description 1"})
+ added_category = add_object_category(value={"name": "category name", "description": "description 1"})
category_id = list(added_category.keys())[0]
object_category = get_object_category(category_id)
assert object_category == added_category
@@ -181,11 +195,18 @@ def add_action_category(cat_id=None, value=None):
def test_add_action_category_twice():
- category = add_action_category(value={"name":"category name", "description":"description 1"})
+ category = add_action_category(value={"name": "category name", "description": "description 1"})
category_id = list(category.keys())[0]
assert category is not None
with pytest.raises(ActionCategoryExisting):
- add_action_category(category_id, value={"name":"category name", "description":"description 2"})
+ add_action_category(category_id, value={"name": "category name", "description": "description 2"})
+
+
+def test_add_action_category_twice_with_same_name():
+ category = add_action_category(value={"name": "category name", "description": "description 1"})
+ assert category is not None
+ with pytest.raises(ActionCategoryExisting):
+ add_action_category(value={"name": "category name", "description": "description 2"})
def get_action_category(cat_id=None):
@@ -195,7 +216,7 @@ def get_action_category(cat_id=None):
def test_get_action_categories():
- added_category = add_action_category(value={"name":"category name", "description":"description 1"})
+ added_category = add_action_category(value={"name": "category name", "description": "description 1"})
category_id = list(added_category.keys())[0]
action_category = get_action_category(category_id)
assert action_category == added_category
diff --git a/python_moondb/tests/unit_python/models/test_meta_rules.py b/python_moondb/tests/unit_python/models/test_meta_rules.py
index a5a11552..4e60e11a 100644
--- a/python_moondb/tests/unit_python/models/test_meta_rules.py
+++ b/python_moondb/tests/unit_python/models/test_meta_rules.py
@@ -41,6 +41,7 @@ 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)
+
def test_set_not_exist_meta_rule_error(db):
# set not existing meta rule and expect to raise and error
with pytest.raises(Exception) as exception_info:
@@ -66,6 +67,21 @@ def test_add_new_meta_rule_success(db):
assert metaRules[meta_rule_id][key] == value[key]
+def test_add_new_meta_rule_with_same_name_twice(db):
+ value = {
+ "name": "MLS_meta_rule",
+ "description": "test",
+ "subject_categories": ["user_security_level_id_1"],
+ "object_categories": ["vm_security_level_id_1"],
+ "action_categories": ["action_type_id_1"]
+ }
+ meta_rules = add_meta_rule(value=value)
+ assert isinstance(meta_rules, dict)
+ assert meta_rules
+ with pytest.raises(Exception) as exc_info:
+ add_meta_rule(value=value)
+
+
def test_set_meta_rule_succes(db):
# arrange
meta_rules = add_meta_rule()
@@ -121,7 +137,7 @@ def test_get_meta_rule_success(db):
# action
meta_rules = get_meta_rules()
# assert
- assert isinstance(meta_rules , dict)
+ assert isinstance(meta_rules, dict)
assert meta_rules
assert len(meta_rules) is 2
for meta_rule_id in meta_rules:
@@ -132,7 +148,7 @@ def test_get_meta_rule_success(db):
def test_get_specific_meta_rule_success(db):
# arrange
- added_meta_rules = add_meta_rule()
+ added_meta_rules = add_meta_rule()
added_meta_rule_id = list(added_meta_rules.keys())[0]
# action
meta_rules = get_meta_rules(meta_rule_id=added_meta_rule_id)
diff --git a/python_moondb/tests/unit_python/models/test_models.py b/python_moondb/tests/unit_python/models/test_models.py
index 06c2b6be..251792c5 100644
--- a/python_moondb/tests/unit_python/models/test_models.py
+++ b/python_moondb/tests/unit_python/models/test_models.py
@@ -140,6 +140,20 @@ def test_add_models(db):
delete_all_models()
+def test_add_models_with_same_name_twice(db):
+ model_value1 = {
+ "name": "MLS",
+ "description": "test",
+ "meta_rules": "meta_rule_mls_1"
+ }
+ models = add_model(value=model_value1)
+ assert isinstance(models, dict)
+ assert models
+ with pytest.raises(Exception) as exc_info:
+ add_model(value=model_value1)
+ delete_all_models()
+
+
def test_delete_models(db):
model_value1 = {
"name": "MLS",
diff --git a/python_moondb/tests/unit_python/policies/test_policies.py b/python_moondb/tests/unit_python/policies/test_policies.py
index 003361d0..f1dd258f 100755
--- a/python_moondb/tests/unit_python/policies/test_policies.py
+++ b/python_moondb/tests/unit_python/policies/test_policies.py
@@ -103,6 +103,19 @@ def test_add_policies_twice_with_same_id(db):
# assert str(exception_info.value) == '409: Policy Error'
+def test_add_policies_twice_with_same_name(db):
+ value = {
+ "name": "test_policy",
+ "model_id": "",
+ "genre": "authz",
+ "description": "test",
+ }
+ add_policies(value=value)
+ with pytest.raises(Exception) as exception_info:
+ add_policies(value=value)
+ # assert str(exception_info.value) == '409: Policy Error'
+
+
def test_delete_policies(db):
value = {
"name": "test_policy1",
diff --git a/python_moondb/tests/unit_python/test_pdp.py b/python_moondb/tests/unit_python/test_pdp.py
index 5134c0fb..942d98a3 100755
--- a/python_moondb/tests/unit_python/test_pdp.py
+++ b/python_moondb/tests/unit_python/test_pdp.py
@@ -93,6 +93,19 @@ def test_add_pdp_twice_with_same_id(db):
assert str(exception_info.value) == '409: Pdp Error'
+def test_add_pdp_twice_with_same_name(db):
+ value = {
+ "name": "test_pdp",
+ "security_pipeline": ["policy_id_1", "policy_id_2"],
+ "keystone_project_id": "keystone_project_id1",
+ "description": "...",
+ }
+ add_pdp(value=value)
+ with pytest.raises(Exception) as exception_info:
+ add_pdp(value=value)
+ assert str(exception_info.value) == '409: Pdp Error'
+
+
def test_get_pdp(db):
pdp_id = "pdp_id1"
value = {