forked from GithubBackups/healthchecks
Fix the pause action to clear Profile.next_nag_date if all checks up
This commit is contained in:
parent
7ba5fcbb71
commit
05db43f95d
@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Fix downtime summary to handle months when the check didn't exist yet (#472)
|
- Fix downtime summary to handle months when the check didn't exist yet (#472)
|
||||||
- Relax cron expression validation: accept all expressions that croniter accepts
|
- Relax cron expression validation: accept all expressions that croniter accepts
|
||||||
- Fix sendalerts to clear Profile.next_nag_date if all checks up
|
- Fix sendalerts to clear Profile.next_nag_date if all checks up
|
||||||
|
- Fix the pause action to clear Profile.next_nag_date if all checks up
|
||||||
|
|
||||||
## v1.19.0 - 2021-02-03
|
## v1.19.0 - 2021-02-03
|
||||||
|
|
||||||
|
@ -6,31 +6,30 @@ from hc.test import BaseTestCase
|
|||||||
|
|
||||||
|
|
||||||
class PauseTestCase(BaseTestCase):
|
class PauseTestCase(BaseTestCase):
|
||||||
def test_it_works(self):
|
def setUp(self):
|
||||||
check = Check.objects.create(project=self.project, status="up")
|
super().setUp()
|
||||||
|
|
||||||
url = "/api/v1/checks/%s/pause" % check.code
|
self.check = Check.objects.create(project=self.project, status="up")
|
||||||
|
self.url = f"/api/v1/checks/{self.check.code}/pause"
|
||||||
|
|
||||||
|
def test_it_works(self):
|
||||||
r = self.client.post(
|
r = self.client.post(
|
||||||
url, "", content_type="application/json", HTTP_X_API_KEY="X" * 32
|
self.url, "", content_type="application/json", HTTP_X_API_KEY="X" * 32
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(r.status_code, 200)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual(r["Access-Control-Allow-Origin"], "*")
|
self.assertEqual(r["Access-Control-Allow-Origin"], "*")
|
||||||
|
|
||||||
check.refresh_from_db()
|
self.check.refresh_from_db()
|
||||||
self.assertEqual(check.status, "paused")
|
self.assertEqual(self.check.status, "paused")
|
||||||
|
|
||||||
def test_it_handles_options(self):
|
def test_it_handles_options(self):
|
||||||
check = Check.objects.create(project=self.project, status="up")
|
r = self.client.options(self.url)
|
||||||
|
|
||||||
r = self.client.options("/api/v1/checks/%s/pause" % check.code)
|
|
||||||
self.assertEqual(r.status_code, 204)
|
self.assertEqual(r.status_code, 204)
|
||||||
self.assertIn("POST", r["Access-Control-Allow-Methods"])
|
self.assertIn("POST", r["Access-Control-Allow-Methods"])
|
||||||
|
|
||||||
def test_it_only_allows_post(self):
|
def test_it_only_allows_post(self):
|
||||||
url = "/api/v1/checks/1659718b-21ad-4ed1-8740-43afc6c41524/pause"
|
r = self.client.get(self.url, HTTP_X_API_KEY="X" * 32)
|
||||||
|
|
||||||
r = self.client.get(url, HTTP_X_API_KEY="X" * 32)
|
|
||||||
self.assertEqual(r.status_code, 405)
|
self.assertEqual(r.status_code, 405)
|
||||||
|
|
||||||
def test_it_validates_ownership(self):
|
def test_it_validates_ownership(self):
|
||||||
@ -60,19 +59,29 @@ class PauseTestCase(BaseTestCase):
|
|||||||
self.assertEqual(r.status_code, 404)
|
self.assertEqual(r.status_code, 404)
|
||||||
|
|
||||||
def test_it_clears_last_start_alert_after(self):
|
def test_it_clears_last_start_alert_after(self):
|
||||||
check = Check(project=self.project, status="up")
|
self.check.last_start = now()
|
||||||
check.last_start = now()
|
self.check.alert_after = self.check.last_start + td(hours=1)
|
||||||
check.alert_after = check.last_start + td(hours=1)
|
self.check.save()
|
||||||
check.save()
|
|
||||||
|
|
||||||
url = "/api/v1/checks/%s/pause" % check.code
|
|
||||||
r = self.client.post(
|
r = self.client.post(
|
||||||
url, "", content_type="application/json", HTTP_X_API_KEY="X" * 32
|
self.url, "", content_type="application/json", HTTP_X_API_KEY="X" * 32
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(r.status_code, 200)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual(r["Access-Control-Allow-Origin"], "*")
|
self.assertEqual(r["Access-Control-Allow-Origin"], "*")
|
||||||
|
|
||||||
check.refresh_from_db()
|
self.check.refresh_from_db()
|
||||||
self.assertEqual(check.last_start, None)
|
self.assertEqual(self.check.last_start, None)
|
||||||
self.assertEqual(check.alert_after, None)
|
self.assertEqual(self.check.alert_after, None)
|
||||||
|
|
||||||
|
def test_it_clears_next_nag_date(self):
|
||||||
|
self.profile.nag_period = td(hours=1)
|
||||||
|
self.profile.next_nag_date = now() + td(minutes=30)
|
||||||
|
self.profile.save()
|
||||||
|
|
||||||
|
self.client.post(
|
||||||
|
self.url, "", content_type="application/json", HTTP_X_API_KEY="X" * 32
|
||||||
|
)
|
||||||
|
|
||||||
|
self.profile.refresh_from_db()
|
||||||
|
self.assertIsNone(self.profile.next_nag_date)
|
||||||
|
@ -293,6 +293,11 @@ def pause(request, code):
|
|||||||
check.last_start = None
|
check.last_start = None
|
||||||
check.alert_after = None
|
check.alert_after = None
|
||||||
check.save()
|
check.save()
|
||||||
|
|
||||||
|
# After pausing a check we must check if all checks are up,
|
||||||
|
# and Profile.next_nag_date needs to be cleared out:
|
||||||
|
check.project.update_next_nag_dates()
|
||||||
|
|
||||||
return JsonResponse(check.to_dict())
|
return JsonResponse(check.to_dict())
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,3 +54,14 @@ class PauseTestCase(BaseTestCase):
|
|||||||
self.client.login(username="bob@example.org", password="password")
|
self.client.login(username="bob@example.org", password="password")
|
||||||
r = self.client.post(self.url)
|
r = self.client.post(self.url)
|
||||||
self.assertEqual(r.status_code, 403)
|
self.assertEqual(r.status_code, 403)
|
||||||
|
|
||||||
|
def test_it_clears_next_nag_date(self):
|
||||||
|
self.profile.nag_period = td(hours=1)
|
||||||
|
self.profile.next_nag_date = now() + td(minutes=30)
|
||||||
|
self.profile.save()
|
||||||
|
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
self.client.post(self.url)
|
||||||
|
|
||||||
|
self.profile.refresh_from_db()
|
||||||
|
self.assertIsNone(self.profile.next_nag_date)
|
||||||
|
@ -535,6 +535,10 @@ def pause(request, code):
|
|||||||
check.alert_after = None
|
check.alert_after = None
|
||||||
check.save()
|
check.save()
|
||||||
|
|
||||||
|
# After pausing a check we must check if all checks are up,
|
||||||
|
# and Profile.next_nag_date needs to be cleared out:
|
||||||
|
check.project.update_next_nag_dates()
|
||||||
|
|
||||||
# Don't redirect after an AJAX request:
|
# Don't redirect after an AJAX request:
|
||||||
if request.META.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest":
|
if request.META.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest":
|
||||||
return HttpResponse()
|
return HttpResponse()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user