Skip to content

Commit

Permalink
Improve archivability test performance
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lukasjuhrich committed Sep 5, 2023
1 parent 9c9a2e8 commit f715e29
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/lib/user/test_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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
):
Expand Down

0 comments on commit f715e29

Please sign in to comment.