Browse Source

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

pull/64/head
Pēteris Caune 9 years ago
parent
commit
89d37f8202
2 changed files with 7 additions and 0 deletions
  1. +3
    -0
      hc/api/models.py
  2. +4
    -0
      hc/api/tests/test_check_model.py

+ 3
- 0
hc/api/models.py View File

@ -91,6 +91,9 @@ class Check(models.Model):
return "down" return "down"
def in_grace_period(self): def in_grace_period(self):
if not self.last_ping:
return False
up_ends = self.last_ping + self.timeout up_ends = self.last_ping + self.timeout
grace_ends = up_ends + self.grace grace_ends = up_ends + self.grace
return up_ends < timezone.now() < grace_ends return up_ends < timezone.now() < grace_ends


+ 4
- 0
hc/api/tests/test_check_model.py View File

@ -13,3 +13,7 @@ class CheckModelTestCase(TestCase):
check.tags = " " check.tags = " "
self.assertEquals(check.tags_list(), []) self.assertEquals(check.tags_list(), [])
def test_in_grace_period_handles_new_check(self):
check = Check()
self.assertFalse(check.in_grace_period())

Loading…
Cancel
Save