Skip to content

Commit c9469df

Browse files
ewdurbinmiketheman
andauthored
fix flaky tests for user notification task (#17662)
Co-authored-by: Mike Fiedler <[email protected]>
1 parent fc5ef93 commit c9469df

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

tests/unit/accounts/test_tasks.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,18 @@ def test_notify_users_of_tos_update(db_request, user_service, monkeypatch):
4242

4343
notify_users_of_tos_update(db_request)
4444

45-
assert send_email.calls == [pretend.call(db_request, u) for u in users_to_notify]
46-
assert user_service.record_tos_engagement.calls == [
47-
pretend.call(u.id, "initial", TermsOfServiceEngagement.Notified)
48-
for u in users_to_notify
49-
]
45+
assert sorted(send_email.calls, key=lambda x: x.args[1]) == sorted(
46+
[pretend.call(db_request, u) for u in users_to_notify], key=lambda x: x.args[1]
47+
)
48+
assert sorted(
49+
user_service.record_tos_engagement.calls, key=lambda x: x.args[0]
50+
) == sorted(
51+
[
52+
pretend.call(u.id, "initial", TermsOfServiceEngagement.Notified)
53+
for u in users_to_notify
54+
],
55+
key=lambda x: x.args[0],
56+
)
5057

5158

5259
@pytest.mark.parametrize("batch_size", [0, 10])
@@ -68,16 +75,18 @@ def test_notify_users_of_tos_update_respects_batch_size(
6875

6976
notify_users_of_tos_update(db_request)
7077

71-
assert (
72-
send_email.calls
73-
== [pretend.call(db_request, u) for u in users_to_notify][:batch_size]
78+
assert sorted(send_email.calls, key=lambda x: x.args[1]) == sorted(
79+
[pretend.call(db_request, u) for u in users_to_notify][:batch_size],
80+
key=lambda x: x.args[1],
7481
)
75-
assert (
76-
user_service.record_tos_engagement.calls
77-
== [
82+
assert sorted(
83+
user_service.record_tos_engagement.calls, key=lambda x: x.args[0]
84+
) == sorted(
85+
[
7886
pretend.call(u.id, "initial", TermsOfServiceEngagement.Notified)
7987
for u in users_to_notify
80-
][:batch_size]
88+
][:batch_size],
89+
key=lambda x: x.args[0],
8190
)
8291

8392

@@ -106,13 +115,19 @@ def test_notify_users_of_tos_update_does_not_renotify(
106115

107116
notify_users_of_tos_update(db_request)
108117

109-
assert send_email.calls == [
110-
pretend.call(db_request, u) for u in users_to_notify[:-1]
111-
]
112-
assert user_service.record_tos_engagement.calls == [
113-
pretend.call(u.id, "initial", TermsOfServiceEngagement.Notified)
114-
for u in users_to_notify[:-1]
115-
]
118+
assert sorted(send_email.calls, key=lambda x: x.args[1]) == sorted(
119+
[pretend.call(db_request, u) for u in users_to_notify[:-1]],
120+
key=lambda x: x.args[1],
121+
)
122+
assert sorted(
123+
user_service.record_tos_engagement.calls, key=lambda x: x.args[0]
124+
) == sorted(
125+
[
126+
pretend.call(u.id, "initial", TermsOfServiceEngagement.Notified)
127+
for u in users_to_notify[:-1]
128+
],
129+
key=lambda x: x.args[0],
130+
)
116131

117132

118133
def _create_old_users_and_releases():

0 commit comments

Comments
 (0)