Skip to content

Commit

Permalink
✅ [#3005] Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Nov 17, 2023
1 parent d9b5b7f commit 8190297
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/openforms/payments/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
116 changes: 116 additions & 0 deletions src/openforms/submissions/tests/test_post_submission_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]"},
completed=True,
cosign_complete=False,
form__registration_backend="email",
form__registration_backend_options={"to_emails": ["[email protected]"]},
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, ["[email protected]"])
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": "[email protected]"}

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": "[email protected]", "email": "[email protected]"},
completed=True,
cosign_complete=False,
form__registration_backend="email",
form__registration_backend_options={"to_emails": ["[email protected]"]},
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, ["[email protected]"])
self.assertEqual(
mails[1].subject, _("Bevestiging van uw inzending van Pretty Form")
)
self.assertEqual(mails[1].to, ["[email protected]"])
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": "[email protected]"}

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")
19 changes: 9 additions & 10 deletions src/openforms/submissions/tests/test_tasks_confirmation_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8190297

Please sign in to comment.