From 31eca9c8e889dc8ed48e61192aa63cb1670e7270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 10 Mar 2017 09:54:16 +0200 Subject: [PATCH] API: fix updating kind=cron to kind=simple --- hc/api/tests/test_update_check.py | 11 +++++++++++ hc/api/views.py | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hc/api/tests/test_update_check.py b/hc/api/tests/test_update_check.py index 89e44b08..c350f0ed 100644 --- a/hc/api/tests/test_update_check.py +++ b/hc/api/tests/test_update_check.py @@ -75,3 +75,14 @@ class UpdateCheckTestCase(BaseTestCase): made_up_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02" r = self.post(made_up_code, {"api_key": "abc"}) 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") diff --git a/hc/api/views.py b/hc/api/views.py index 91607e93..2d10a479 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -72,6 +72,7 @@ def _update(check, spec): check.tags = spec["tags"] if "timeout" in spec and "schedule" not in spec: + check.kind = "simple" check.timeout = td(seconds=spec["timeout"]) if "grace" in spec: @@ -80,7 +81,7 @@ def _update(check, spec): if "schedule" in spec: check.kind = "cron" check.schedule = spec["schedule"] - if "tz" in spec and "schedule" in spec: + if "tz" in spec: check.tz = spec["tz"] check.save()