diff options
Diffstat (limited to 'tests/unit/auth')
-rw-r--r-- | tests/unit/auth/test_groups.py | 5 | ||||
-rw-r--r-- | tests/unit/auth/test_privileges.py | 5 | ||||
-rw-r--r-- | tests/unit/auth/test_resources.py | 25 | ||||
-rw-r--r-- | tests/unit/auth/test_roles.py | 6 |
4 files changed, 27 insertions, 14 deletions
diff --git a/tests/unit/auth/test_groups.py b/tests/unit/auth/test_groups.py index 4824e14..d3b8fd4 100644 --- a/tests/unit/auth/test_groups.py +++ b/tests/unit/auth/test_groups.py @@ -19,7 +19,10 @@ create_group_failure = { "message": "Unauthorised: Failed to create group." } -uuid_fn = lambda : UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") +def uuid_fn(): + """Mock function for uuid""" + return UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") + GROUP = Group(UUID("9988c21d-f02f-4d45-8966-22c968ac2fbf"), "TheTestGroup", {"group_description": "The test group"}) diff --git a/tests/unit/auth/test_privileges.py b/tests/unit/auth/test_privileges.py index 8395293..3c645c7 100644 --- a/tests/unit/auth/test_privileges.py +++ b/tests/unit/auth/test_privileges.py @@ -6,7 +6,6 @@ from gn3.auth.authorisation.privileges import Privilege, user_privileges from tests.unit.auth import conftest -SORT_KEY = lambda x: x.privilege_id PRIVILEGES = sorted( (Privilege("system:group:create-group", "Create a group"), @@ -29,7 +28,7 @@ PRIVILEGES = sorted( Privilege("group:role:edit-role", "edit/update an existing role"), Privilege("group:user:assign-role", "Assign a role to an existing user"), Privilege("group:role:delete-role", "Delete an existing role")), - key=SORT_KEY) + key=lambda x: x.privilege_id) @pytest.mark.unit_test @pytest.mark.parametrize( @@ -43,4 +42,4 @@ def test_user_privileges(auth_testdb_path, fxtr_users, user, expected):# pylint: """ with db.connection(auth_testdb_path) as conn: assert sorted( - user_privileges(conn, user), key=SORT_KEY) == expected + user_privileges(conn, user), key=lambda x: x.privilege_id) == expected diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py index 2884add..7b9798a 100644 --- a/tests/unit/auth/test_resources.py +++ b/tests/unit/auth/test_resources.py @@ -21,7 +21,12 @@ create_resource_failure = { "status": "error", "message": "Unauthorised: Could not create resource" } -uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") + + +def uuid_fn(): + """Mock function for uuid""" + return uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") + @pytest.mark.unit_test @pytest.mark.parametrize( @@ -71,7 +76,6 @@ def test_create_resource_raises_for_unauthorised_users( assert create_resource( conn, "test_resource", resource_category, user, False) == expected -SORTKEY = lambda resource: resource.resource_id @pytest.mark.unit_test def test_public_resources(fxtr_resources): @@ -81,12 +85,16 @@ def test_public_resources(fxtr_resources): THEN: only list the resources that are public """ conn, _res = fxtr_resources - assert sorted(public_resources(conn), key=SORTKEY) == sorted(tuple( - res for res in conftest.TEST_RESOURCES if res.public), key=SORTKEY) + assert sorted( + public_resources(conn), + key=lambda resource: resource.resource_id) == sorted(tuple( + res for res in + conftest.TEST_RESOURCES + if res.public), key=lambda resource: resource.resource_id) PUBLIC_RESOURCES = sorted( {res.resource_id: res for res in conftest.TEST_RESOURCES_PUBLIC}.values(), - key=SORTKEY) + key=lambda resource: resource.resource_id) @pytest.mark.unit_test @pytest.mark.parametrize( @@ -97,13 +105,12 @@ PUBLIC_RESOURCES = sorted( {res.resource_id: res for res in (conftest.TEST_RESOURCES_GROUP_01 + conftest.TEST_RESOURCES_PUBLIC)}.values(), - key=SORTKEY), + key=lambda resource: resource.resource_id), sorted( {res.resource_id: res for res in ((conftest.TEST_RESOURCES_GROUP_01[1],) + conftest.TEST_RESOURCES_PUBLIC)}.values() - , - key=SORTKEY), + , key=lambda resource: resource.resource_id), PUBLIC_RESOURCES, PUBLIC_RESOURCES)))) def test_user_resources(fxtr_group_user_roles, user, expected): """ @@ -114,4 +121,4 @@ def test_user_resources(fxtr_group_user_roles, user, expected): conn, *_others = fxtr_group_user_roles assert sorted( {res.resource_id: res for res in user_resources(conn, user) - }.values(), key=SORTKEY) == expected + }.values(), key=lambda resource: resource.resource_id) == expected diff --git a/tests/unit/auth/test_roles.py b/tests/unit/auth/test_roles.py index 02fd9f7..8e22bb5 100644 --- a/tests/unit/auth/test_roles.py +++ b/tests/unit/auth/test_roles.py @@ -16,7 +16,11 @@ create_role_failure = { "message": "Unauthorised: Could not create role" } -uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") + +def uuid_fn(): + """Mock function for uuid""" + return uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") + PRIVILEGES = ( Privilege("group:resource:view-resource", |