From 1d6b75d5dc612c7b8be6ad7e4d721cbb4a9e1131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 15 Mar 2021 12:56:07 +0200 Subject: [PATCH] Move Profile *model* tests to test_profile_model --- hc/accounts/tests/test_profile.py | 71 ------------------------- hc/accounts/tests/test_profile_model.py | 67 +++++++++++++++++++++++ 2 files changed, 67 insertions(+), 71 deletions(-) diff --git a/hc/accounts/tests/test_profile.py b/hc/accounts/tests/test_profile.py index 8b7a4b7a..782e88a6 100644 --- a/hc/accounts/tests/test_profile.py +++ b/hc/accounts/tests/test_profile.py @@ -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="bob@example.org", password="password") diff --git a/hc/accounts/tests/test_profile_model.py b/hc/accounts/tests/test_profile_model.py index 14cc0f22..f4e16014 100644 --- a/hc/accounts/tests/test_profile_model.py +++ b/hc/accounts/tests/test_profile_model.py @@ -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")