send_email: Skip the ScheduledEmail table for 0-delay emails.

This commit is contained in:
Alex Vandiver
2025-02-28 19:27:37 +00:00
committed by Tim Abbott
parent c5200e8b05
commit 66bad1da39
8 changed files with 139 additions and 175 deletions

View File

@@ -1040,8 +1040,8 @@ class LoginTest(ZulipTestCase):
# to sending messages, such as getting the welcome bot, looking up
# the alert words for a realm, etc.
with (
self.assert_database_query_count(95),
self.assert_memcached_count(14),
self.assert_database_query_count(94),
self.assert_memcached_count(15),
self.captureOnCommitCallbacks(execute=True),
):
self.register(self.nonreg_email("test"), "test")
@@ -1239,7 +1239,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome")
result = self.client_get(urlsplit(unsubscribe_link).path)
# The welcome email jobs are no longer scheduled.
# The welcome email job are no longer scheduled.
self.assertEqual(result.status_code, 200)
self.assertEqual(0, ScheduledEmail.objects.filter(users=user_profile).count())
@@ -1248,8 +1248,8 @@ class EmailUnsubscribeTests(ZulipTestCase):
We provide one-click unsubscribe links in digest e-mails that you can
click even when logged out to stop receiving them.
Unsubscribing from these emails also dequeues any digest email jobs that
have been queued.
Since pending digests are in a RabbitMQ queue, we cannot unqueue them
once they're enqueued.
"""
user_profile = self.example_user("hamlet")
self.assertTrue(user_profile.enable_digest_emails)
@@ -1270,8 +1270,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
to_user_ids=[user_profile.id],
context=context,
)
self.assertEqual(1, ScheduledEmail.objects.filter(users=user_profile).count())
self.assert_length(ScheduledEmail.objects.filter(users=user_profile), 0)
# Simulate unsubscribing from digest e-mails.
unsubscribe_link = one_click_unsubscribe_link(user_profile, "digest")
@@ -1283,7 +1282,6 @@ class EmailUnsubscribeTests(ZulipTestCase):
user_profile.refresh_from_db()
self.assertFalse(user_profile.enable_digest_emails)
self.assertEqual(0, ScheduledEmail.objects.filter(users=user_profile).count())
def test_login_unsubscribe(self) -> None:
"""