From 0fdd8718957be35105746633e47356e1a0a21d1f Mon Sep 17 00:00:00 2001 From: Viktor van Wijk Date: Thu, 12 Dec 2024 11:04:54 +0100 Subject: [PATCH] :white_check_mark: [#4895] Move confirmation email header test to submissions app This test is not exclusive to appointments, so it makes more sense to have it in the submission app --- .../tests/test_confirmation_emails.py | 31 ------------------ .../tests/test_tasks_confirmation_emails.py | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/openforms/appointments/tests/test_confirmation_emails.py b/src/openforms/appointments/tests/test_confirmation_emails.py index 6a11d3024b..be806a825d 100644 --- a/src/openforms/appointments/tests/test_confirmation_emails.py +++ b/src/openforms/appointments/tests/test_confirmation_emails.py @@ -12,7 +12,6 @@ from django.utils.translation import gettext as _ from openforms.config.models import GlobalConfiguration -from openforms.emails.constants import EmailContentTypeChoices, EmailEventChoices from openforms.formio.typing import Component from openforms.submissions.tasks import schedule_emails from openforms.submissions.tests.factories import SubmissionFactory @@ -300,33 +299,3 @@ def test_cancel_instructions(self): with self.subTest(type="plain text"): self.assertIn(cancel_link, message_text) - - def test_headers_present_in_confirmation_email(self): - appointment = AppointmentFactory.create( - plugin="with-email", - submission__language_code="nl", - submission__form__is_appointment_form=True, - submission__form__send_confirmation_email=True, - products=[Product(identifier="dummy", name="")], - appointment_info__registration_ok=True, - contact_details_meta=[LAST_NAME, EMAIL], - contact_details={"lastName": "Powers", "email": "austin@powers.net"}, - ) - send_confirmation_email(appointment.submission) - - self.assertEqual(len(mail.outbox), 1) - message = mail.outbox[0] - - # UUID is not a constant, so just test if it exists - submission_uuid = message.extra_headers.pop("X-OF-Content-UUID", None) - self.assertIsNotNone(submission_uuid) - - # Test remaining headers - self.assertEqual( - message.extra_headers, - { - "Content-Language": "nl", - "X-OF-Content-Type": EmailContentTypeChoices.submission, - "X-OF-Event": EmailEventChoices.confirmation, - }, - ) diff --git a/src/openforms/submissions/tests/test_tasks_confirmation_emails.py b/src/openforms/submissions/tests/test_tasks_confirmation_emails.py index 2194501216..52256d918e 100644 --- a/src/openforms/submissions/tests/test_tasks_confirmation_emails.py +++ b/src/openforms/submissions/tests/test_tasks_confirmation_emails.py @@ -11,6 +11,7 @@ from privates.test import temp_private_root from openforms.config.models import GlobalConfiguration +from openforms.emails.constants import EmailContentTypeChoices, EmailEventChoices from openforms.emails.models import ConfirmationEmailTemplate from openforms.emails.tests.factories import ConfirmationEmailTemplateFactory from openforms.forms.tests.factories import FormStepFactory @@ -641,6 +642,37 @@ def test_template_is_rendered_in_submission_language(self): self.assertIn("Translated Radio option 1", html_message) self.assertIn("Translated Select option 2", html_message) + def test_headers_present_in_confirmation_email(self): + submission = SubmissionFactory.from_components( + completed=True, + components_list=[ + { + "key": "email", + "confirmationRecipient": True, + }, + ], + submitted_data={"email": "test@test.nl"}, + ) + with override_settings(CELERY_TASK_ALWAYS_EAGER=True): + send_confirmation_email(submission.id) + + self.assertEqual(len(mail.outbox), 1) + message = mail.outbox[0] + + # UUID is not a constant, so just test if it exists + submission_uuid = message.extra_headers.pop("X-OF-Content-UUID", None) + self.assertIsNotNone(submission_uuid) + + # Test remaining headers + self.assertEqual( + message.extra_headers, + { + "Content-Language": "nl", + "X-OF-Content-Type": EmailContentTypeChoices.submission, + "X-OF-Event": EmailEventChoices.confirmation, + }, + ) + class RaceConditionTests(TransactionTestCase): @patch("openforms.submissions.tasks.emails._send_confirmation_email")