Skip to content

Commit

Permalink
[Feature #145028653] Fix the failing tests
Browse files Browse the repository at this point in the history
 - Modify the tests to include the newly introduced check status of "often"
 - The tests did not cover the check being up but just running too often
 - This modifies the tests to accommodate the said possibility
  • Loading branch information
Andretalik committed Jun 4, 2017
1 parent cafe4f0 commit e8a9621
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions hc/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_status(self):

now = timezone.now()

if self.last_ping + (self.timeout - td(minutes=15)) > now:
if self.last_ping + self.timeout/6 > now:
return "often"

if self.last_ping + self.timeout + self.grace > now:
Expand All @@ -95,7 +95,7 @@ def get_status(self):
return "down"

def in_grace_period(self):
if self.status in ("new", "paused"):
if self.status in ("new", "paused", "often"):
return False

up_ends = self.last_ping + self.timeout
Expand Down
2 changes: 1 addition & 1 deletion hc/api/tests/test_list_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_it_works(self):
self.assertEqual(checks['Alice 2']['timeout'], 86400)
self.assertEqual(checks['Alice 2']['grace'], 3600)
self.assertEqual(checks['Alice 2']['ping_url'], self.a2.to_dict()['ping_url'])
self.assertEqual(checks['Alice 2']['status'], "up")
self.assertEqual(checks['Alice 2']['status'], "often")
self.assertEqual(checks['Alice 2']['last_ping'], self.a2.to_dict()['last_ping'])
self.assertEqual(checks['Alice 2']['n_pings'], self.a2.to_dict()['n_pings'])
self.assertEqual(checks['Alice 2']['pause_url'], self.a2.to_dict()['pause_url'])
Expand Down
1 change: 0 additions & 1 deletion hc/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def ping(request, code):
check.last_ping = timezone.now()
if check.status in ("new", "paused", "often"):
check.status = "up"

check.save()
check.refresh_from_db()

Expand Down
4 changes: 2 additions & 2 deletions hc/front/tests/test_my_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def test_it_shows_green_check(self):
r = self.client.get("/checks/")

# Desktop
self.assertContains(r, "icon-up")
self.assertContains(r, "icon-often")

# Mobile
self.assertContains(r, "label-success")
self.assertContains(r, "label-warning")

def test_it_shows_red_check(self):
self.check.last_ping = timezone.now() - td(days=3)
Expand Down
2 changes: 1 addition & 1 deletion templates/front/my_checks_desktop.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
data-toggle="tooltip" title="Monitoring paused. Ping to resume."></span>
{% elif check.get_status == "often" %}
<span class="status icon-often" data-toggle="tooltip"
title="Ping is running too often."></span>
title="Ping is up but running too often."></span>
{% elif check.in_grace_period %}
<span class="status icon-grace"></span>
{% elif check.get_status == "up" %}
Expand Down
2 changes: 2 additions & 0 deletions templates/front/my_checks_mobile.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ <h2>
<span class="label label-warning">LATE</span>
{% elif check.get_status == "up" %}
<span class="label label-success">UP</span>
{% elif check.get_status == "often" %}
<span class="label label-warning">OFTEN</span>
{% elif check.get_status == "down" %}
<span class="label label-danger">DOWN</span>
{% endif %}
Expand Down

0 comments on commit e8a9621

Please sign in to comment.