Browse Source

Check model gets "in_grace_period" method. It replaces the transient "grace" status. Also, remove references of the obsolete "paused" status.

pull/64/head
Pēteris Caune 9 years ago
parent
commit
1f70f56819
8 changed files with 64 additions and 19 deletions
  1. +6
    -4
      hc/api/models.py
  2. +9
    -0
      hc/api/tests/test_sendalerts.py
  3. +44
    -0
      hc/front/tests/test_my_checks.py
  4. +1
    -1
      hc/front/views.py
  5. +1
    -4
      templates/emails/alert-body-html.html
  6. +1
    -4
      templates/emails/report-body-html.html
  7. +1
    -3
      templates/front/my_checks_desktop.html
  8. +1
    -3
      templates/front/my_checks_mobile.html

+ 6
- 4
hc/api/models.py View File

@ -80,7 +80,7 @@ class Check(models.Model):
return errors
def get_status(self):
if self.status in ("new", "paused"):
if self.status == "new":
return self.status
now = timezone.now()
@ -88,11 +88,13 @@ class Check(models.Model):
if self.last_ping + self.timeout > now:
return "up"
if self.last_ping + self.timeout + self.grace > now:
return "grace"
return "down"
def in_grace_period(self):
up_ends = self.last_ping + self.timeout
grace_ends = up_ends + self.grace
return up_ends < timezone.now() < grace_ends
def assign_all_channels(self):
if self.user:
channels = Channel.objects.filter(user=self.user)


+ 9
- 0
hc/api/tests/test_sendalerts.py View File

@ -29,3 +29,12 @@ class SendAlertsTestCase(BaseTestCase):
handled_names.append(args[0].name)
assert set(names) == set(handled_names)
def test_it_handles_grace_period(self):
check = Check(user=self.alice, status="up")
# 1 day 30 minutes after ping the check is in grace period:
check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
check.save()
# Expect no exceptions--
Command().handle_one(check)

+ 44
- 0
hc/front/tests/test_my_checks.py View File

@ -1,5 +1,7 @@
from hc.api.models import Check
from hc.test import BaseTestCase
from datetime import timedelta as td
from django.utils import timezone
class MyChecksTestCase(BaseTestCase):
@ -14,3 +16,45 @@ class MyChecksTestCase(BaseTestCase):
self.client.login(username=email, password="password")
r = self.client.get("/checks/")
self.assertContains(r, "Alice Was Here", status_code=200)
def test_it_shows_green_check(self):
self.check.last_ping = timezone.now()
self.check.status = "up"
self.check.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get("/checks/")
# Desktop
self.assertContains(r, "glyphicon-ok-sign")
# Mobile
self.assertContains(r, "label-success")
def test_it_shows_red_check(self):
self.check.last_ping = timezone.now() - td(days=3)
self.check.status = "up"
self.check.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get("/checks/")
# Desktop
self.assertContains(r, "glyphicon-exclamation-sign")
# Mobile
self.assertContains(r, "label-danger")
def test_it_shows_amber_check(self):
self.check.last_ping = timezone.now() - td(days=1, minutes=30)
self.check.status = "up"
self.check.save()
self.client.login(username="[email protected]", password="password")
r = self.client.get("/checks/")
# Desktop
self.assertContains(r, "glyphicon-exclamation-sign grace")
# Mobile
self.assertContains(r, "label-warning")

+ 1
- 1
hc/front/views.py View File

@ -42,7 +42,7 @@ def my_checks(request):
if status == "down":
down_tags.add(tag)
elif status == "grace":
elif check.in_grace_period():
grace_tags.add(tag)
ctx = {


+ 1
- 4
templates/emails/alert-body-html.html View File

@ -19,7 +19,6 @@
}
.new { background: #AAA; }
.paused { background: #AAA; }
.up { background: #5cb85c; }
.grace { background: #f0ad4e; }
.down { background: #d9534f; }
@ -52,12 +51,10 @@
<span class="badge new">NEW</span>
{% elif check.get_status == "up" %}
<span class="badge up">UP</span>
{% elif check.get_status == "grace" %}
{% elif check.in_grace_period %}
<span class="badge grace">LATE</span>
{% elif check.get_status == "down" %}
<span class="badge down">DOWN</span>
{% elif check.get_status == "paused" %}
<span class="badge paused">PAUSED</span>
{% endif %}
</td>
<td>


+ 1
- 4
templates/emails/report-body-html.html View File

@ -19,7 +19,6 @@
}
.new { background: #AAA; }
.paused { background: #AAA; }
.up { background: #5cb85c; }
.grace { background: #f0ad4e; }
.down { background: #d9534f; }
@ -49,12 +48,10 @@
<span class="badge new">NEW</span>
{% elif check.get_status == "up" %}
<span class="badge up">UP</span>
{% elif check.get_status == "grace" %}
{% elif check.in_grace_period %}
<span class="badge grace">LATE</span>
{% elif check.get_status == "down" %}
<span class="badge down">DOWN</span>
{% elif check.get_status == "paused" %}
<span class="badge paused">PAUSED</span>
{% endif %}
</td>
<td>


+ 1
- 3
templates/front/my_checks_desktop.html View File

@ -18,12 +18,10 @@
<span class="glyphicon glyphicon-question-sign new"></span>
{% elif check.get_status == "up" %}
<span class="glyphicon glyphicon-ok-sign up"></span>
{% elif check.get_status == "grace" %}
{% elif check.in_grace_period %}
<span class="glyphicon glyphicon-exclamation-sign grace"></span>
{% elif check.get_status == "down" %}
<span class="glyphicon glyphicon-exclamation-sign down"></span>
{% elif check.get_status == "paused" %}
<span class="glyphicon glyphicon-minus-sign paused"></span>
{% endif %}
</td>
<td class="name-cell">


+ 1
- 3
templates/front/my_checks_mobile.html View File

@ -27,12 +27,10 @@
<span class="label label-default">NEW</span>
{% elif check.get_status == "up" %}
<span class="label label-success">UP</span>
{% elif check.get_status == "grace" %}
{% elif check.in_grace_period %}
<span class="label label-warning">LATE</span>
{% elif check.get_status == "down" %}
<span class="label label-danger">DOWN</span>
{% elif check.get_status == "paused" %}
<span class="label label-default">PAUSED</span>
{% endif %}
</td>
</tr>


Loading…
Cancel
Save