users: Fetch user groups ordered by ID to send events.

The user groups, fetched to send events when deactivating or
reactivating a user, are ordered by ID so that we can avoid
flaky behavior in tests when verifying event details in
test_do_deactivate_user and test_do_reactivate_user tests in
test_events.py.
This commit is contained in:
Sahil Batra 2024-10-11 23:05:34 +05:30 committed by Tim Abbott
parent 36183761f8
commit 5a55735ecb
2 changed files with 6 additions and 2 deletions

View File

@ -776,7 +776,9 @@ def do_reactivate_user(user_profile: UserProfile, *, acting_user: UserProfile |
subscriber_peer_info=subscriber_peer_info,
)
member_user_groups = user_profile.direct_groups.select_related("named_user_group")
member_user_groups = user_profile.direct_groups.select_related("named_user_group").order_by(
"id"
)
named_user_groups = []
setting_user_groups = []
for group in member_user_groups:

View File

@ -427,7 +427,9 @@ def send_events_for_user_deactivation(user_profile: UserProfile) -> None:
# data, but guests who cannot access the deactivated user
# need an explicit 'user_group/remove_members' event to
# update the user groups data.
deactivated_user_groups = user_profile.direct_groups.select_related("named_user_group")
deactivated_user_groups = user_profile.direct_groups.select_related(
"named_user_group"
).order_by("id")
deactivated_user_named_groups = []
deactivated_user_setting_groups = []
for group in deactivated_user_groups: