-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e54452c
commit 95c923a
Showing
2 changed files
with
800 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,18 @@ | |
|
||
from django.core import mail | ||
from django.test import TestCase, override_settings | ||
from django.utils.translation import gettext as _ | ||
|
||
from django_yubin.models import Message | ||
from freezegun import freeze_time | ||
|
||
from openforms.config.models import GlobalConfiguration | ||
from openforms.logging.tests.factories import TimelineLogProxyFactory | ||
from openforms.submissions.tasks import schedule_emails | ||
from openforms.submissions.tests.factories import SubmissionFactory | ||
|
||
from ...payments.constants import PaymentStatus | ||
from ...payments.tests.factories import SubmissionPaymentFactory | ||
from ..tasks import send_email_digest | ||
|
||
|
||
|
@@ -177,3 +181,369 @@ def test_no_recipients(self): | |
send_email_digest() | ||
|
||
self.assertEqual(0, len(mail.outbox)) | ||
|
||
|
||
@override_settings(CELERY_TASK_ALWAYS_EAGER=True, LANGUAGE_CODE="nl") | ||
class QueueEmailsTaskTests(TestCase): | ||
def test_submission_completed_cosign_and_payment_not_needed(self): | ||
submission = SubmissionFactory.from_components( | ||
components_list=[ | ||
{ | ||
"key": "email", | ||
"type": "email", | ||
"label": "Email", | ||
"confirmationRecipient": True, | ||
} | ||
], | ||
form__name="Pretty Form", | ||
submitted_data={"email": "[email protected]"}, | ||
completed=True, | ||
cosign_complete=False, | ||
confirmation_email_sent=False, | ||
) | ||
|
||
with self.captureOnCommitCallbacks(execute=True): | ||
schedule_emails(submission.id) | ||
|
||
mails = mail.outbox | ||
|
||
self.assertEqual(1, len(mails)) | ||
self.assertEqual( | ||
mails[0].subject, "Bevestiging van uw inzending van Pretty Form" | ||
) | ||
self.assertEqual(mails[0].to, ["[email protected]"]) | ||
self.assertEqual(mails[0].cc, []) | ||
|
||
submission.refresh_from_db() | ||
|
||
self.assertTrue(submission.confirmation_email_sent) | ||
self.assertFalse(submission.cosign_request_email_sent) | ||
|
||
def test_submission_completed_cosign_needed(self): | ||
submission = SubmissionFactory.from_components( | ||
components_list=[ | ||
{ | ||
"key": "email", | ||
"type": "email", | ||
"label": "Email", | ||
"confirmationRecipient": True, | ||
}, | ||
{ | ||
"key": "cosign", | ||
"type": "cosign", | ||
"label": "Cosign component", | ||
"validate": {"required": True}, | ||
}, | ||
], | ||
submitted_data={"email": "[email protected]", "cosign": "[email protected]"}, | ||
completed=True, | ||
cosign_request_email_sent=False, | ||
cosign_complete=False, | ||
confirmation_email_sent=False, | ||
form__name="Pretty Form", | ||
) | ||
|
||
with self.captureOnCommitCallbacks(execute=True): | ||
schedule_emails(submission.id) | ||
|
||
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) | ||
|
||
def test_submission_completed_payment_needed(self): | ||
submission = SubmissionFactory.from_components( | ||
components_list=[ | ||
{ | ||
"key": "email", | ||
"type": "email", | ||
"label": "Email", | ||
"confirmationRecipient": True, | ||
}, | ||
], | ||
submitted_data={ | ||
"email": "[email protected]", | ||
}, | ||
completed=True, | ||
confirmation_email_sent=False, | ||
form__name="Pretty Form", | ||
form__product__price=10, | ||
form__payment_backend="demo", | ||
) | ||
SubmissionPaymentFactory.create( | ||
submission=submission, amount=10, status=PaymentStatus.started | ||
) | ||
|
||
with self.captureOnCommitCallbacks(execute=True): | ||
schedule_emails(submission.id) | ||
|
||
mails = mail.outbox | ||
|
||
self.assertEqual(1, len(mails)) | ||
self.assertEqual( | ||
mails[0].subject, "Bevestiging van uw inzending van Pretty Form" | ||
) | ||
self.assertEqual(mails[0].to, ["[email protected]"]) | ||
self.assertEqual(mails[0].cc, []) | ||
|
||
payment_info = _( | ||
"Payment of EUR %(payment_price)s is required. You can pay using the link below." | ||
) % {"payment_price": "10,00"} | ||
|
||
self.assertIn(payment_info, mails[0].body.strip("\n")) | ||
|
||
submission.refresh_from_db() | ||
|
||
self.assertTrue(submission.confirmation_email_sent) | ||
self.assertFalse(submission.cosign_request_email_sent) | ||
|
||
def test_submission_completed_cosign_and_payment_needed(self): | ||
submission = SubmissionFactory.from_components( | ||
components_list=[ | ||
{ | ||
"key": "email", | ||
"type": "email", | ||
"label": "Email", | ||
"confirmationRecipient": True, | ||
}, | ||
{ | ||
"key": "cosign", | ||
"type": "cosign", | ||
"label": "Cosign component", | ||
"validate": {"required": True}, | ||
}, | ||
], | ||
submitted_data={"email": "[email protected]", "cosign": "[email protected]"}, | ||
completed=True, | ||
cosign_request_email_sent=False, | ||
cosign_complete=False, | ||
confirmation_email_sent=False, | ||
form__name="Pretty Form", | ||
form__product__price=10, | ||
form__payment_backend="demo", | ||
) | ||
SubmissionPaymentFactory.create( | ||
submission=submission, amount=10, status=PaymentStatus.started | ||
) | ||
|
||
with self.captureOnCommitCallbacks(execute=True): | ||
schedule_emails(submission.id) | ||
|
||
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]"} | ||
payment_info = _( | ||
"Payment of EUR %(payment_price)s is required. You can pay using the link below." | ||
) % {"payment_price": "10,00"} | ||
|
||
self.assertIn(cosign_info, mails[1].body.strip("\n")) | ||
self.assertIn(payment_info, mails[1].body.strip("\n")) | ||
|
||
submission.refresh_from_db() | ||
|
||
self.assertTrue(submission.cosign_request_email_sent) | ||
self.assertTrue(submission.confirmation_email_sent) | ||
|
||
def test_cosign_done_payment_not_needed(self): | ||
submission = SubmissionFactory.from_components( | ||
components_list=[ | ||
{ | ||
"key": "email", | ||
"type": "email", | ||
"label": "Email", | ||
"confirmationRecipient": True, | ||
}, | ||
{ | ||
"key": "cosign", | ||
"type": "cosign", | ||
"label": "Cosign component", | ||
"validate": {"required": True}, | ||
}, | ||
], | ||
submitted_data={"email": "[email protected]", "cosign": "[email protected]"}, | ||
completed=True, | ||
cosign_request_email_sent=True, | ||
cosign_complete=True, | ||
confirmation_email_sent=True, | ||
form__name="Pretty Form", | ||
) | ||
|
||
with self.captureOnCommitCallbacks(execute=True): | ||
schedule_emails(submission.id) | ||
|
||
mails = mail.outbox | ||
|
||
self.assertEqual(1, len(mails)) | ||
self.assertEqual( | ||
mails[0].subject, "Bevestiging van uw inzending van Pretty Form" | ||
) | ||
self.assertEqual(mails[0].to, ["[email protected]"]) | ||
self.assertEqual(mails[0].cc, ["[email protected]"]) | ||
|
||
cosign_info = _( | ||
"This email is a confirmation that this form has been co-signed by %(cosigner_email)s and can now be processed." | ||
) % {"cosigner_email": "[email protected]"} | ||
|
||
self.assertIn(cosign_info, mails[0].body.strip("\n")) | ||
|
||
submission.refresh_from_db() | ||
|
||
self.assertTrue(submission.cosign_confirmation_email_sent) | ||
|
||
def test_cosign_done_payment_needed_not_done(self): | ||
submission = SubmissionFactory.from_components( | ||
components_list=[ | ||
{ | ||
"key": "email", | ||
"type": "email", | ||
"label": "Email", | ||
"confirmationRecipient": True, | ||
}, | ||
{ | ||
"key": "cosign", | ||
"type": "cosign", | ||
"label": "Cosign component", | ||
"validate": {"required": True}, | ||
}, | ||
], | ||
submitted_data={"email": "[email protected]", "cosign": "[email protected]"}, | ||
completed=True, | ||
cosign_request_email_sent=True, | ||
cosign_complete=True, | ||
confirmation_email_sent=True, | ||
form__name="Pretty Form", | ||
form__product__price=10, | ||
form__payment_backend="demo", | ||
) | ||
SubmissionPaymentFactory.create( | ||
submission=submission, amount=10, status=PaymentStatus.started | ||
) | ||
|
||
with self.captureOnCommitCallbacks(execute=True): | ||
schedule_emails(submission.id) | ||
|
||
mails = mail.outbox | ||
|
||
self.assertEqual(1, len(mails)) | ||
self.assertEqual( | ||
mails[0].subject, "Bevestiging van uw inzending van Pretty Form" | ||
) | ||
self.assertEqual(mails[0].to, ["[email protected]"]) | ||
self.assertEqual(mails[0].cc, ["[email protected]"]) | ||
|
||
cosign_info = _( | ||
"This email is a confirmation that this form has been co-signed by %(cosigner_email)s and can now be processed." | ||
) % {"cosigner_email": "[email protected]"} | ||
payment_info = _( | ||
"Payment of EUR %(payment_price)s is required. You can pay using the link below." | ||
) % {"payment_price": "10,00"} | ||
|
||
self.assertIn(cosign_info, mails[0].body.strip("\n")) | ||
self.assertIn(payment_info, mails[0].body.strip("\n")) | ||
|
||
submission.refresh_from_db() | ||
|
||
self.assertTrue(submission.cosign_confirmation_email_sent) | ||
self.assertFalse(submission.payment_complete_confirmation_email_sent) | ||
|
||
def test_cosign_done_payment_done(self): | ||
submission = SubmissionFactory.from_components( | ||
components_list=[ | ||
{ | ||
"key": "email", | ||
"type": "email", | ||
"label": "Email", | ||
"confirmationRecipient": True, | ||
}, | ||
{ | ||
"key": "cosign", | ||
"type": "cosign", | ||
"label": "Cosign component", | ||
"validate": {"required": True}, | ||
}, | ||
], | ||
submitted_data={"email": "[email protected]", "cosign": "[email protected]"}, | ||
completed=True, | ||
cosign_request_email_sent=True, | ||
cosign_complete=True, | ||
confirmation_email_sent=True, | ||
form__name="Pretty Form", | ||
form__product__price=10, | ||
form__payment_backend="demo", | ||
) | ||
SubmissionPaymentFactory.create( | ||
submission=submission, amount=10, status=PaymentStatus.completed | ||
) | ||
|
||
with self.captureOnCommitCallbacks(execute=True): | ||
schedule_emails(submission.id) | ||
|
||
mails = mail.outbox | ||
|
||
self.assertEqual(1, len(mails)) | ||
self.assertEqual( | ||
mails[0].subject, "Bevestiging van uw inzending van Pretty Form" | ||
) | ||
self.assertEqual(mails[0].to, ["[email protected]"]) | ||
self.assertEqual(mails[0].cc, ["[email protected]"]) | ||
|
||
cosign_info = _( | ||
"This email is a confirmation that this form has been co-signed by %(cosigner_email)s and can now be processed." | ||
) % {"cosigner_email": "[email protected]"} | ||
payment_info = _( | ||
"Payment of EUR %(payment_price)s is required. You can pay using the link below." | ||
) % {"payment_price": "10,00"} | ||
|
||
self.assertIn(cosign_info, mails[0].body.strip("\n")) | ||
self.assertNotIn(payment_info, mails[0].body.strip("\n")) | ||
|
||
submission.refresh_from_db() | ||
|
||
self.assertTrue(submission.cosign_confirmation_email_sent) | ||
self.assertTrue(submission.payment_complete_confirmation_email_sent) | ||
|
||
# | ||
# Status: submission completed, payment done | ||
# | ||
def test_payment_done_cosign_not_needed(self): | ||
pass | ||
|
||
def test_payment_done_cosign_needed_not_done(self): | ||
pass | ||
|
||
def test_payment_done_cosign_done(self): | ||
pass | ||
|
||
# | ||
# Status: submission completed, payment done, cosign done. Registration failed | ||
# | ||
def test_confirmation_email_not_sent_again(self): | ||
pass |
Oops, something went wrong.