Browse Source

API: update check's "alert_after" field when changing schedule

pull/340/head
Pēteris Caune 5 years ago
parent
commit
cde1f50ac2
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 14 additions and 3 deletions
  1. +3
    -2
      CHANGELOG.md
  2. +10
    -1
      hc/api/tests/test_update_check.py
  3. +1
    -0
      hc/api/views.py

+ 3
- 2
CHANGELOG.md View File

@ -10,8 +10,9 @@ All notable changes to this project will be documented in this file.
### Bug Fixes ### Bug Fixes
- The "render_docs" command checks if markdown and pygments is installed (#329) - The "render_docs" command checks if markdown and pygments is installed (#329)
- The team size limit is applied to the n. of distinct users across all projects (#332) - The team size limit is applied to the n. of distinct users across all projects (#332)
- Don't let SuspiciousOperation bubble up when validating channel ids in API
- Security: check channel ownership when setting check's channels via API
- API: don't let SuspiciousOperation bubble up when validating channel ids
- API security: check channel ownership when setting check's channels
- API: update check's "alert_after" field when changing schedule
## v1.13.0 - 2020-02-13 ## v1.13.0 - 2020-02-13


+ 10
- 1
hc/api/tests/test_update_check.py View File

@ -1,5 +1,7 @@
from datetime import timedelta as td
import uuid import uuid
from django.utils.timezone import now
from hc.api.models import Channel, Check from hc.api.models import Channel, Check
from hc.test import BaseTestCase from hc.test import BaseTestCase
@ -14,6 +16,10 @@ class UpdateCheckTestCase(BaseTestCase):
return self.client.post(url, data, content_type="application/json") return self.client.post(url, data, content_type="application/json")
def test_it_works(self): def test_it_works(self):
self.check.last_ping = now()
self.check.status = "up"
self.check.save()
r = self.post( r = self.post(
self.check.code, self.check.code,
{ {
@ -34,7 +40,6 @@ class UpdateCheckTestCase(BaseTestCase):
self.assertEqual(doc["name"], "Foo") self.assertEqual(doc["name"], "Foo")
self.assertEqual(doc["tags"], "bar,baz") self.assertEqual(doc["tags"], "bar,baz")
self.assertEqual(doc["desc"], "My description") self.assertEqual(doc["desc"], "My description")
self.assertEqual(doc["last_ping"], None)
self.assertEqual(doc["n_pings"], 0) self.assertEqual(doc["n_pings"], 0)
self.assertTrue("schedule" not in doc) self.assertTrue("schedule" not in doc)
@ -48,6 +53,10 @@ class UpdateCheckTestCase(BaseTestCase):
self.assertEqual(self.check.timeout.total_seconds(), 3600) self.assertEqual(self.check.timeout.total_seconds(), 3600)
self.assertEqual(self.check.grace.total_seconds(), 60) self.assertEqual(self.check.grace.total_seconds(), 60)
# alert_after should be updated too
expected_aa = self.check.last_ping + td(seconds=3600 + 60)
self.assertEqual(self.check.alert_after, expected_aa)
def test_it_handles_options(self): def test_it_handles_options(self):
r = self.client.options("/api/v1/checks/%s" % self.check.code) r = self.client.options("/api/v1/checks/%s" % self.check.code)
self.assertEqual(r.status_code, 204) self.assertEqual(r.status_code, 204)


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

@ -89,6 +89,7 @@ def _update(check, spec):
if "tz" in spec: if "tz" in spec:
check.tz = spec["tz"] check.tz = spec["tz"]
check.alert_after = check.going_down_after()
check.save() check.save()
# This needs to be done after saving the check, because of # This needs to be done after saving the check, because of


Loading…
Cancel
Save