forked from GithubBackups/healthchecks
Move Profile *model* tests to test_profile_model
This commit is contained in:
parent
05db43f95d
commit
1d6b75d5dc
@ -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="bob@example.org", password="password")
|
self.client.login(username="bob@example.org", password="password")
|
||||||
|
|
||||||
|
@ -1,11 +1,78 @@
|
|||||||
from datetime import timedelta as td
|
from datetime import timedelta as td
|
||||||
|
|
||||||
|
from django.core import mail
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
|
|
||||||
|
|
||||||
class ProfileModelTestCase(BaseTestCase):
|
class ProfileModelTestCase(BaseTestCase):
|
||||||
|
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_it_sets_next_nag_date(self):
|
def test_it_sets_next_nag_date(self):
|
||||||
Check.objects.create(project=self.project, status="down")
|
Check.objects.create(project=self.project, status="down")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user