diff options
author | Thomas Duval <thomas.duval@orange.com> | 2018-06-19 16:13:31 +0200 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2018-06-19 16:30:55 +0200 |
commit | 2dbe655587ca98b67c1a3e3798c63fd47229adc0 (patch) | |
tree | df374b5378225c9946ec0c97968bfa591fb9f9b6 /moon_manager/tests/unit_python/api/test_pdp.py | |
parent | d28f8e68ac176a15dbbd7873f757f5a9f221d118 (diff) |
Update code to 4.5 official version
Change-Id: I5075da0e2a3247ae1564f21b358748f482b75aa4
Diffstat (limited to 'moon_manager/tests/unit_python/api/test_pdp.py')
-rw-r--r-- | moon_manager/tests/unit_python/api/test_pdp.py | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/moon_manager/tests/unit_python/api/test_pdp.py b/moon_manager/tests/unit_python/api/test_pdp.py index fbaa6c7b..1ac9b84f 100644 --- a/moon_manager/tests/unit_python/api/test_pdp.py +++ b/moon_manager/tests/unit_python/api/test_pdp.py @@ -1,6 +1,7 @@ import json import api.utilities as utilities -import pytest +from helpers import data_builder as builder +from uuid import uuid4 def get_pdp(client): @@ -42,9 +43,15 @@ def test_get_pdp(): def test_add_pdp(): + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = builder.create_new_policy( + subject_category_name="subject_category1" + uuid4().hex, + object_category_name="object_category1" + uuid4().hex, + action_category_name="action_category1" + uuid4().hex, + meta_rule_name="meta_rule_1" + uuid4().hex, + model_name="model1" + uuid4().hex) data = { "name": "testuser", - "security_pipeline": ["policy_id_1", "policy_id_2"], + "security_pipeline": [policy_id], "keystone_project_id": "keystone_project_id", "description": "description of testuser" } @@ -78,8 +85,8 @@ def test_add_pdp_with_empty_user(): } client = utilities.register_client() req, models = add_pdp(client, data) - assert req.status_code == 500 - assert json.loads(req.data)["message"] == "Empty String" + assert req.status_code == 400 + assert json.loads(req.data)["message"] == "Key: 'name', [Empty String]" def test_add_pdp_with_user_contain_space(): @@ -91,8 +98,8 @@ def test_add_pdp_with_user_contain_space(): } client = utilities.register_client() req, models = add_pdp(client, data) - assert req.status_code == 500 - assert json.loads(req.data)["message"] == "String contains space" + assert req.status_code == 400 + assert json.loads(req.data)["message"] == "Key: 'name', [String contains space]" def test_add_pdp_without_security_pipeline(): @@ -104,8 +111,8 @@ def test_add_pdp_without_security_pipeline(): } client = utilities.register_client() req, meta_rules = add_pdp(client, data) - assert req.status_code == 500 - assert json.loads(req.data)["message"] == 'Empty Container' + assert req.status_code == 400 + assert json.loads(req.data)["message"] == "Key: 'security_pipeline', [Empty Container]" def test_add_pdp_without_keystone(): @@ -117,20 +124,33 @@ def test_add_pdp_without_keystone(): } client = utilities.register_client() req, meta_rules = add_pdp(client, data) - assert req.status_code == 500 - assert json.loads(req.data)["message"] == 'Empty String' + assert req.status_code == 400 + assert json.loads(req.data)["message"] == "Key: 'keystone_project_id', [Empty String]" def test_update_pdp(): + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id = builder.create_new_policy( + subject_category_name="subject_category1"+uuid4().hex, + object_category_name="object_category1"+uuid4().hex, + action_category_name="action_category1"+uuid4().hex, + meta_rule_name="meta_rule_1"+uuid4().hex, + model_name="model1"+uuid4().hex) data_add = { "name": "testuser", - "security_pipeline": ["policy_id_1", "policy_id_2"], + "security_pipeline": [policy_id], "keystone_project_id": "keystone_project_id", "description": "description of testuser" } + + subject_category_id, object_category_id, action_category_id, meta_rule_id, policy_id_update = builder.create_new_policy( + subject_category_name="subject_category1" + uuid4().hex, + object_category_name="object_category1" + uuid4().hex, + action_category_name="action_category1" + uuid4().hex, + meta_rule_name="meta_rule_1" + uuid4().hex, + model_name="model1" + uuid4().hex) data_update = { "name": "testuser", - "security_pipeline": ["policy_id_1_update", "policy_id_2_update"], + "security_pipeline": [policy_id_update], "keystone_project_id": "keystone_project_id_update", "description": "description of testuser" } @@ -151,7 +171,8 @@ def test_update_pdp(): def test_update_pdp_without_id(): client = utilities.register_client() req_update = update_pdp(client, "testuser", "") - assert req_update[0].status_code == 500 + assert req_update[0].status_code == 400 + assert json.loads(req_update[0].data)["message"] == 'Invalid Key :name not found' def test_update_pdp_without_user(): @@ -163,8 +184,8 @@ def test_update_pdp_without_user(): } client = utilities.register_client() req_update = update_pdp(client, data, "") - assert req_update[0].status_code == 500 - assert json.loads(req_update[0].data)["message"] == "Empty String" + assert req_update[0].status_code == 400 + assert json.loads(req_update[0].data)["message"] == "Key: 'name', [Empty String]" def test_update_pdp_without_security_pipeline(): @@ -176,5 +197,5 @@ def test_update_pdp_without_security_pipeline(): } client = utilities.register_client() req_update = update_pdp(client, data, "") - assert req_update[0].status_code == 500 - assert json.loads(req_update[0].data)["message"] == "Empty Container"
\ No newline at end of file + assert req_update[0].status_code == 400 + assert json.loads(req_update[0].data)["message"] == "Key: 'security_pipeline', [Empty Container]"
\ No newline at end of file |