Skip to content

Commit f715e29

Browse files
committed
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.
1 parent 9c9a2e8 commit f715e29

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tests/lib/user/test_deletion.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pycroft.helpers.interval import closed, closedopen
1010
from pycroft.helpers.utc import with_min_time
1111
from pycroft.lib.user_deletion import (
12-
get_archivable_members,
12+
select_archivable_members,
1313
archive_users,
1414
ArchivableMemberInfo,
1515
)
@@ -19,6 +19,11 @@
1919
HostFactory
2020

2121

22+
def get_archivable_members(session, current_year=2022):
23+
"""Like `get_archivable_members`, just without all the joinedloads."""
24+
return session.execute(select_archivable_members(current_year)).all()
25+
26+
2227
@pytest.fixture(scope='module')
2328
def config(module_session):
2429
return ConfigFactory()
@@ -95,7 +100,7 @@ def do_not_archive_membership(self, session, old_user, do_not_archive_group):
95100
active_during=closedopen(datetime(2020, 1, 1), None),
96101
)
97102

98-
@pytest.mark.parametrize("year", [2022, 2023, 2024])
103+
@pytest.mark.parametrize("year", [2022, 2023])
99104
def test_old_users_in_deletion_list_after(self, session, old_user, year, end_date):
100105
members = get_archivable_members(session, current_year=year)
101106
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):
106111
get_archivable_members(session, current_year=year), old_user
107112
)
108113

109-
@pytest.mark.parametrize("year", list(range(2018, 2023)))
114+
@pytest.mark.parametrize("year", list(range(2019, 2023)))
110115
def test_user_with_do_not_archive_not_in_list(
111116
self, session, old_user, do_not_archive_membership, year
112117
):

0 commit comments

Comments
 (0)