From 819029729c392babbff2c52091790369b737bb37 Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Fri, 17 Nov 2023 12:51:26 +0100 Subject: [PATCH] :white_check_mark: [#3005] Fix tests --- src/openforms/payments/tests/test_views.py | 4 +- .../tests/test_post_submission_event.py | 116 ++++++++++++++++++ .../tests/test_tasks_confirmation_emails.py | 19 ++- 3 files changed, 127 insertions(+), 12 deletions(-) diff --git a/src/openforms/payments/tests/test_views.py b/src/openforms/payments/tests/test_views.py index c039f52177..e7a55f26f7 100644 --- a/src/openforms/payments/tests/test_views.py +++ b/src/openforms/payments/tests/test_views.py @@ -33,7 +33,7 @@ class ViewsTests(TestCase): @override_settings( CORS_ALLOW_ALL_ORIGINS=False, CORS_ALLOWED_ORIGINS=["http://allowed.foo"] ) - @patch("openforms.payments.views.update_submission_payment_status.delay") + @patch("openforms.payments.views.on_post_submission_event") def test_views(self, update_payments_mock): register = Registry() register("plugin1")(Plugin) @@ -172,7 +172,7 @@ def test_views(self, update_payments_mock): CORS_ALLOW_ALL_ORIGINS=False, CORS_ALLOWED_ORIGINS=["http://allowed.foo"] ) @patch("openforms.plugins.registry.GlobalConfiguration.get_solo") - @patch("openforms.payments.views.update_submission_payment_status.delay") + @patch("openforms.payments.views.on_post_submission_event") def test_start_plugin_not_enabled(self, update_payments_mock, mock_get_solo): register = Registry() register("plugin1")(Plugin) diff --git a/src/openforms/submissions/tests/test_post_submission_event.py b/src/openforms/submissions/tests/test_post_submission_event.py index 5c09ed564f..6076de8ef3 100644 --- a/src/openforms/submissions/tests/test_post_submission_event.py +++ b/src/openforms/submissions/tests/test_post_submission_event.py @@ -754,3 +754,119 @@ def test_submission_completed_incomplete_appointment(self): with self.assertRaises(AppointmentRegistrationFailed): on_post_submission_event(submission.id) + + def test_cosign_not_required_and_not_filled_in_proceeds_with_registration(self): + submission = SubmissionFactory.from_components( + components_list=[ + { + "key": "email", + "type": "email", + "label": "Email", + "confirmationRecipient": True, + }, + { + "key": "cosign", + "type": "cosign", + "label": "Cosign component", + "validate": {"required": False}, + }, + ], + submitted_data={"cosign": "", "email": "test@test.nl"}, + completed=True, + cosign_complete=False, + form__registration_backend="email", + form__registration_backend_options={"to_emails": ["test@registration.nl"]}, + form__name="Pretty Form", + auth_info__attribute=AuthAttribute.bsn, + auth_info__value="111222333", + ) + + with patch( + "openforms.registrations.contrib.email.plugin.EmailRegistration.register_submission" + ) as mock_registration, patch( + "openforms.registrations.contrib.email.plugin.EmailRegistration.update_payment_status" + ) as mock_payment_status_update: + on_post_submission_event(submission.id) + + mock_registration.assert_called_once() + mock_payment_status_update.assert_not_called() + + mails = mail.outbox + + self.assertEqual(1, len(mails)) # No cosign request email! + self.assertEqual( + mails[0].subject, _("Bevestiging van uw inzending van Pretty Form") + ) + self.assertEqual(mails[0].to, ["test@test.nl"]) + self.assertEqual(mails[0].cc, []) + + cosign_info = _( + "This form will not be processed until it has been co-signed. A co-sign request was sent to %(cosigner_email)s." + ) % {"cosigner_email": "cosign@test.nl"} + + self.assertNotIn(cosign_info, mails[0].body.strip("\n")) + + submission.refresh_from_db() + + self.assertFalse(submission.cosign_request_email_sent) + self.assertTrue(submission.confirmation_email_sent) + self.assertNotEqual(submission.auth_info.value, "111222333") + + def test_cosign_not_required_but_filled_in_does_not_proceed_with_registration(self): + submission = SubmissionFactory.from_components( + components_list=[ + { + "key": "email", + "type": "email", + "label": "Email", + "confirmationRecipient": True, + }, + { + "key": "cosign", + "type": "cosign", + "label": "Cosign component", + "validate": {"required": False}, + }, + ], + submitted_data={"cosign": "cosign@test.nl", "email": "test@test.nl"}, + completed=True, + cosign_complete=False, + form__registration_backend="email", + form__registration_backend_options={"to_emails": ["test@registration.nl"]}, + form__name="Pretty Form", + auth_info__attribute=AuthAttribute.bsn, + auth_info__value="111222333", + ) + + with patch( + "openforms.registrations.contrib.email.plugin.EmailRegistration.register_submission" + ) as mock_registration, patch( + "openforms.registrations.contrib.email.plugin.EmailRegistration.update_payment_status" + ) as mock_payment_status_update: + on_post_submission_event(submission.id) + + mock_registration.assert_not_called() + mock_payment_status_update.assert_not_called() + + mails = mail.outbox + + self.assertEqual(2, len(mails)) + self.assertEqual(mails[0].subject, _("Co-sign request for Pretty Form")) + self.assertEqual(mails[0].to, ["cosign@test.nl"]) + self.assertEqual( + mails[1].subject, _("Bevestiging van uw inzending van Pretty Form") + ) + self.assertEqual(mails[1].to, ["test@test.nl"]) + self.assertEqual(mails[1].cc, []) + + cosign_info = _( + "This form will not be processed until it has been co-signed. A co-sign request was sent to %(cosigner_email)s." + ) % {"cosigner_email": "cosign@test.nl"} + + self.assertIn(cosign_info, mails[1].body.strip("\n")) + + submission.refresh_from_db() + + self.assertTrue(submission.cosign_request_email_sent) + self.assertTrue(submission.confirmation_email_sent) + self.assertEqual(submission.auth_info.value, "111222333") diff --git a/src/openforms/submissions/tests/test_tasks_confirmation_emails.py b/src/openforms/submissions/tests/test_tasks_confirmation_emails.py index 74fc1280f0..092c7b75f2 100644 --- a/src/openforms/submissions/tests/test_tasks_confirmation_emails.py +++ b/src/openforms/submissions/tests/test_tasks_confirmation_emails.py @@ -18,7 +18,6 @@ from openforms.forms.tests.factories import FormStepFactory from openforms.utils.tests.html_assert import HTMLAssertMixin -from ..tasks import maybe_send_confirmation_email from ..tasks.emails import schedule_emails, send_confirmation_email from .factories import SubmissionFactory, SubmissionStepFactory @@ -32,7 +31,7 @@ def test_task_without_mail_template(self): ), "There should not be any mail templates" with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) self.assertEqual(len(mail.outbox), 0) @@ -93,7 +92,7 @@ def test_completed_submission_send_confirmation_email(self): # "execute" the celery task with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) # Verify that email was sent self.assertEqual(len(mail.outbox), 1) @@ -126,7 +125,7 @@ def test_complete_submission_without_email_recipient(self): # "execute" the celery task with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) # assert that no e-mail was sent self.assertEqual(len(mail.outbox), 0) @@ -187,7 +186,7 @@ def test_complete_submission_send_confirmation_email_with_summary(self): # "execute" the celery task with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) # Verify that email was sent self.assertEqual(len(mail.outbox), 1) @@ -262,7 +261,7 @@ def test_complete_submission_send_confirmation_email_to_many_recipients(self): # "execute" the celery task with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) # Verify that email was sent self.assertEqual(len(mail.outbox), 1) @@ -296,7 +295,7 @@ def test_completed_submission_with_incomplete_payment_delays_confirmation_email( with patch.object(send_confirmation_email, "apply_async") as mock_apply_async: # "execute" the celery task - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) # verify timeout task is delayed mock_apply_async.assert_called_once_with( @@ -449,7 +448,7 @@ def test_completed_submission_with_confirmation_email_when_already_sent( # "execute" the celery task with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) # assert that no e-mail was sent self.assertEqual(len(mail.outbox), 0) @@ -511,7 +510,7 @@ def test_send_confirmation_email_when_appointment_is_changed(self): # "execute" the celery task with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) # Verify that email was sent self.assertEqual(len(mail.outbox), 1) @@ -638,7 +637,7 @@ def test_template_is_rendered_in_submission_language(self): # "execute" the celery task with override_settings(CELERY_TASK_ALWAYS_EAGER=True): - maybe_send_confirmation_email(submission.id) + schedule_emails(submission.id) # Verify that email was sent self.assertEqual(len(mail.outbox), 1)