about summary refs log tree commit diff
path: root/tests/unit/auth/test_resources.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-01-18 14:59:35 +0300
committerFrederick Muriuki Muriithi2023-01-18 14:59:35 +0300
commit4cc328ef78c7b8108d7623fdd4fcae5294317f2e (patch)
tree5fff59d3a57bb6e0ec044373f205ed4503d8b47a /tests/unit/auth/test_resources.py
parente97703817628e6b781c5b883ed3aa7fbf9967628 (diff)
downloadgenenetwork3-4cc328ef78c7b8108d7623fdd4fcae5294317f2e.tar.gz
auth: Fix tests after enforcing FOREIGN KEY constraint
Fix a number of tests and fixtures that were not conforming to the FOREIGN KEY
constraints:

* Each test that creates a new "object" needs to clean up after itself
* Each fixture that sets up test data needs to clean up after itself
Diffstat (limited to 'tests/unit/auth/test_resources.py')
-rw-r--r--tests/unit/auth/test_resources.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py
index b756cd9..e6ebeb9 100644
--- a/tests/unit/auth/test_resources.py
+++ b/tests/unit/auth/test_resources.py
@@ -3,6 +3,7 @@ import uuid
 
 import pytest
 
+from gn3.auth import db
 from gn3.auth.authorisation.groups import Group
 from gn3.auth.authorisation.resources import (
     Resource, user_resources, create_resource, ResourceCategory,
@@ -35,10 +36,14 @@ def test_create_resource(mocker, fxtr_app, fxtr_users_in_group, user, expected):
     """Test that resource creation works as expected."""
     mocker.patch("gn3.auth.authorisation.resources.uuid4", uuid_fn)
     conn, _group, _users = fxtr_users_in_group
-    with fxtr_app.app_context() as flask_context:
+    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
 
+        # Cleanup
+        cursor.execute(
+            "DELETE FROM resources WHERE resource_id=?", (str(uuid_fn()),))
+
 SORTKEY = lambda resource: resource.resource_id
 
 @pytest.mark.unit_test
@@ -74,5 +79,5 @@ def test_user_resources(fxtr_group_user_roles, user, expected):
     WHEN: a particular user's resources are requested
     THEN: list only the resources for which the user can access
     """
-    conn = fxtr_group_user_roles
+    conn, *_others = fxtr_group_user_roles
     assert sorted(user_resources(conn, user), key=SORTKEY) == expected