Browse Source

API: fix updating kind=cron to kind=simple

pull/117/head
Pēteris Caune 8 years ago
parent
commit
31eca9c8e8
2 changed files with 13 additions and 1 deletions
  1. +11
    -0
      hc/api/tests/test_update_check.py
  2. +2
    -1
      hc/api/views.py

+ 11
- 0
hc/api/tests/test_update_check.py View File

@ -75,3 +75,14 @@ class UpdateCheckTestCase(BaseTestCase):
made_up_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02" made_up_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
r = self.post(made_up_code, {"api_key": "abc"}) r = self.post(made_up_code, {"api_key": "abc"})
self.assertEqual(r.status_code, 400) self.assertEqual(r.status_code, 400)
def test_it_updates_cron_to_simple(self):
self.check.kind = "cron"
self.check.schedule = "5 * * * *"
self.check.save()
r = self.post(self.check.code, {"api_key": "abc", "timeout": 3600})
self.assertEqual(r.status_code, 200)
self.check.refresh_from_db()
self.assertEqual(self.check.kind, "simple")

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

@ -72,6 +72,7 @@ def _update(check, spec):
check.tags = spec["tags"] check.tags = spec["tags"]
if "timeout" in spec and "schedule" not in spec: if "timeout" in spec and "schedule" not in spec:
check.kind = "simple"
check.timeout = td(seconds=spec["timeout"]) check.timeout = td(seconds=spec["timeout"])
if "grace" in spec: if "grace" in spec:
@ -80,7 +81,7 @@ def _update(check, spec):
if "schedule" in spec: if "schedule" in spec:
check.kind = "cron" check.kind = "cron"
check.schedule = spec["schedule"] check.schedule = spec["schedule"]
if "tz" in spec and "schedule" in spec:
if "tz" in spec:
check.tz = spec["tz"] check.tz = spec["tz"]
check.save() check.save()


Loading…
Cancel
Save