about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-16 15:14:40 -0500
committerFrederick Muriuki Muriithi2024-09-16 15:19:21 -0500
commit3c47081696e5a81f70e4ed509267725bc904434c (patch)
tree0a5290f789c3765ac3b228af7b4eddb12acbec4d /tests
parente829074e99fd5bec033765d18d5efa55e1edce44 (diff)
downloadgn-auth-3c47081696e5a81f70e4ed509267725bc904434c.tar.gz
Pass cursor rather than connection to create_resource function
In order to decouple the `create_resource` function from the related
functions that assign roles to users, this commit changes the code to
pass in a cursor rather than a connection.

The cursor will be the same cursor passed into the role assignment
functions ensuring that the resource creation and role assignment
happen in a single transaction.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/auth/test_resources.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py
index 9b45b68..7f0b43d 100644
--- a/tests/unit/auth/test_resources.py
+++ b/tests/unit/auth/test_resources.py
@@ -47,11 +47,11 @@ def test_create_resource(# pylint: disable=[too-many-arguments, unused-argument]
             user,
             tuple(client for client in clients if client.user == user)[0]))
     conn, _group, _users = fxtr_users_in_group
-    resource = create_resource(
-        conn, "test_resource", resource_category, user, False)
-    assert resource == expected
 
     with db.cursor(conn) as cursor:
+        resource = create_resource(
+            cursor, "test_resource", resource_category, user, _group, False)
+        assert resource == expected
         # Cleanup
         cursor.execute(
             "DELETE FROM user_roles WHERE resource_id=?",
@@ -82,8 +82,15 @@ def test_create_resource_raises_for_unauthorised_users(
             tuple(client for client in clients if client.user == user)[0]))
     conn, _group, _users = fxtr_users_in_group
     with pytest.raises(AuthorisationError):
-        assert create_resource(
-            conn, "test_resource", resource_category, user, False) == expected
+        with db.cursor(conn) as cursor:
+            assert create_resource(
+                cursor,
+                "test_resource",
+                resource_category,
+                user,
+                _group,
+                False
+            ) == expected
 
 def sort_key_resources(resource):
     """Sort-key for resources."""