diff options
author | Thomas Duval <thomas.duval@orange.com> | 2020-06-03 10:06:52 +0200 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2020-06-03 10:06:52 +0200 |
commit | 7bb53c64da2dcf88894bfd31503accdd81498f3d (patch) | |
tree | 4310e12366818af27947b5e2c80cb162da93a4b5 /old/python_moondb/tests/unit_python/test_pdp.py | |
parent | cbea4e360e9bfaa9698cf7c61c83c96a1ba89b8c (diff) |
Update to new version 5.4HEADstable/jermamaster
Signed-off-by: Thomas Duval <thomas.duval@orange.com>
Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea
Diffstat (limited to 'old/python_moondb/tests/unit_python/test_pdp.py')
-rwxr-xr-x | old/python_moondb/tests/unit_python/test_pdp.py | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/old/python_moondb/tests/unit_python/test_pdp.py b/old/python_moondb/tests/unit_python/test_pdp.py new file mode 100755 index 00000000..4d245e4d --- /dev/null +++ b/old/python_moondb/tests/unit_python/test_pdp.py @@ -0,0 +1,149 @@ +import pytest +import helpers.mock_data as mock_data +import helpers.pdp_helper as pdp_helper + + +def test_update_pdp(db): + pdp_id = "pdp_id1" + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy( + subject_category_name="subject_category1", + object_category_name="object_category1", + action_category_name="action_category1", + meta_rule_name="meta_rule_1", + model_name="model1") + value = { + "name": "test_pdp", + "security_pipeline": [policy_id], + "keystone_project_id": "keystone_project_id1", + "description": "...", + } + pdp_helper.add_pdp(pdp_id, value) + pdp = pdp_helper.update_pdp(pdp_id, value) + assert pdp + + +def test_update_pdp_with_invalid_id(db): + pdp_id = "pdp_id1" + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy( + subject_category_name="subject_category1", + object_category_name="object_category1", + action_category_name="action_category1", + meta_rule_name="meta_rule_1", + model_name="model1") + value = { + "name": "test_pdp", + "security_pipeline": [policy_id], + "keystone_project_id": "keystone_project_id1", + "description": "...", + } + with pytest.raises(Exception) as exception_info: + pdp_helper.update_pdp(pdp_id, value) + assert str(exception_info.value) == '400: Pdp Unknown' + + +def test_delete_pdp(db): + pdp_id = "pdp_id1" + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy( + subject_category_name="subject_category1", + object_category_name="object_category1", + action_category_name="action_category1", + meta_rule_name="meta_rule_1", + model_name="model1") + value = { + "name": "test_pdp", + "security_pipeline": [policy_id], + "keystone_project_id": "keystone_project_id1", + "description": "...", + } + pdp_helper.add_pdp(pdp_id, value) + pdp_helper.delete_pdp(pdp_id) + assert len(pdp_helper.get_pdp(pdp_id)) == 0 + + +def test_delete_pdp_with_invalid_id(db): + pdp_id = "pdp_id1" + with pytest.raises(Exception) as exception_info: + pdp_helper.delete_pdp(pdp_id) + assert str(exception_info.value) == '400: Pdp Unknown' + + +def test_add_pdp(db): + pdp_id = "pdp_id1" + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy( + subject_category_name="subject_category1", + object_category_name="object_category1", + action_category_name="action_category1", + meta_rule_name="meta_rule_1", + model_name="model1") + value = { + "name": "test_pdp", + "security_pipeline": [policy_id], + "keystone_project_id": "keystone_project_id1", + "description": "...", + } + pdp = pdp_helper.add_pdp(pdp_id, value) + assert pdp + + +def test_add_pdp_twice_with_same_id(db): + pdp_id = "pdp_id1" + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy( + subject_category_name="subject_category1", + object_category_name="object_category1", + action_category_name="action_category1", + meta_rule_name="meta_rule_1", + model_name="model1") + value = { + "name": "test_pdp", + "security_pipeline": [policy_id], + "keystone_project_id": "keystone_project_id1", + "description": "...", + } + pdp_helper.add_pdp(pdp_id, value) + with pytest.raises(Exception) as exception_info: + pdp_helper.add_pdp(pdp_id, value) + assert str(exception_info.value) == '409: Pdp Error' + + +def test_add_pdp_twice_with_same_name(db): + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy( + subject_category_name="subject_category1", + object_category_name="object_category1", + action_category_name="action_category1", + meta_rule_name="meta_rule_1", + model_name="model1") + value = { + "name": "test_pdp", + "security_pipeline": [policy_id], + "keystone_project_id": "keystone_project_id1", + "description": "...", + } + pdp_helper.add_pdp(value=value) + with pytest.raises(Exception) as exception_info: + pdp_helper.add_pdp(value=value) + assert str(exception_info.value) == '409: Pdp Error' + + +def test_get_pdp(db): + pdp_id = "pdp_id1" + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = mock_data.create_new_policy( + subject_category_name="subject_category1", + object_category_name="object_category1", + action_category_name="action_category1", + meta_rule_name="meta_rule_1", + model_name="model1") + value = { + "name": "test_pdp", + "security_pipeline": [policy_id], + "keystone_project_id": "keystone_project_id1", + "description": "...", + } + pdp_helper.add_pdp(pdp_id, value) + pdp = pdp_helper.get_pdp(pdp_id) + assert len(pdp) == 1 + + +def test_get_pdp_with_invalid_id(db): + pdp_id = "invalid" + pdp = pdp_helper.get_pdp(pdp_id) + assert len(pdp) == 0 |