From 4cc328ef78c7b8108d7623fdd4fcae5294317f2e Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 18 Jan 2023 14:59:35 +0300 Subject: 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 --- tests/unit/auth/test_groups.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/unit/auth/test_groups.py') diff --git a/tests/unit/auth/test_groups.py b/tests/unit/auth/test_groups.py index 53e0543..158360e 100644 --- a/tests/unit/auth/test_groups.py +++ b/tests/unit/auth/test_groups.py @@ -73,10 +73,15 @@ def test_create_group_role(mocker, fxtr_users_in_group, fxtr_app, user, expected mocker.patch("gn3.auth.authorisation.groups.uuid4", uuid_fn) mocker.patch("gn3.auth.authorisation.roles.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_group_role( conn, GROUP, "ResourceEditor", PRIVILEGES) == expected + # cleanup + cursor.execute( + ("DELETE FROM group_roles " + "WHERE group_role_id=? AND group_id=? AND role_id=?"), + (str(uuid_fn()), str(GROUP.group_id), str(uuid_fn()))) @pytest.mark.unit_test def test_create_multiple_groups(mocker, fxtr_app, fxtr_users): -- cgit v1.2.3