diff --git a/hc/api/models.py b/hc/api/models.py index 310cc7f4..3bce955a 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -91,6 +91,9 @@ class Check(models.Model): return "down" def in_grace_period(self): + if not self.last_ping: + return False + up_ends = self.last_ping + self.timeout grace_ends = up_ends + self.grace return up_ends < timezone.now() < grace_ends diff --git a/hc/api/tests/test_check_model.py b/hc/api/tests/test_check_model.py index af940f6c..48946e17 100644 --- a/hc/api/tests/test_check_model.py +++ b/hc/api/tests/test_check_model.py @@ -13,3 +13,7 @@ class CheckModelTestCase(TestCase): check.tags = " " self.assertEquals(check.tags_list(), []) + + def test_in_grace_period_handles_new_check(self): + check = Check() + self.assertFalse(check.in_grace_period())