Check.in_grace_period() should not blow up if last_ping is None

This commit is contained in:
Pēteris Caune 2016-06-20 22:32:32 +03:00
parent 1f70f56819
commit 89d37f8202
2 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -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())