-
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.
[#3725] Added failed registrations to email digest
- Loading branch information
Showing
9 changed files
with
224 additions
and
31 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
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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
{% load static i18n %} | ||
|
||
<p> | ||
{% blocktranslate %}Here is a summary of the emails that failed to send yesterday:{% endblocktranslate %} | ||
{% blocktranslate %}Here is a summary of the failed procedures in the past 24 hours:{% endblocktranslate %} | ||
</p> | ||
<ul> | ||
{% for log in logs %}<li>- Email for the event "{{ log.event }}" for submission {{ log.submission_uuid }}.</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
{% if failed_emails %} | ||
<h5>{% trans "Emails" %}</h5> | ||
<ul> | ||
{% for email in failed_emails %} | ||
<li>- Email for the event "{{ email.event }}" for submission {{ email.submission_uuid }}.</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% if failed_registrations %} | ||
<h5>{% trans "Registrations" %}</h5> | ||
<ul> | ||
{% for registration in failed_registrations %} | ||
<li>- {{ registration.form_name }} failed {{ registration.failed_submissions_counter }} times between {{ registration.initial_failure_at|date:"H:i" }} and {{ registration.last_failure_at|date:"H:i" }}.</li> | ||
<a href="{{ registration.admin_link }}">Click here to see all the failed submissions for form {{ registration.form_name }} in the admin</a> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} |
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 |
---|---|---|
|
@@ -9,7 +9,9 @@ | |
from freezegun import freeze_time | ||
|
||
from openforms.config.models import GlobalConfiguration | ||
from openforms.forms.tests.factories import FormFactory | ||
from openforms.logging.tests.factories import TimelineLogProxyFactory | ||
from openforms.submissions.constants import RegistrationStatuses | ||
from openforms.submissions.tests.factories import SubmissionFactory | ||
|
||
from ..tasks import send_email_digest | ||
|
@@ -72,8 +74,9 @@ def test_create_digest_email(self): | |
expected_content = dedent( | ||
f""" | ||
<p> | ||
Here is a summary of the emails that failed to send yesterday: | ||
Here is a summary of the failed procedures in the past 24 hours: | ||
</p> | ||
<h5>Emails</h5> | ||
<ul> | ||
<li>- Email for the event "registration" for submission {submission.uuid}.</li> | ||
|
@@ -128,8 +131,9 @@ def test_that_repeated_failures_are_not_mentioned_multiple_times(self): | |
expected_content = dedent( | ||
f""" | ||
<p> | ||
Here is a summary of the emails that failed to send yesterday: | ||
Here is a summary of the failed procedures in the past 24 hours: | ||
</p> | ||
<h5>Emails</h5> | ||
<ul> | ||
<li>- Email for the event "registration" for submission {submission.uuid}.</li> | ||
|
@@ -177,3 +181,92 @@ def test_no_recipients(self): | |
send_email_digest() | ||
|
||
self.assertEqual(0, len(mail.outbox)) | ||
|
||
def test_failed_submissions_are_correctly_sent(self): | ||
# 1st form with 2 failures in the past 24 hours | ||
form_1 = FormFactory.create() | ||
failed_submission_1 = SubmissionFactory.create( | ||
form=form_1, registration_status=RegistrationStatuses.failed | ||
) | ||
failed_submission_2 = SubmissionFactory.create( | ||
form=form_1, registration_status=RegistrationStatuses.failed | ||
) | ||
|
||
# 1st failure | ||
with freeze_time("2023-01-02T12:30:00+01:00"): | ||
TimelineLogProxyFactory.create( | ||
template="logging/events/registration_failure.txt", | ||
content_object=failed_submission_1, | ||
extra_data={ | ||
"log_event": "registration_failure", | ||
"include_in_daily_digest": True, | ||
}, | ||
) | ||
|
||
# 2nd failure | ||
with freeze_time("2023-01-02T18:30:00+01:00"): | ||
TimelineLogProxyFactory.create( | ||
template="logging/events/registration_failure.txt", | ||
content_object=failed_submission_2, | ||
extra_data={ | ||
"log_event": "registration_failure", | ||
"include_in_daily_digest": True, | ||
}, | ||
) | ||
|
||
# 2nd form with 1 failure in the past 24 hours | ||
form_2 = FormFactory.create() | ||
failed_submission = SubmissionFactory.create( | ||
form=form_2, registration_status=RegistrationStatuses.failed | ||
) | ||
|
||
# failure | ||
with freeze_time("2023-01-02T12:30:00+01:00"): | ||
TimelineLogProxyFactory.create( | ||
template="logging/events/registration_failure.txt", | ||
content_object=failed_submission, | ||
extra_data={ | ||
"log_event": "registration_failure", | ||
"include_in_daily_digest": True, | ||
}, | ||
) | ||
|
||
with ( | ||
freeze_time("2023-01-03T01:00:00+01:00"), | ||
patch( | ||
"openforms.emails.tasks.GlobalConfiguration.get_solo", | ||
return_value=GlobalConfiguration( | ||
recipients_email_digest=["[email protected]"] | ||
), | ||
), | ||
patch("openforms.emails.tasks.send_mail_html") as patch_email, | ||
): | ||
send_email_digest() | ||
|
||
patch_email.assert_called_once() | ||
|
||
args = patch_email.call_args.args | ||
expected_content = dedent( | ||
f""" | ||
<p> | ||
Here is a summary of the failed procedures in the past 24 hours: | ||
</p> | ||
<h5>Registrations</h5> | ||
<ul> | ||
<li>- {form_1.name} failed 2 times between 12:30 and 18:30.</li> | ||
<a href="/admin/submissions/submission/?form__id__exact={form_1.id}&needs_on_completion_retry__exact=1&from_time=24hAgo"> | ||
Click here to see all the failed submissions for form {form_1.name} in the admin | ||
</a> | ||
<li>- {form_2.name} failed 1 times between 12:30 and 12:30.</li> | ||
<a href="/admin/submissions/submission/?form__id__exact={form_2.id}&needs_on_completion_retry__exact=1&from_time=24hAgo"> | ||
Click here to see all the failed submissions for form {form_2.name} in the admin | ||
</a> | ||
</ul> | ||
""" | ||
).strip() | ||
|
||
self.assertHTMLEqual( | ||
expected_content, | ||
args[1].strip(), | ||
) |
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
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
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
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
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
Oops, something went wrong.