From cc40793fc7a2468c7065b5544c4450644e5e6c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 21 Dec 2018 11:31:00 +0200 Subject: [PATCH] Clear Check.alert_after when pausing a check. --- hc/api/tests/test_pause.py | 9 +++++++-- hc/api/views.py | 1 + hc/front/tests/test_pause.py | 6 +++++- hc/front/views.py | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hc/api/tests/test_pause.py b/hc/api/tests/test_pause.py index 4a86518a..eb9e8d0d 100644 --- a/hc/api/tests/test_pause.py +++ b/hc/api/tests/test_pause.py @@ -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) diff --git a/hc/api/views.py b/hc/api/views.py index d9f5c624..6c322497 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -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()) diff --git a/hc/front/tests/test_pause.py b/hc/front/tests/test_pause.py index 4c64a4b6..d06da671 100644 --- a/hc/front/tests/test_pause.py +++ b/hc/front/tests/test_pause.py @@ -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="alice@example.org", 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) diff --git a/hc/front/views.py b/hc/front/views.py index 4efaf7bd..eb4087ef 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -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", ""):