From 906ab2dbab5bf8bebefe1ebf5a1018bf356279d5 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Fri, 5 Feb 2021 12:13:11 +0100 Subject: [PATCH] rename some exceptions --- tests/test_administration.py | 54 ++++++++++++++--------------- tests/test_permissions.py | 2 +- tests/test_server_side_scripting.py | 6 ++-- tests/test_tickets_200.py | 2 +- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/test_administration.py b/tests/test_administration.py index 8347f02..9ecc136 100644 --- a/tests/test_administration.py +++ b/tests/test_administration.py @@ -28,8 +28,8 @@ from caosdb import administration as admin from caosdb.connection.connection import configure_connection, get_connection -from caosdb.exceptions import (HTTPClientError, HTTPAuthorizationError, - LoginFailedError, ResourceNotFoundError) +from caosdb.exceptions import (HTTPClientError, HTTPForbiddenError, + LoginFailedError, HTTPResourceNotFoundError) from nose.tools import (assert_equal, assert_is_not_none, assert_raises, assert_true) from pytest import raises @@ -104,7 +104,7 @@ def test_insert_role_success(): def test_insert_role_failure_permission(): switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._insert_role(name=test_role, description=test_role_desc) assert cm.value.msg == "You are not permitted to insert a new role." @@ -130,13 +130,13 @@ def test_update_role_success(): def test_update_role_failure_permissions(): test_insert_role_success() switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._update_role(name=test_role, description=test_role_desc + "asdf") assert cm.value.msg == "You are not permitted to update this role." def test_update_role_failure_non_existing(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._update_role(name=test_role, description=test_role_desc + "asdf") assert cm.value.msg == "Role does not exist." @@ -149,13 +149,13 @@ def test_delete_role_success(): def test_delete_role_failure_permissions(): test_insert_role_success() switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._delete_role(name=test_role) assert cm.value.msg == "You are not permitted to delete this role." def test_delete_role_failure_non_existing(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._delete_role(name=test_role) assert cm.value.msg == "Role does not exist." @@ -169,13 +169,13 @@ def test_retrieve_role_success(): def test_retrieve_role_failure_permission(): test_insert_role_success() switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._retrieve_role(name=test_role) assert cm.value.msg == "You are not permitted to retrieve this role." def test_retrieve_role_failure_non_existing(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._retrieve_role(name=test_role) assert cm.value.msg == "Role does not exist." @@ -194,7 +194,7 @@ def test_set_permissions_success(): def test_set_permissions_failure_permissions(): test_insert_role_success() switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._set_permissions( role=test_role, permission_rules=[ admin.PermissionRule( @@ -203,7 +203,7 @@ def test_set_permissions_failure_permissions(): def test_set_permissions_failure_non_existing(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._set_permissions( role=test_role, permission_rules=[ admin.PermissionRule( @@ -221,13 +221,13 @@ def test_get_permissions_success(): def test_get_permissions_failure_permissions(): test_set_permissions_success() switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._get_permissions(role=test_role) assert cm.value.msg == "You are not permitted to retrieve this role's permissions." def test_get_permissions_failure_non_existing(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._get_permissions(role="non-existing-role") assert cm.value.msg == "Role does not exist." @@ -243,13 +243,13 @@ def test_get_roles_success(): def test_get_roles_failure_permissions(): test_insert_role_success() switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._get_roles(username=test_user) assert cm.value.msg == "You are not permitted to retrieve this user's roles." def test_get_roles_failure_non_existing(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._get_roles(username="non-existing-user") assert cm.value.msg == "User does not exist." @@ -276,7 +276,7 @@ def test_set_roles_failure_permissions(): roles = {test_role} roles.union(roles_old) switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._set_roles(username=test_user, roles=roles_old) assert cm.value.msg == "You are not permitted to set this user's roles." @@ -291,7 +291,7 @@ def test_set_roles_failure_non_existing_role(): def test_set_roles_failure_non_existing_user(): test_insert_role_success() roles = {test_role} - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._set_roles(username="non-existing-user", roles=roles) assert cm.value.msg == "User does not exist." @@ -307,7 +307,7 @@ def test_insert_user_success(): def test_insert_user_failure_permissions(): switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._insert_user( name=test_user, password="secret1P!", @@ -332,13 +332,13 @@ def test_delete_user_success(): def test_delete_user_failure_permissions(): test_insert_user_success() switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._delete_user(name="non_existing_user") assert cm.value.msg == "You are not permitted to delete this user." def test_delete_user_failure_non_existing(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._delete_user(name="non_existing_user") assert cm.value.msg == "User does not exist." @@ -412,7 +412,7 @@ def test_update_user_failure_permissions_status(): status="INACTIVE", email="email@example.com", entity=None) is not None switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._update_user( realm=None, name=test_user + "2", @@ -428,7 +428,7 @@ def test_update_user_failure_permissions_email(): password="secret1P!", status="ACTIVE", email="email@example.com", entity=None) is not None switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._update_user( realm=None, name=test_user + "2", @@ -444,7 +444,7 @@ def test_update_user_failure_permissions_entity(): password="secret1P!", status="ACTIVE", email="email@example.com", entity=None) is not None switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._update_user( realm=None, name=test_user + "2", @@ -460,7 +460,7 @@ def test_update_user_failure_permissions_password(): password="secret1P!", status="ACTIVE", email="email@example.com", entity=None) is not None switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._update_user( realm=None, name=test_user + "2", @@ -472,7 +472,7 @@ def test_update_user_failure_permissions_password(): def test_update_user_failure_non_existing_user(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._update_user( realm=None, name="non-existing-user", @@ -506,13 +506,13 @@ def test_retrieve_user_success(): def test_retrieve_user_failure_permissions(): test_insert_user_success() switch_to_normal_user() - with raises(HTTPAuthorizationError) as cm: + with raises(HTTPForbiddenError) as cm: admin._retrieve_user(realm=None, name=test_user + "2") assert cm.value.msg == "You are not permitted to retrieve this user." def test_retrieve_user_failure_non_existing(): - with raises(ResourceNotFoundError) as cm: + with raises(HTTPResourceNotFoundError) as cm: admin._retrieve_user(realm=None, name="non_existing") assert cm.value.msg == "User does not exist." diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 9b534dc..1953b38 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -938,7 +938,7 @@ def test_download_file(): grant_permission(f2, "RETRIEVE:ENTITY") deny_permission(f2, "RETRIEVE:FILE") - with raises(db.HTTPAuthorizationError): + with raises(db.HTTPForbiddenError): f.download() '''SUCCESS''' diff --git a/tests/test_server_side_scripting.py b/tests/test_server_side_scripting.py index 168f2f0..d61cc5f 100644 --- a/tests/test_server_side_scripting.py +++ b/tests/test_server_side_scripting.py @@ -34,7 +34,7 @@ from http.client import HTTPSConnection import ssl from caosdb import get_connection, get_config, Info, execute_query, RecordType from caosdb.exceptions import (HTTPClientError, - ResourceNotFoundError) + HTTPResourceNotFoundError) from caosdb.connection.encode import MultipartParam, multipart_encode from caosdb.connection.utils import urlencode, urlparse from caosdb import administration as admin @@ -109,7 +109,7 @@ def teardown_module(): def test_call_script_non_existing(): form = dict() form["call"] = "non_existing_script" - with raises(ResourceNotFoundError): + with raises(HTTPResourceNotFoundError): get_connection().post_form_data("scripting", form) @@ -397,5 +397,5 @@ def test_evil_path(): _SERVER_SIDE_SCRIPTING_BIN_DIR_LOCAL, "ok")) - with raises(ResourceNotFoundError): + with raises(HTTPResourceNotFoundError): r = run_server_side_script("../ok") diff --git a/tests/test_tickets_200.py b/tests/test_tickets_200.py index 1084b03..1b242c8 100644 --- a/tests/test_tickets_200.py +++ b/tests/test_tickets_200.py @@ -198,7 +198,7 @@ def test_ticket_232(): for i in range(1000): uri.append("longname" + str(i)) - # with raises(h.URITooLongError) as exc_info: + # with raises(h.HTTPURITooLongError) as exc_info: # h.get_connection().retrieve(uri) c = h.Container().extend(uri).retrieve(raise_exception_on_error=False) -- GitLab