From ce23d65ebf21dd022f8230fb6a9f5264357f92e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 21 Jun 2016 02:22:51 +0300 Subject: [PATCH] Check.get_status() returns "up" also during grace period --- hc/api/models.py | 2 +- hc/api/tests/test_check_model.py | 12 +++++++++++- hc/api/tests/test_sendalerts.py | 3 +-- templates/emails/alert-body-html.html | 4 ++-- templates/emails/report-body-html.html | 4 ++-- templates/front/my_checks_desktop.html | 4 ++-- templates/front/my_checks_mobile.html | 4 ++-- 7 files changed, 21 insertions(+), 12 deletions(-) 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 @@ {% if check.get_status == "new" %} NEW - {% elif check.get_status == "up" %} - UP {% elif check.in_grace_period %} LATE + {% elif check.get_status == "up" %} + UP {% elif check.get_status == "down" %} DOWN {% endif %} diff --git a/templates/emails/report-body-html.html b/templates/emails/report-body-html.html index 92edcc7a..8f84b45a 100644 --- a/templates/emails/report-body-html.html +++ b/templates/emails/report-body-html.html @@ -46,10 +46,10 @@ {% if check.get_status == "new" %} NEW - {% elif check.get_status == "up" %} - UP {% elif check.in_grace_period %} LATE + {% elif check.get_status == "up" %} + UP {% elif check.get_status == "down" %} DOWN {% endif %} diff --git a/templates/front/my_checks_desktop.html b/templates/front/my_checks_desktop.html index 9161e892..f44d2410 100644 --- a/templates/front/my_checks_desktop.html +++ b/templates/front/my_checks_desktop.html @@ -16,10 +16,10 @@ {% if check.get_status == "new" %} - {% elif check.get_status == "up" %} - {% elif check.in_grace_period %} + {% elif check.get_status == "up" %} + {% elif check.get_status == "down" %} {% endif %} diff --git a/templates/front/my_checks_mobile.html b/templates/front/my_checks_mobile.html index ebaa4db6..dd44c150 100644 --- a/templates/front/my_checks_mobile.html +++ b/templates/front/my_checks_mobile.html @@ -25,10 +25,10 @@ {% if check.get_status == "new" %} NEW - {% elif check.get_status == "up" %} - UP {% elif check.in_grace_period %} LATE + {% elif check.get_status == "up" %} + UP {% elif check.get_status == "down" %} DOWN {% endif %}