forked from GithubBackups/healthchecks
More tests for sendreports.
This commit is contained in:
parent
8d956b3365
commit
ae4144b1cd
@ -1,6 +1,6 @@
|
||||
from datetime import timedelta
|
||||
from datetime import timedelta as td
|
||||
|
||||
from django.utils import timezone
|
||||
from django.utils.timezone import now
|
||||
from hc.api.management.commands.sendreports import Command
|
||||
from hc.api.models import Check
|
||||
from hc.test import BaseTestCase
|
||||
@ -8,13 +8,42 @@ from hc.test import BaseTestCase
|
||||
|
||||
class SendAlertsTestCase(BaseTestCase):
|
||||
|
||||
def test_it_sends_report(self):
|
||||
# Make alice eligible for reports
|
||||
self.alice.date_joined = timezone.now() - timedelta(days=365)
|
||||
def setUp(self):
|
||||
super(SendAlertsTestCase, 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()
|
||||
|
||||
check = Check(user=self.alice, last_ping=timezone.now())
|
||||
check.save()
|
||||
# And it needs at least one check that has been pinged.
|
||||
self.check = Check(user=self.alice, last_ping=now())
|
||||
self.check.save()
|
||||
|
||||
def test_it_sends_report(self):
|
||||
sent = Command().handle_one_run()
|
||||
self.assertEqual(sent, 1)
|
||||
|
||||
# Alice's profile should have been updated
|
||||
self.profile.refresh_from_db()
|
||||
self.assertTrue(self.profile.next_report_date > now())
|
||||
|
||||
def test_it_obeys_next_report_date(self):
|
||||
self.profile.next_report_date = now() + td(days=1)
|
||||
self.profile.save()
|
||||
|
||||
sent = Command().handle_one_run()
|
||||
self.assertEqual(sent, 0)
|
||||
|
||||
def test_it_obeys_reports_allowed_flag(self):
|
||||
self.profile.reports_allowed = False
|
||||
self.profile.save()
|
||||
|
||||
sent = Command().handle_one_run()
|
||||
self.assertEqual(sent, 0)
|
||||
|
||||
def test_it_requires_pinged_checks(self):
|
||||
self.check.delete()
|
||||
|
||||
sent = Command().handle_one_run()
|
||||
self.assertEqual(sent, 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user