diff options
author | Frederick Muriuki Muriithi | 2022-11-24 13:42:37 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-11-24 13:52:29 +0300 |
commit | 021b8dfcb99928b363e4546f626e3deb5793e392 (patch) | |
tree | 107182d01dc7e5fd802fadb4e12cd88867748c36 /tests/unit/auth/conftest.py | |
parent | bac3865f7c0d625f2932e1c3fb001cc6a0048921 (diff) | |
download | genenetwork3-021b8dfcb99928b363e4546f626e3deb5793e392.tar.gz |
auth: Implement `create_resource` function
* gn3/auth/authentication/checks.py: new `authenticated_p` decorator to apply
on any function that requires the user to be authenticated before it runs.
* gn3/auth/authorisation/checks.py: use a `auth.authentication.users.User`
object rather than a UUID object in the global `g`.
* gn3/auth/authorisation/groups.py: Implement the `authenticated_user_group`
function to get the group(s) in which the currently authenticated user
belongs.
* gn3/auth/authorisation/resources.py: Implement the `create_resource`
function correctly.
* tests/unit/auth/conftest.py: extract the User objects into a global variable
for reusability with the tests.
* tests/unit/auth/test_resources.py: Use global user objects from conftest in
the tests. Set a User object (rather than UUID) in the global `g` variable.
Diffstat (limited to 'tests/unit/auth/conftest.py')
-rw-r--r-- | tests/unit/auth/conftest.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tests/unit/auth/conftest.py b/tests/unit/auth/conftest.py index 37d78a3..e582640 100644 --- a/tests/unit/auth/conftest.py +++ b/tests/unit/auth/conftest.py @@ -65,29 +65,30 @@ def test_group(conn_after_auth_migrations):# pylint: disable=[redefined-outer-na yield (conn_after_auth_migrations, Group(group_id, group_name)) +TEST_USERS = ( + User(uuid.UUID("ecb52977-3004-469e-9428-2a1856725c7f"), "group@lead.er", + "Group Leader"), + User(uuid.UUID("21351b66-8aad-475b-84ac-53ce528451e3"), + "group@mem.ber01", "Group Member 01"), + User(uuid.UUID("ae9c6245-0966-41a5-9a5e-20885a96bea7"), + "group@mem.ber02", "Group Member 02"), + User(uuid.UUID("9a0c7ce5-2f40-4e78-979e-bf3527a59579"), + "unaff@iliated.user", "Unaffiliated User")) + @pytest.fixture(scope="function") def test_users(conn_after_auth_migrations):# pylint: disable=[redefined-outer-name] """Fixture: setup test users.""" query = "INSERT INTO users(user_id, email, name) VALUES (?, ?, ?)" query_user_roles = "INSERT INTO user_roles(user_id, role_id) VALUES (?, ?)" - the_users = ( - ("ecb52977-3004-469e-9428-2a1856725c7f", "group@lead.er", - "Group Leader"), - ("21351b66-8aad-475b-84ac-53ce528451e3", "group@mem.ber01", - "Group Member 01"), - ("ae9c6245-0966-41a5-9a5e-20885a96bea7", "group@mem.ber02", - "Group Member 02"), - ("9a0c7ce5-2f40-4e78-979e-bf3527a59579", "unaff@iliated.user", - "Unaffiliated User")) test_user_roles = ( ("ecb52977-3004-469e-9428-2a1856725c7f", "a0e67630-d502-4b9f-b23f-6805d0f30e30"),) with db.cursor(conn_after_auth_migrations) as cursor: - cursor.executemany(query, the_users) + cursor.executemany(query, ( + (str(user.user_id), user.email, user.name) for user in TEST_USERS)) cursor.executemany(query_user_roles, test_user_roles) - yield (conn_after_auth_migrations, tuple( - User(uuid.UUID(uid), email, name) for uid, email, name in the_users)) + yield (conn_after_auth_migrations, TEST_USERS) with db.cursor(conn_after_auth_migrations) as cursor: cursor.executemany( |