diff options
author | Frederick Muriuki Muriithi | 2022-12-12 13:33:13 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-12-12 13:33:13 +0300 |
commit | 5269d0e9927a18f7266d53ecb67a81c7eadf70b9 (patch) | |
tree | 8076d960d860b1bed533c12d33616c580221d94d /tests/unit/auth/fixtures/role_fixtures.py | |
parent | 2344e4cd55cc37dac93ab2127a456a39dc4fedbe (diff) | |
download | genenetwork3-5269d0e9927a18f7266d53ecb67a81c7eadf70b9.tar.gz |
tests: Update fixtures to use for testing resources functions
Diffstat (limited to 'tests/unit/auth/fixtures/role_fixtures.py')
-rw-r--r-- | tests/unit/auth/fixtures/role_fixtures.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/tests/unit/auth/fixtures/role_fixtures.py b/tests/unit/auth/fixtures/role_fixtures.py index f8b0f6f..befa6b0 100644 --- a/tests/unit/auth/fixtures/role_fixtures.py +++ b/tests/unit/auth/fixtures/role_fixtures.py @@ -1,9 +1,45 @@ """Fixtures and utilities for role-related tests""" +import uuid + import pytest from gn3.auth import db +from gn3.auth.authorisation.roles import Role +from gn3.auth.authorisation.privileges import Privilege + +RESOURCE_READER_ROLE = Role( + uuid.UUID("c3ca2507-ee24-4835-9b31-8c21e1c072d3"), "resource_reader", + (Privilege(uuid.UUID("7f261757-3211-4f28-a43f-a09b800b164d"), + "view-resource"),)) + +RESOURCE_EDITOR_ROLE = Role( + uuid.UUID("89819f84-6346-488b-8955-86062e9eedb7"), "resource_editor", ( + Privilege(uuid.UUID("7f261757-3211-4f28-a43f-a09b800b164d"), + "view-resource"), + Privilege(uuid.UUID("2f980855-959b-4339-b80e-25d1ec286e21"), + "edit-resource"))) + +TEST_ROLES = (RESOURCE_READER_ROLE, RESOURCE_EDITOR_ROLE) @pytest.fixture(scope="function") -def fixture_user_roles(test_users_in_group): - conn, *_others = test_users_in_group - raise Exception("NOT IMPLEMENTED ...") +def fixture_roles(conn_after_auth_migrations): + """Setup some example roles.""" + with db.cursor(conn_after_auth_migrations) as cursor: + cursor.executemany( + ("INSERT INTO roles VALUES (?, ?, ?)"), + ((str(role.role_id), role.role_name, 1) for role in TEST_ROLES)) + cursor.executemany( + ("INSERT INTO role_privileges VALUES (?, ?)"), + ((str(role.role_id), str(privilege.privilege_id)) + for role in TEST_ROLES for privilege in role.privileges)) + + yield conn_after_auth_migrations, TEST_ROLES + + with db.cursor(conn_after_auth_migrations) as cursor: + cursor.executemany( + ("DELETE FROM role_privileges WHERE role_id=? AND privilege_id=?"), + ((str(role.role_id), str(privilege.privilege_id)) + for role in TEST_ROLES for privilege in role.privileges)) + cursor.executemany( + ("DELETE FROM roles WHERE role_id=?"), + ((str(role.role_id),) for role in TEST_ROLES)) |