|
@ -1,11 +1,6 @@ |
|
|
from datetime import timedelta as td |
|
|
|
|
|
from django.core import mail |
|
|
|
|
|
|
|
|
|
|
|
from django.test.utils import override_settings |
|
|
from django.test.utils import override_settings |
|
|
from django.utils.timezone import now |
|
|
|
|
|
from hc.test import BaseTestCase |
|
|
from hc.test import BaseTestCase |
|
|
from hc.accounts.models import Credential |
|
|
from hc.accounts.models import Credential |
|
|
from hc.api.models import Check |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProfileTestCase(BaseTestCase): |
|
|
class ProfileTestCase(BaseTestCase): |
|
@ -15,72 +10,6 @@ class ProfileTestCase(BaseTestCase): |
|
|
r = self.client.get("/accounts/profile/") |
|
|
r = self.client.get("/accounts/profile/") |
|
|
self.assertContains(r, "Email and Password") |
|
|
self.assertContains(r, "Email and Password") |
|
|
|
|
|
|
|
|
def test_it_sends_report(self): |
|
|
|
|
|
check = Check(project=self.project, name="Test Check") |
|
|
|
|
|
check.last_ping = now() |
|
|
|
|
|
check.save() |
|
|
|
|
|
|
|
|
|
|
|
sent = self.profile.send_report() |
|
|
|
|
|
self.assertTrue(sent) |
|
|
|
|
|
|
|
|
|
|
|
# And an email should have been sent |
|
|
|
|
|
self.assertEqual(len(mail.outbox), 1) |
|
|
|
|
|
message = mail.outbox[0] |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(message.subject, "Monthly Report") |
|
|
|
|
|
self.assertIn("Test Check", message.body) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_skips_report_if_no_pings(self): |
|
|
|
|
|
check = Check(project=self.project, name="Test Check") |
|
|
|
|
|
check.save() |
|
|
|
|
|
|
|
|
|
|
|
sent = self.profile.send_report() |
|
|
|
|
|
self.assertFalse(sent) |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_skips_report_if_no_recent_pings(self): |
|
|
|
|
|
check = Check(project=self.project, name="Test Check") |
|
|
|
|
|
check.last_ping = now() - td(days=365) |
|
|
|
|
|
check.save() |
|
|
|
|
|
|
|
|
|
|
|
sent = self.profile.send_report() |
|
|
|
|
|
self.assertFalse(sent) |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_sends_nag(self): |
|
|
|
|
|
check = Check(project=self.project, name="Test Check") |
|
|
|
|
|
check.status = "down" |
|
|
|
|
|
check.last_ping = now() |
|
|
|
|
|
check.save() |
|
|
|
|
|
|
|
|
|
|
|
self.profile.nag_period = td(hours=1) |
|
|
|
|
|
self.profile.save() |
|
|
|
|
|
|
|
|
|
|
|
sent = self.profile.send_report(nag=True) |
|
|
|
|
|
self.assertTrue(sent) |
|
|
|
|
|
|
|
|
|
|
|
# And an email should have been sent |
|
|
|
|
|
self.assertEqual(len(mail.outbox), 1) |
|
|
|
|
|
message = mail.outbox[0] |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(message.subject, "Reminder: 1 check still down") |
|
|
|
|
|
self.assertIn("Test Check", message.body) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_skips_nag_if_none_down(self): |
|
|
|
|
|
check = Check(project=self.project, name="Test Check") |
|
|
|
|
|
check.last_ping = now() |
|
|
|
|
|
check.save() |
|
|
|
|
|
|
|
|
|
|
|
self.profile.nag_period = td(hours=1) |
|
|
|
|
|
self.profile.save() |
|
|
|
|
|
|
|
|
|
|
|
sent = self.profile.send_report(nag=True) |
|
|
|
|
|
self.assertFalse(sent) |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(len(mail.outbox), 0) |
|
|
|
|
|
|
|
|
|
|
|
def test_leaving_works(self): |
|
|
def test_leaving_works(self): |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
|
|
|
|
|