Update report templates for weekly reports

This commit is contained in:
Pēteris Caune 2021-05-26 09:48:23 +03:00
parent 8ce09ab9e5
commit a0cd2c63e9
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
5 changed files with 23 additions and 4 deletions

View File

@ -214,6 +214,7 @@ class Profile(models.Model):
"nag_period": self.nag_period.total_seconds(), "nag_period": self.nag_period.total_seconds(),
"num_down": num_down, "num_down": num_down,
"month_boundaries": boundaries, "month_boundaries": boundaries,
"monthly_or_weekly": self.reports,
} }
emails.report(self.user.email, ctx, headers) emails.report(self.user.email, ctx, headers)

View File

@ -33,7 +33,7 @@ class SendReportsTestCase(BaseTestCase):
self.check.status = "down" self.check.status = "down"
self.check.save() self.check.save()
def test_it_sends_report(self): def test_it_sends_monthly_report(self):
cmd = Command(stdout=Mock()) cmd = Command(stdout=Mock())
cmd.pause = Mock() # don't pause for 1s cmd.pause = Mock() # don't pause for 1s
@ -48,6 +48,23 @@ class SendReportsTestCase(BaseTestCase):
email = mail.outbox[0] email = mail.outbox[0]
self.assertTrue("List-Unsubscribe" in email.extra_headers) self.assertTrue("List-Unsubscribe" in email.extra_headers)
self.assertTrue("List-Unsubscribe-Post" in email.extra_headers) self.assertTrue("List-Unsubscribe-Post" in email.extra_headers)
self.assertEqual(email.subject, "Monthly Report")
self.assertIn("This is a monthly report", email.body)
self.assertIn("This is a monthly report", email.alternatives[0][0])
def test_it_sends_weekly_report(self):
self.profile.reports = "weekly"
self.profile.save()
cmd = Command(stdout=Mock())
cmd.pause = Mock() # don't pause for 1s
cmd.handle_one_report()
email = mail.outbox[0]
self.assertEqual(email.subject, "Weekly Report")
self.assertIn("This is a weekly report", email.body)
self.assertIn("This is a weekly report", email.alternatives[0][0])
def test_it_obeys_next_report_date(self): def test_it_obeys_next_report_date(self):
self.profile.next_report_date = now() + td(days=1) self.profile.next_report_date = now() + td(days=1)

View File

@ -24,7 +24,8 @@ Hello,<br />
page on {% site_name %} to set your notification preferences. page on {% site_name %} to set your notification preferences.
{% else %} {% else %}
This is a monthly report sent by <a href="{% site_root %}">{% site_name %}</a>. This is a {{ monthly_or_weekly }} report
sent by <a href="{% site_root %}">{% site_name %}</a>.
<br /> <br />
{% include "emails/summary-downtimes-html.html" %} {% include "emails/summary-downtimes-html.html" %}

View File

@ -3,7 +3,7 @@ Hello,
{% if nag %}This is a {% if nag_period == 3600 %}hourly {% endif %}{% if nag_period == 86400 %}daily {% endif %}reminder sent by {% site_name %}. {% if nag %}This is a {% if nag_period == 3600 %}hourly {% endif %}{% if nag_period == 86400 %}daily {% endif %}reminder sent by {% site_name %}.
{% if num_down == 1%}One check is currently DOWN.{% else %}{{ num_down }} checks are currently DOWN.{% endif %}{% else %}This is a monthly report sent by {% site_name %}.{% endif %} {% if num_down == 1%}One check is currently DOWN.{% else %}{{ num_down }} checks are currently DOWN.{% endif %}{% else %}This is a {{ monthly_or_weekly }} report sent by {% site_name %}.{% endif %}
{% include 'emails/summary-text.html' %} {% include 'emails/summary-text.html' %}

View File

@ -1,6 +1,6 @@
{% if nag %} {% if nag %}
Reminder: {{ num_down }} check{{ num_down|pluralize }} still down Reminder: {{ num_down }} check{{ num_down|pluralize }} still down
{% else %} {% else %}
Monthly Report {{ monthly_or_weekly|capfirst }} Report
{% endif %} {% endif %}