From dfe5eb18e3ec8dc570d118bfe95c5d4dcb2c7575 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 2 Feb 2023 11:35:51 +0300 Subject: auth: Reorganise modules/packages for easier dev and maintenance Split the views/routes into separate modules each dealing with a narrower scope of the application to aid in maintenance, and help with making the development easier. --- tests/unit/auth/test_groups.py | 16 ++++++++-------- tests/unit/auth/test_resources.py | 6 +++--- tests/unit/auth/test_roles.py | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/auth/test_groups.py b/tests/unit/auth/test_groups.py index 219b82a..18f9b23 100644 --- a/tests/unit/auth/test_groups.py +++ b/tests/unit/auth/test_groups.py @@ -9,7 +9,7 @@ from gn3.auth.authentication.users import User from gn3.auth.authorisation.roles import Role from gn3.auth.authorisation.privileges import Privilege from gn3.auth.authorisation.errors import AuthorisationError -from gn3.auth.authorisation.groups import ( +from gn3.auth.authorisation.groups.models import ( Group, GroupRole, user_group, create_group, MembershipError, create_group_role) @@ -46,7 +46,7 @@ def test_create_group(# pylint: disable=[too-many-arguments] THEN: verify they are only able to create the group if they have the appropriate privileges """ - mocker.patch("gn3.auth.authorisation.groups.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.groups.models.uuid4", uuid_fn) with fxtr_app.app_context() as flask_context: flask_context.g.user = user with db.connection(auth_testdb_path) as conn: @@ -62,7 +62,7 @@ def test_create_group_raises_exception_with_non_privileged_user(# pylint: disabl WHEN: the user attempts to create a group THEN: verify the system raises an exception """ - mocker.patch("gn3.auth.authorisation.groups.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.groups.models.uuid4", uuid_fn) with fxtr_app.app_context() as flask_context: flask_context.g.user = user with db.connection(auth_testdb_path) as conn: @@ -89,8 +89,8 @@ def test_create_group_role(mocker, fxtr_users_in_group, fxtr_app, user, expected THEN: verify they are only able to create the role if they have the appropriate privileges and that the role is attached to the given group """ - mocker.patch("gn3.auth.authorisation.groups.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.roles.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.groups.models.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.roles.models.uuid4", uuid_fn) conn, _group, _users = fxtr_users_in_group with fxtr_app.app_context() as flask_context, db.cursor(conn) as cursor: flask_context.g.user = user @@ -114,8 +114,8 @@ def test_create_group_role_raises_exception_with_unauthorised_users( THEN: verify they are only able to create the role if they have the appropriate privileges and that the role is attached to the given group """ - mocker.patch("gn3.auth.authorisation.groups.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.roles.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.groups.models.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.roles.models.uuid4", uuid_fn) conn, _group, _users = fxtr_users_in_group with fxtr_app.app_context() as flask_context: flask_context.g.user = user @@ -132,7 +132,7 @@ def test_create_multiple_groups(mocker, fxtr_app, fxtr_users): THEN: The system should prevent that, and respond with an appropriate error message """ - mocker.patch("gn3.auth.authorisation.groups.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.groups.models.uuid4", uuid_fn) user = User( UUID("ecb52977-3004-469e-9428-2a1856725c7f"), "group@lead.er", "Group Leader") diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py index a0236c4..a360442 100644 --- a/tests/unit/auth/test_resources.py +++ b/tests/unit/auth/test_resources.py @@ -6,7 +6,7 @@ import pytest from gn3.auth import db from gn3.auth.authorisation.groups import Group from gn3.auth.authorisation.errors import AuthorisationError -from gn3.auth.authorisation.resources import ( +from gn3.auth.authorisation.resources.models import ( Resource, user_resources, create_resource, ResourceCategory, public_resources) @@ -32,7 +32,7 @@ uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") "test_resource", resource_category, False),)))) def test_create_resource(mocker, fxtr_app, fxtr_users_in_group, user, expected): """Test that resource creation works as expected.""" - mocker.patch("gn3.auth.authorisation.resources.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.resources.models.uuid4", uuid_fn) conn, _group, _users = fxtr_users_in_group with fxtr_app.app_context() as flask_context, db.cursor(conn) as cursor: flask_context.g.user = user @@ -52,7 +52,7 @@ def test_create_resource(mocker, fxtr_app, fxtr_users_in_group, user, expected): def test_create_resource_raises_for_unauthorised_users( mocker, fxtr_app, fxtr_users_in_group, user, expected): """Test that resource creation works as expected.""" - mocker.patch("gn3.auth.authorisation.resources.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.resources.models.uuid4", uuid_fn) conn, _group, _users = fxtr_users_in_group with fxtr_app.app_context() as flask_context: flask_context.g.user = user diff --git a/tests/unit/auth/test_roles.py b/tests/unit/auth/test_roles.py index 78ff8a6..9152042 100644 --- a/tests/unit/auth/test_roles.py +++ b/tests/unit/auth/test_roles.py @@ -6,7 +6,7 @@ import pytest from gn3.auth import db from gn3.auth.authorisation.privileges import Privilege from gn3.auth.authorisation.errors import AuthorisationError -from gn3.auth.authorisation.roles import Role, user_roles, create_role +from gn3.auth.authorisation.roles.models import Role, user_roles, create_role from tests.unit.auth import conftest from tests.unit.auth.fixtures import TEST_USERS @@ -36,7 +36,7 @@ def test_create_role(# pylint: disable=[too-many-arguments] THEN: verify they are only able to create the role if they have the appropriate privileges """ - mocker.patch("gn3.auth.authorisation.roles.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.roles.models.uuid4", uuid_fn) with fxtr_app.app_context() as flask_context: flask_context.g.user = user with db.connection(auth_testdb_path) as conn, db.cursor(conn) as cursor: @@ -55,7 +55,7 @@ def test_create_role_raises_exception_for_unauthorised_users(# pylint: disable=[ THEN: verify they are only able to create the role if they have the appropriate privileges """ - mocker.patch("gn3.auth.authorisation.roles.uuid4", uuid_fn) + mocker.patch("gn3.auth.authorisation.roles.models.uuid4", uuid_fn) with fxtr_app.app_context() as flask_context: flask_context.g.user = user with db.connection(auth_testdb_path) as conn, db.cursor(conn) as cursor: -- cgit v1.2.3