|
@ -8,20 +8,24 @@ from hc.test import BaseTestCase |
|
|
from mock import Mock |
|
|
from mock import Mock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SendAlertsTestCase(BaseTestCase): |
|
|
|
|
|
|
|
|
class SendReportsTestCase(BaseTestCase): |
|
|
def setUp(self): |
|
|
def setUp(self): |
|
|
super(SendAlertsTestCase, self).setUp() |
|
|
|
|
|
|
|
|
super(SendReportsTestCase, self).setUp() |
|
|
|
|
|
|
|
|
# Make alice eligible for reports: |
|
|
|
|
|
# account needs to be more than one month old |
|
|
|
|
|
self.alice.date_joined = now() - td(days=365) |
|
|
|
|
|
self.alice.save() |
|
|
|
|
|
|
|
|
|
|
|
# Make alice eligible for nags: |
|
|
|
|
|
|
|
|
# Make alice eligible for a monthly report: |
|
|
|
|
|
self.profile.next_report_date = now() - td(hours=1) |
|
|
|
|
|
# and for a nag |
|
|
self.profile.nag_period = td(hours=1) |
|
|
self.profile.nag_period = td(hours=1) |
|
|
self.profile.next_nag_date = now() - td(seconds=10) |
|
|
self.profile.next_nag_date = now() - td(seconds=10) |
|
|
self.profile.save() |
|
|
self.profile.save() |
|
|
|
|
|
|
|
|
|
|
|
# Disable bob's and charlie's monthly reports so they don't interfere |
|
|
|
|
|
self.bobs_profile.reports_allowed = False |
|
|
|
|
|
self.bobs_profile.save() |
|
|
|
|
|
|
|
|
|
|
|
self.charlies_profile.reports_allowed = False |
|
|
|
|
|
self.charlies_profile.save() |
|
|
|
|
|
|
|
|
# And it needs at least one check that has been pinged. |
|
|
# And it needs at least one check that has been pinged. |
|
|
self.check = Check(project=self.project, last_ping=now()) |
|
|
self.check = Check(project=self.project, last_ping=now()) |
|
|
self.check.status = "down" |
|
|
self.check.status = "down" |
|
@ -37,6 +41,7 @@ class SendAlertsTestCase(BaseTestCase): |
|
|
|
|
|
|
|
|
self.profile.refresh_from_db() |
|
|
self.profile.refresh_from_db() |
|
|
self.assertTrue(self.profile.next_report_date > now()) |
|
|
self.assertTrue(self.profile.next_report_date > now()) |
|
|
|
|
|
self.assertEqual(self.profile.next_report_date.day, 1) |
|
|
self.assertEqual(len(mail.outbox), 1) |
|
|
self.assertEqual(len(mail.outbox), 1) |
|
|
|
|
|
|
|
|
email = mail.outbox[0] |
|
|
email = mail.outbox[0] |
|
@ -49,6 +54,18 @@ class SendAlertsTestCase(BaseTestCase): |
|
|
found = Command().handle_one_monthly_report() |
|
|
found = Command().handle_one_monthly_report() |
|
|
self.assertFalse(found) |
|
|
self.assertFalse(found) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_fills_blank_next_report_date(self): |
|
|
|
|
|
self.profile.next_report_date = None |
|
|
|
|
|
self.profile.save() |
|
|
|
|
|
|
|
|
|
|
|
found = Command().handle_one_monthly_report() |
|
|
|
|
|
self.assertTrue(found) |
|
|
|
|
|
|
|
|
|
|
|
self.profile.refresh_from_db() |
|
|
|
|
|
self.assertTrue(self.profile.next_report_date) |
|
|
|
|
|
self.assertEqual(self.profile.next_report_date.day, 1) |
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0) |
|
|
|
|
|
|
|
|
def test_it_obeys_reports_allowed_flag(self): |
|
|
def test_it_obeys_reports_allowed_flag(self): |
|
|
self.profile.reports_allowed = False |
|
|
self.profile.reports_allowed = False |
|
|
self.profile.save() |
|
|
self.profile.save() |
|
|