From 89d37f820254d01f942f57f978a37b1f1b063143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 20 Jun 2016 22:32:32 +0300 Subject: [PATCH] Check.in_grace_period() should not blow up if last_ping is None --- hc/api/models.py | 3 +++ hc/api/tests/test_check_model.py | 4 ++++ 2 files changed, 7 insertions(+) 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())