diff options
Diffstat (limited to 'tests/unit/auth')
20 files changed, 68 insertions, 68 deletions
diff --git a/tests/unit/auth/conftest.py b/tests/unit/auth/conftest.py index a7c64a8..facfb81 100644 --- a/tests/unit/auth/conftest.py +++ b/tests/unit/auth/conftest.py @@ -3,7 +3,7 @@ import uuid import datetime from contextlib import contextmanager -from gn3.auth.authentication.oauth2.models.oauth2token import OAuth2Token +from gn_auth.auth.authentication.oauth2.models.oauth2token import OAuth2Token from .fixtures import * # pylint: disable=[wildcard-import,unused-wildcard-import] diff --git a/tests/unit/auth/fixtures/group_fixtures.py b/tests/unit/auth/fixtures/group_fixtures.py index d7bbc56..b2bae24 100644 --- a/tests/unit/auth/fixtures/group_fixtures.py +++ b/tests/unit/auth/fixtures/group_fixtures.py @@ -3,9 +3,9 @@ import uuid import pytest -from gn3.auth import db -from gn3.auth.authorisation.groups import Group, GroupRole -from gn3.auth.authorisation.resources import Resource, ResourceCategory +from gn_auth.auth import db +from gn_auth.auth.authorisation.groups import Group, GroupRole +from gn_auth.auth.authorisation.resources import Resource, ResourceCategory from .role_fixtures import RESOURCE_EDITOR_ROLE, RESOURCE_READER_ROLE diff --git a/tests/unit/auth/fixtures/migration_fixtures.py b/tests/unit/auth/fixtures/migration_fixtures.py index eb42c2b..2a67c01 100644 --- a/tests/unit/auth/fixtures/migration_fixtures.py +++ b/tests/unit/auth/fixtures/migration_fixtures.py @@ -4,8 +4,8 @@ from yoyo.backends import DatabaseBackend from yoyo import get_backend, read_migrations from yoyo.migrations import Migration, MigrationList -from gn3.auth import db -from gn3.migrations import apply_migrations, rollback_migrations +from gn_auth.auth import db +from gn_auth.migrations import apply_migrations, rollback_migrations @pytest.fixture(scope="session") def auth_testdb_path(fxtr_app_config): # pylint: disable=redefined-outer-name diff --git a/tests/unit/auth/fixtures/oauth2_client_fixtures.py b/tests/unit/auth/fixtures/oauth2_client_fixtures.py index 654d048..70cd2c2 100644 --- a/tests/unit/auth/fixtures/oauth2_client_fixtures.py +++ b/tests/unit/auth/fixtures/oauth2_client_fixtures.py @@ -5,9 +5,9 @@ import datetime import pytest -from gn3.auth import db -from gn3.auth.authentication.users import hash_password -from gn3.auth.authentication.oauth2.models.oauth2client import OAuth2Client +from gn_auth.auth import db +from gn_auth.auth.authentication.users import hash_password +from gn_auth.auth.authentication.oauth2.models.oauth2client import OAuth2Client @pytest.fixture(autouse=True) def fxtr_patch_envvars(monkeypatch): diff --git a/tests/unit/auth/fixtures/resource_fixtures.py b/tests/unit/auth/fixtures/resource_fixtures.py index 117b4f4..efe617e 100644 --- a/tests/unit/auth/fixtures/resource_fixtures.py +++ b/tests/unit/auth/fixtures/resource_fixtures.py @@ -1,7 +1,7 @@ """Fixtures and utilities for resource-related tests""" import pytest -from gn3.auth import db +from gn_auth.auth import db from .group_fixtures import TEST_RESOURCES diff --git a/tests/unit/auth/fixtures/role_fixtures.py b/tests/unit/auth/fixtures/role_fixtures.py index ee86aa2..c97716f 100644 --- a/tests/unit/auth/fixtures/role_fixtures.py +++ b/tests/unit/auth/fixtures/role_fixtures.py @@ -3,9 +3,9 @@ import uuid import pytest -from gn3.auth import db -from gn3.auth.authorisation.roles import Role -from gn3.auth.authorisation.privileges import Privilege +from gn_auth.auth import db +from gn_auth.auth.authorisation.roles import Role +from gn_auth.auth.authorisation.privileges import Privilege RESOURCE_READER_ROLE = Role( uuid.UUID("c3ca2507-ee24-4835-9b31-8c21e1c072d3"), "resource_reader", True, diff --git a/tests/unit/auth/fixtures/user_fixtures.py b/tests/unit/auth/fixtures/user_fixtures.py index d248f54..21708a5 100644 --- a/tests/unit/auth/fixtures/user_fixtures.py +++ b/tests/unit/auth/fixtures/user_fixtures.py @@ -3,8 +3,8 @@ import uuid import pytest -from gn3.auth import db -from gn3.auth.authentication.users import User, hash_password +from gn_auth.auth import db +from gn_auth.auth.authentication.users import User, hash_password TEST_USERS = ( User(uuid.UUID("ecb52977-3004-469e-9428-2a1856725c7f"), "group@lead.er", diff --git a/tests/unit/auth/test_credentials.py b/tests/unit/auth/test_credentials.py index f2a3d25..8011ec2 100644 --- a/tests/unit/auth/test_credentials.py +++ b/tests/unit/auth/test_credentials.py @@ -3,9 +3,9 @@ import pytest from yoyo.migrations import MigrationList from hypothesis import given, settings, strategies, HealthCheck -from gn3.auth import db -from gn3.auth.authentication import credentials_in_database -from gn3.migrations import get_migration, apply_migrations, rollback_migrations +from gn_auth.auth import db +from gn_auth.auth.authentication import credentials_in_database +from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import migrations_up_to diff --git a/tests/unit/auth/test_groups.py b/tests/unit/auth/test_groups.py index 4824e14..8a47cf8 100644 --- a/tests/unit/auth/test_groups.py +++ b/tests/unit/auth/test_groups.py @@ -4,12 +4,12 @@ from uuid import UUID import pytest from pymonad.maybe import Nothing -from gn3.auth import db -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.models import ( +from gn_auth.auth import db +from gn_auth.auth.authentication.users import User +from gn_auth.auth.authorisation.roles import Role +from gn_auth.auth.authorisation.privileges import Privilege +from gn_auth.auth.authorisation.errors import AuthorisationError +from gn_auth.auth.authorisation.groups.models import ( Group, GroupRole, user_group, create_group, create_group_role) from tests.unit.auth import conftest @@ -45,8 +45,8 @@ 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.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.groups.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) with db.connection(auth_testdb_path) as conn: assert create_group( @@ -61,8 +61,8 @@ 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.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.groups.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) with db.connection(auth_testdb_path) as conn: with pytest.raises(AuthorisationError): @@ -88,9 +88,9 @@ def test_create_group_role(mocker, fxtr_users_in_group, 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.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.roles.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.groups.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.roles.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) conn, _group, _users = fxtr_users_in_group with db.cursor(conn) as cursor: @@ -114,9 +114,9 @@ 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.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.roles.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.groups.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.roles.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) conn, _group, _users = fxtr_users_in_group with pytest.raises(AuthorisationError): @@ -132,11 +132,11 @@ def test_create_multiple_groups(mocker, fxtr_users): THEN: The system should prevent that, and respond with an appropriate error message """ - mocker.patch("gn3.auth.authorisation.groups.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.groups.models.uuid4", uuid_fn) user = User( UUID("ecb52977-3004-469e-9428-2a1856725c7f"), "group@lead.er", "Group Leader") - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) conn, _test_users = fxtr_users # First time, successfully creates the group diff --git a/tests/unit/auth/test_migrations_add_data_to_table.py b/tests/unit/auth/test_migrations_add_data_to_table.py index 9cb5d0c..fa46cc9 100644 --- a/tests/unit/auth/test_migrations_add_data_to_table.py +++ b/tests/unit/auth/test_migrations_add_data_to_table.py @@ -1,8 +1,8 @@ """Test data insertion when migrations are run.""" import pytest -from gn3.auth import db -from gn3.migrations import get_migration, apply_migrations, rollback_migrations +from gn_auth.auth import db +from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_add_remove_columns.py b/tests/unit/auth/test_migrations_add_remove_columns.py index ea9bf7b..a44563a 100644 --- a/tests/unit/auth/test_migrations_add_remove_columns.py +++ b/tests/unit/auth/test_migrations_add_remove_columns.py @@ -1,8 +1,8 @@ """Test migrations that alter tables adding/removing columns.""" import pytest -from gn3.auth import db -from gn3.migrations import get_migration, apply_migrations, rollback_migrations +from gn_auth.auth import db +from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_create_tables.py b/tests/unit/auth/test_migrations_create_tables.py index 2b8140b..f56489a 100644 --- a/tests/unit/auth/test_migrations_create_tables.py +++ b/tests/unit/auth/test_migrations_create_tables.py @@ -1,8 +1,8 @@ """Test migrations that create tables""" import pytest -from gn3.auth import db -from gn3.migrations import get_migration, apply_migrations, rollback_migrations +from gn_auth.auth import db +from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_drop_tables.py b/tests/unit/auth/test_migrations_drop_tables.py index 2362c77..4ce0d45 100644 --- a/tests/unit/auth/test_migrations_drop_tables.py +++ b/tests/unit/auth/test_migrations_drop_tables.py @@ -2,8 +2,8 @@ import pytest -from gn3.auth import db -from gn3.migrations import get_migration, apply_migrations, rollback_migrations +from gn_auth.auth import db +from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_indexes.py b/tests/unit/auth/test_migrations_indexes.py index b1f06d9..dcec7c4 100644 --- a/tests/unit/auth/test_migrations_indexes.py +++ b/tests/unit/auth/test_migrations_indexes.py @@ -1,8 +1,8 @@ """Test that indexes are created and removed.""" import pytest -from gn3.auth import db -from gn3.migrations import get_migration, apply_migrations, rollback_migrations +from gn_auth.auth import db +from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_init_data_in_resource_categories_table.py b/tests/unit/auth/test_migrations_init_data_in_resource_categories_table.py index dd3d4c6..8a92ae1 100644 --- a/tests/unit/auth/test_migrations_init_data_in_resource_categories_table.py +++ b/tests/unit/auth/test_migrations_init_data_in_resource_categories_table.py @@ -3,8 +3,8 @@ Test that the `resource_categories` table is initialised with the startup data. """ import pytest -from gn3.auth import db -from gn3.migrations import get_migration, apply_migrations, rollback_migrations +from gn_auth.auth import db +from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_insert_data_into_empty_table.py b/tests/unit/auth/test_migrations_insert_data_into_empty_table.py index ebb7fa6..0cf9a1f 100644 --- a/tests/unit/auth/test_migrations_insert_data_into_empty_table.py +++ b/tests/unit/auth/test_migrations_insert_data_into_empty_table.py @@ -4,7 +4,7 @@ from contextlib import closing import pytest -from gn3.migrations import get_migration, apply_migrations, rollback_migrations +from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_privileges.py b/tests/unit/auth/test_privileges.py index 8395293..a40e875 100644 --- a/tests/unit/auth/test_privileges.py +++ b/tests/unit/auth/test_privileges.py @@ -1,8 +1,8 @@ """Test the privileges module""" import pytest -from gn3.auth import db -from gn3.auth.authorisation.privileges import Privilege, user_privileges +from gn_auth.auth import db +from gn_auth.auth.authorisation.privileges import Privilege, user_privileges from tests.unit.auth import conftest diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py index 2884add..12b8d95 100644 --- a/tests/unit/auth/test_resources.py +++ b/tests/unit/auth/test_resources.py @@ -3,11 +3,11 @@ import uuid import pytest -from gn3.auth import db +from gn_auth.auth import db -from gn3.auth.authorisation.groups import Group -from gn3.auth.authorisation.errors import AuthorisationError -from gn3.auth.authorisation.resources.models import ( +from gn_auth.auth.authorisation.groups import Group +from gn_auth.auth.authorisation.errors import AuthorisationError +from gn_auth.auth.authorisation.resources.models import ( Resource, user_resources, create_resource, ResourceCategory, public_resources) @@ -33,8 +33,8 @@ uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b") "test_resource", resource_category, False),)))) def test_create_resource(mocker, fxtr_users_in_group, user, expected): """Test that resource creation works as expected.""" - mocker.patch("gn3.auth.authorisation.resources.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.resources.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) conn, _group, _users = fxtr_users_in_group resource = create_resource( @@ -63,8 +63,8 @@ def test_create_resource(mocker, fxtr_users_in_group, user, expected): def test_create_resource_raises_for_unauthorised_users( mocker, fxtr_users_in_group, user, expected): """Test that resource creation works as expected.""" - mocker.patch("gn3.auth.authorisation.resources.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.resources.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) conn, _group, _users = fxtr_users_in_group with pytest.raises(AuthorisationError): diff --git a/tests/unit/auth/test_roles.py b/tests/unit/auth/test_roles.py index 02fd9f7..31d5e8e 100644 --- a/tests/unit/auth/test_roles.py +++ b/tests/unit/auth/test_roles.py @@ -3,10 +3,10 @@ import uuid 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.models import Role, user_roles, create_role +from gn_auth.auth import db +from gn_auth.auth.authorisation.privileges import Privilege +from gn_auth.auth.authorisation.errors import AuthorisationError +from gn_auth.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,8 +36,8 @@ 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.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.roles.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) with db.connection(auth_testdb_path) as conn, db.cursor(conn) as cursor: the_role = create_role(cursor, "a_test_role", PRIVILEGES) @@ -55,8 +55,8 @@ 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.models.uuid4", uuid_fn) - mocker.patch("gn3.auth.authorisation.checks.require_oauth.acquire", + mocker.patch("gn_auth.auth.authorisation.roles.models.uuid4", uuid_fn) + mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire", conftest.get_tokeniser(user)) with db.connection(auth_testdb_path) as conn, db.cursor(conn) as cursor: with pytest.raises(AuthorisationError): diff --git a/tests/unit/auth/test_token.py b/tests/unit/auth/test_token.py index 76316ea..4a864fe 100644 --- a/tests/unit/auth/test_token.py +++ b/tests/unit/auth/test_token.py @@ -2,7 +2,7 @@ import pytest -from gn3.auth import db +from gn_auth.auth import db SUCCESS_RESULT = { "status_code": 200, |