diff --git a/hc/api/models.py b/hc/api/models.py index 3bce955a..d126f6a6 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -85,7 +85,7 @@ class Check(models.Model): now = timezone.now() - if self.last_ping + self.timeout > now: + if self.last_ping + self.timeout + self.grace > now: return "up" return "down" diff --git a/hc/api/tests/test_check_model.py b/hc/api/tests/test_check_model.py index 48946e17..73b7181f 100644 --- a/hc/api/tests/test_check_model.py +++ b/hc/api/tests/test_check_model.py @@ -1,5 +1,7 @@ -from django.test import TestCase +from datetime import timedelta +from django.test import TestCase +from django.utils import timezone from hc.api.models import Check @@ -17,3 +19,11 @@ class CheckModelTestCase(TestCase): def test_in_grace_period_handles_new_check(self): check = Check() self.assertFalse(check.in_grace_period()) + + def test_status_works_with_grace_period(self): + check = Check() + check.status = "up" + check.last_ping = timezone.now() - timedelta(days=1, minutes=30) + + self.assertTrue(check.in_grace_period()) + self.assertEqual(check.get_status(), "up") diff --git a/hc/api/tests/test_sendalerts.py b/hc/api/tests/test_sendalerts.py index f1d83159..b4c17e94 100644 --- a/hc/api/tests/test_sendalerts.py +++ b/hc/api/tests/test_sendalerts.py @@ -1,11 +1,10 @@ from datetime import timedelta from django.utils import timezone -from mock import patch - from hc.api.management.commands.sendalerts import Command from hc.api.models import Check from hc.test import BaseTestCase +from mock import patch class SendAlertsTestCase(BaseTestCase): diff --git a/templates/emails/alert-body-html.html b/templates/emails/alert-body-html.html index b6a8f1d9..4016fa1c 100644 --- a/templates/emails/alert-body-html.html +++ b/templates/emails/alert-body-html.html @@ -49,10 +49,10 @@