From 364a4376c3a6aca6ed816f68bdee4a906dad0d28 Mon Sep 17 00:00:00 2001 From: Lukas Juhrich Date: Fri, 5 Aug 2022 01:13:54 +0200 Subject: [PATCH] Improve archivability test performance 1. We restrict the ranges to a smaller subset which is still meaningful. 2. We use the `select` statement itself rather than the wrapper method adding a ton of `joinedload`s. --- tests/lib/user/test_deletion.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/lib/user/test_deletion.py b/tests/lib/user/test_deletion.py index dae88b8d1..413f0703c 100644 --- a/tests/lib/user/test_deletion.py +++ b/tests/lib/user/test_deletion.py @@ -9,7 +9,7 @@ from pycroft.helpers.interval import closed, closedopen from pycroft.helpers.utc import with_min_time from pycroft.lib.user_deletion import ( - get_archivable_members, + select_archivable_members, archive_users, ArchivableMemberInfo, ) @@ -19,6 +19,11 @@ HostFactory +def get_archivable_members(session, current_year=2022): + """Like `get_archivable_members`, just without all the joinedloads.""" + return session.execute(select_archivable_members(current_year)).all() + + @pytest.fixture(scope='module') def config(module_session): return ConfigFactory() @@ -95,7 +100,7 @@ def do_not_archive_membership(self, session, old_user, do_not_archive_group): active_during=closedopen(datetime(2020, 1, 1), None), ) - @pytest.mark.parametrize("year", [2022, 2023, 2024]) + @pytest.mark.parametrize("year", [2022, 2023]) def test_old_users_in_deletion_list_after(self, session, old_user, year, end_date): members = get_archivable_members(session, current_year=year) assert_member_present(members, old_user, end_date) @@ -106,7 +111,7 @@ def test_old_user_not_in_list_before(self, session, old_user, year): get_archivable_members(session, current_year=year), old_user ) - @pytest.mark.parametrize("year", list(range(2018, 2023))) + @pytest.mark.parametrize("year", list(range(2019, 2023))) def test_user_with_do_not_archive_not_in_list( self, session, old_user, do_not_archive_membership, year ):