From 04eb04e86512f0da36ea03e7a010a45f3082c2b4 Mon Sep 17 00:00:00 2001 From: Julian Dehm Date: Thu, 21 Dec 2023 16:32:36 +0100 Subject: [PATCH] tests/notifications: fix flaky email test --- changelog/_4567.md | 4 ++++ tests/notifications/test_creator_notifications.py | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/changelog/_4567.md b/changelog/_4567.md index 473794e5d..0ea2ce740 100644 --- a/changelog/_4567.md +++ b/changelog/_4567.md @@ -2,3 +2,7 @@ - test helper for testing emails - initial doc on testing + +### Fixed + +- fixed the flaky test_notify_creator_exclude_moderator test diff --git a/tests/notifications/test_creator_notifications.py b/tests/notifications/test_creator_notifications.py index 37d74acda..47062f139 100644 --- a/tests/notifications/test_creator_notifications.py +++ b/tests/notifications/test_creator_notifications.py @@ -3,6 +3,7 @@ from django.urls import reverse from adhocracy4.test.helpers import redirect_target +from tests.helpers import get_emails_for_address @pytest.mark.django_db @@ -33,10 +34,11 @@ def test_notify_creator_exclude_moderator(idea, comment_factory, user): comment_factory(content_object=idea) assert len(mail.outbox) == 3 + mails = get_emails_for_address(creator_moderator.email) + assert len(mails) == 1 # moderator notification instead of creator notification - assert mail.outbox[1].to[0] == creator_moderator.email - assert not mail.outbox[1].subject.startswith("Reaction to your contribution") - assert mail.outbox[1].subject.startswith("A comment was added to the project") + assert not mails[0].subject.startswith("Reaction to your contribution") + assert mails[0].subject.startswith("A comment was added to the project") @pytest.mark.django_db