diff options
author | 2018-05-09 09:28:32 +0000 | |
---|---|---|
committer | 2018-05-09 09:28:32 +0000 | |
commit | d28f8e68ac176a15dbbd7873f757f5a9f221d118 (patch) | |
tree | fbb22197b5809c4748aece78c98132504e8f5b10 /moon_manager/tests/unit_python/api/test_assignemnt.py | |
parent | a89a8e0738ab597d80d29964a137d7f3eb9fb9a5 (diff) | |
parent | 5dffe7e0889dd76885d313c1d44a4b389f4b8667 (diff) |
Merge "continue integrating validation"
Diffstat (limited to 'moon_manager/tests/unit_python/api/test_assignemnt.py')
-rw-r--r-- | moon_manager/tests/unit_python/api/test_assignemnt.py | 75 |
1 files changed, 64 insertions, 11 deletions
diff --git a/moon_manager/tests/unit_python/api/test_assignemnt.py b/moon_manager/tests/unit_python/api/test_assignemnt.py index 9fd83857..4e2acddc 100644 --- a/moon_manager/tests/unit_python/api/test_assignemnt.py +++ b/moon_manager/tests/unit_python/api/test_assignemnt.py @@ -17,14 +17,14 @@ def add_subject_assignment(client, policy_id, category_id): "category_id": category_id, "data_id": "data_id1" } - req = client.post("/policies/{}/subject_assignments/{}".format(policy_id, category_id), data=json.dumps(data), + req = client.post("/policies/{}/subject_assignments".format(policy_id), data=json.dumps(data), headers={'Content-Type': 'application/json'}) subject_assignment = utilities.get_json(req.data) return req, subject_assignment -def delete_subject_assignment(client, policy_id): - req = client.delete("/policies/{}/subject_assignments".format(policy_id)) +def delete_subject_assignment(client, policy_id, sub_id, cat_id,data_id): + req = client.delete("/policies/{}/subject_assignments/{}/{}/{}".format(policy_id, sub_id, cat_id,data_id)) return req @@ -42,6 +42,14 @@ def test_add_subject_assignment(): assert value[id]['subject_id'] == "id1" +def test_add_subject_assignment_without_cat_id(): + policy_id = utilities.get_policy_id() + client = utilities.register_client() + req, subject_assignment = add_subject_assignment(client, policy_id, "") + assert req.status_code == 500 + assert json.loads(req.data)["message"] == 'Empty String' + + def test_get_subject_assignment(): policy_id = utilities.get_policy_id() client = utilities.register_client() @@ -54,9 +62,19 @@ def test_get_subject_assignment(): def test_delete_subject_assignment(): client = utilities.register_client() policy_id = utilities.get_policy_id() - success_req = delete_subject_assignment(client, policy_id) + req, subject_assignment = get_subject_assignment(client, policy_id) + value = subject_assignment["subject_assignments"] + id = list(value.keys())[0] + success_req = delete_subject_assignment(client, policy_id, value[id]['subject_id'], value[id]['category_id'],value[id]['assignments'][0]) assert success_req.status_code == 200 + +def test_delete_subject_assignment_without_policy_id(): + client = utilities.register_client() + success_req = delete_subject_assignment(client, "", "id1", "111" ,"data_id1") + assert success_req.status_code == 500 + + # --------------------------------------------------------------------------- # object_categories_test @@ -80,8 +98,8 @@ def add_object_assignment(client, policy_id, category_id): return req, object_assignment -def delete_object_assignment(client, policy_id): - req = client.delete("/policies/{}/object_assignments".format(policy_id)) +def delete_object_assignment(client, policy_id, obj_id, cat_id, data_id): + req = client.delete("/policies/{}/object_assignments/{}/{}/{}".format(policy_id, obj_id, cat_id, data_id)) return req @@ -108,12 +126,30 @@ def test_add_object_assignment(): assert value[id]['object_id'] == "id1" +def test_add_object_assignment_without_cat_id(): + policy_id = utilities.get_policy_id() + client = utilities.register_client() + req, object_assignment = add_object_assignment(client, policy_id, "") + assert req.status_code == 500 + assert json.loads(req.data)["message"] == 'Empty String' + + def test_delete_object_assignment(): client = utilities.register_client() policy_id = utilities.get_policy_id() - success_req = delete_object_assignment(client, policy_id) + req, object_assignment = get_object_assignment(client, policy_id) + value = object_assignment["object_assignments"] + id = list(value.keys())[0] + success_req = delete_object_assignment(client, policy_id, value[id]['object_id'], value[id]['category_id'],value[id]['assignments'][0]) assert success_req.status_code == 200 + +def test_delete_object_assignment_without_policy_id(): + client = utilities.register_client() + success_req = delete_object_assignment(client, "", "id1", "111" ,"data_id1") + assert success_req.status_code == 500 + + # --------------------------------------------------------------------------- # action_categories_test @@ -137,8 +173,8 @@ def add_action_assignment(client, policy_id, category_id): return req, action_assignment -def delete_action_assignment(client, policy_id): - req = client.delete("/policies/{}/action_assignments".format(policy_id)) +def delete_action_assignment(client, policy_id, action_id, cat_id, data_id): + req = client.delete("/policies/{}/action_assignments/{}/{}/{}".format(policy_id, action_id, cat_id, data_id)) return req @@ -165,10 +201,27 @@ def test_add_action_assignment(): assert value[id]['action_id'] == "id1" +def test_add_action_assignment_without_cat_id(): + policy_id = utilities.get_policy_id() + client = utilities.register_client() + req, action_assignment = add_action_assignment(client, policy_id, "") + assert req.status_code == 500 + assert json.loads(req.data)["message"] == 'Empty String' + + def test_delete_action_assignment(): client = utilities.register_client() policy_id = utilities.get_policy_id() - success_req = delete_action_assignment(client, policy_id) + req, action_assignment = get_action_assignment(client, policy_id) + value = action_assignment["action_assignments"] + id = list(value.keys())[0] + success_req = delete_action_assignment(client, policy_id, value[id]['action_id'], value[id]['category_id'],value[id]['assignments'][0]) assert success_req.status_code == 200 -# ---------------------------------------------------------------------------
\ No newline at end of file + +def test_delete_action_assignment_without_policy_id(): + client = utilities.register_client() + success_req = delete_action_assignment(client, "", "id1", "111" ,"data_id1") + assert success_req.status_code == 500 + +# --------------------------------------------------------------------------- |