aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/auth/test_resources.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-02-03 15:15:26 +0300
committerFrederick Muriuki Muriithi2023-02-03 15:15:26 +0300
commite6dd74a3fab65355c0aa187ee31d5ee74a888649 (patch)
tree615214631357f96874b59919da4409d1b28cfe2b /tests/unit/auth/test_resources.py
parentecce454ca9d0f374e22da8401206e3b1695dbded (diff)
downloadgenenetwork3-e6dd74a3fab65355c0aa187ee31d5ee74a888649.tar.gz
auth: tests: mock token acquisition. Fix minor bugs.
Diffstat (limited to 'tests/unit/auth/test_resources.py')
-rw-r--r--tests/unit/auth/test_resources.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py
index a360442..7e3d9ad 100644
--- a/tests/unit/auth/test_resources.py
+++ b/tests/unit/auth/test_resources.py
@@ -4,6 +4,7 @@ import uuid
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.models import (
@@ -30,14 +31,16 @@ uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
(Resource(
group, 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):
+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",
+ conftest.get_tokeniser(user))
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
- assert create_resource(conn, "test_resource", resource_category) == expected
+ assert create_resource(
+ conn, "test_resource", resource_category, user) == expected
+ with db.cursor(conn) as cursor:
# Cleanup
cursor.execute(
"DELETE FROM resources WHERE resource_id=?", (str(uuid_fn()),))
@@ -50,15 +53,15 @@ def test_create_resource(mocker, fxtr_app, fxtr_users_in_group, user, expected):
(create_resource_failure, create_resource_failure,
create_resource_failure))))
def test_create_resource_raises_for_unauthorised_users(
- mocker, fxtr_app, fxtr_users_in_group, user, expected):
+ 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",
+ conftest.get_tokeniser(user))
conn, _group, _users = fxtr_users_in_group
- with fxtr_app.app_context() as flask_context:
- flask_context.g.user = user
- with pytest.raises(AuthorisationError):
- assert create_resource(
- conn, "test_resource", resource_category) == expected
+ with pytest.raises(AuthorisationError):
+ assert create_resource(
+ conn, "test_resource", resource_category, user) == expected
SORTKEY = lambda resource: resource.resource_id