Browse Source

Clear Check.alert_after when pausing a check.

pull/211/head
Pēteris Caune 6 years ago
parent
commit
cc40793fc7
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 14 additions and 3 deletions
  1. +7
    -2
      hc/api/tests/test_pause.py
  2. +1
    -0
      hc/api/views.py
  3. +5
    -1
      hc/front/tests/test_pause.py
  4. +1
    -0
      hc/front/views.py

+ 7
- 2
hc/api/tests/test_pause.py View File

@ -1,3 +1,5 @@
from datetime import timedelta as td
from django.utils.timezone import now
from hc.api.models import Check
from hc.test import BaseTestCase
@ -57,8 +59,10 @@ class PauseTestCase(BaseTestCase):
self.assertEqual(r.status_code, 404)
def test_it_clears_last_start(self):
check = Check(user=self.alice, status="up", last_start=now())
def test_it_clears_last_start_alert_after(self):
check = Check(user=self.alice, status="up")
check.last_start = now()
check.alert_after = check.last_start + td(hours=1)
check.save()
url = "/api/v1/checks/%s/pause" % check.code
@ -70,3 +74,4 @@ class PauseTestCase(BaseTestCase):
check.refresh_from_db()
self.assertEqual(check.last_start, None)
self.assertEqual(check.alert_after, None)

+ 1
- 0
hc/api/views.py View File

@ -189,6 +189,7 @@ def pause(request, code):
check.status = "paused"
check.last_start = None
check.alert_after = None
check.save()
return JsonResponse(check.to_dict())


+ 5
- 1
hc/front/tests/test_pause.py View File

@ -1,3 +1,5 @@
from datetime import timedelta as td
from django.utils.timezone import now
from hc.api.models import Check
from hc.test import BaseTestCase
@ -33,8 +35,9 @@ class PauseTestCase(BaseTestCase):
r = self.client.post(self.url)
self.assertRedirects(r, "/checks/")
def test_it_clears_last_start(self):
def test_it_clears_last_start_alert_after(self):
self.check.last_start = now()
self.check.alert_after = self.check.last_start + td(hours=1)
self.check.save()
self.client.login(username="[email protected]", password="password")
@ -42,3 +45,4 @@ class PauseTestCase(BaseTestCase):
self.check.refresh_from_db()
self.assertEqual(self.check.last_start, None)
self.assertEqual(self.check.alert_after, None)

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

@ -353,6 +353,7 @@ def pause(request, code):
check.status = "paused"
check.last_start = None
check.alert_after = None
check.save()
if "/details/" in request.META.get("HTTP_REFERER", ""):


Loading…
Cancel
Save