Browse Source

Fix the month boundary calculation in monthly reports

Fixes: #497
pull/504/head
Pēteris Caune 4 years ago
parent
commit
67d11e8d40
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 19 additions and 3 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +5
    -1
      hc/accounts/models.py
  3. +13
    -2
      hc/accounts/tests/test_profile_model.py

+ 1
- 0
CHANGELOG.md View File

@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
- Fix sendalerts to clear Profile.next_nag_date if all checks up
- Fix the pause action to clear Profile.next_nag_date if all checks up
- Fix the "Email Reports" screen to clear Profile.next_nag_date if all checks up
- Fix the month boundary calculation in monthly reports (#497)
## v1.19.0 - 2021-02-03


+ 5
- 1
hc/accounts/models.py View File

@ -195,6 +195,10 @@ class Profile(models.Model):
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
}
boundaries = month_boundaries(months=3)
# throw away the current month, keep two previous months
boundaries.pop()
ctx = {
"checks": checks,
"sort": self.sort,
@ -204,7 +208,7 @@ class Profile(models.Model):
"nag": nag,
"nag_period": self.nag_period.total_seconds(),
"num_down": num_down,
"month_boundaries": month_boundaries(),
"month_boundaries": boundaries,
}
emails.report(self.user.email, ctx, headers)


+ 13
- 2
hc/accounts/tests/test_profile_model.py View File

@ -1,12 +1,17 @@
from datetime import timedelta as td
from datetime import datetime, timedelta as td
from unittest.mock import Mock, patch
from django.core import mail
from django.utils.timezone import now
from django.utils.timezone import now, utc
from hc.test import BaseTestCase
from hc.api.models import Check
CURRENT_TIME = datetime(2020, 1, 15, tzinfo=utc)
MOCK_NOW = Mock(return_value=CURRENT_TIME)
class ProfileModelTestCase(BaseTestCase):
@patch("hc.lib.date.timezone.now", MOCK_NOW)
def test_it_sends_report(self):
check = Check(project=self.project, name="Test Check")
check.last_ping = now()
@ -22,6 +27,12 @@ class ProfileModelTestCase(BaseTestCase):
self.assertEqual(message.subject, "Monthly Report")
self.assertIn("Test Check", message.body)
html, _ = message.alternatives[0]
self.assertNotIn("Jan. 2020", html)
self.assertIn("Dec. 2019", html)
self.assertIn("Nov. 2019", html)
self.assertNotIn("Oct. 2019", html)
def test_it_skips_report_if_no_pings(self):
check = Check(project=self.project, name="Test Check")
check.save()


Loading…
Cancel
Save