Browse Source

Move Profile *model* tests to test_profile_model

pull/504/head
Pēteris Caune 4 years ago
parent
commit
1d6b75d5dc
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 67 additions and 71 deletions
  1. +0
    -71
      hc/accounts/tests/test_profile.py
  2. +67
    -0
      hc/accounts/tests/test_profile_model.py

+ 0
- 71
hc/accounts/tests/test_profile.py View File

@ -1,11 +1,6 @@
from datetime import timedelta as td
from django.core import mail
from django.test.utils import override_settings
from django.utils.timezone import now
from hc.test import BaseTestCase
from hc.accounts.models import Credential
from hc.api.models import Check
class ProfileTestCase(BaseTestCase):
@ -15,72 +10,6 @@ class ProfileTestCase(BaseTestCase):
r = self.client.get("/accounts/profile/")
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):
self.client.login(username="[email protected]", password="password")


+ 67
- 0
hc/accounts/tests/test_profile_model.py View File

@ -1,11 +1,78 @@
from datetime import timedelta as td
from django.core import mail
from django.utils.timezone import now
from hc.test import BaseTestCase
from hc.api.models import Check
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):
Check.objects.create(project=self.project, status="down")


Loading…
Cancel
Save