From e6dd74a3fab65355c0aa187ee31d5ee74a888649 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 3 Feb 2023 15:15:26 +0300 Subject: auth: tests: mock token acquisition. Fix minor bugs. --- tests/unit/auth/test_roles.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/unit/auth/test_roles.py') diff --git a/tests/unit/auth/test_roles.py b/tests/unit/auth/test_roles.py index 9152042..30b7f43 100644 --- a/tests/unit/auth/test_roles.py +++ b/tests/unit/auth/test_roles.py @@ -37,11 +37,11 @@ def test_create_role(# pylint: disable=[too-many-arguments] appropriate privileges """ 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: - the_role = create_role(cursor, "a_test_role", PRIVILEGES) - assert the_role == expected + mocker.patch("gn3.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) + assert the_role == expected @pytest.mark.unit_test @pytest.mark.parametrize( @@ -56,11 +56,11 @@ def test_create_role_raises_exception_for_unauthorised_users(# pylint: disable=[ appropriate privileges """ 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: - with pytest.raises(AuthorisationError): - create_role(cursor, "a_test_role", PRIVILEGES) + mocker.patch("gn3.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): + create_role(cursor, "a_test_role", PRIVILEGES) @pytest.mark.unit_test @pytest.mark.parametrize( -- cgit v1.2.3