diff --git a/hc/front/forms.py b/hc/front/forms.py index 88f43e4f..3721adb1 100644 --- a/hc/front/forms.py +++ b/hc/front/forms.py @@ -24,10 +24,9 @@ class TimeoutForm(forms.Form): class CronForm(forms.Form): - schedule = forms.CharField(required=False, max_length=100, + schedule = forms.CharField(max_length=100, validators=[CronExpressionValidator()]) - tz = forms.CharField(required=False, max_length=36, - validators=[TimezoneValidator()]) + tz = forms.CharField(max_length=36, validators=[TimezoneValidator()]) grace = forms.IntegerField(min_value=1, max_value=43200) diff --git a/hc/front/tests/test_update_timeout.py b/hc/front/tests/test_update_timeout.py index dc25bfeb..e1578efa 100644 --- a/hc/front/tests/test_update_timeout.py +++ b/hc/front/tests/test_update_timeout.py @@ -84,6 +84,32 @@ class UpdateTimeoutTestCase(BaseTestCase): self.check.refresh_from_db() self.assertEqual(self.check.kind, "simple") + def test_it_rejects_missing_schedule(self): + url = "/checks/%s/timeout/" % self.check.code + # tz field is omitted so this should fail: + payload = { + "kind": "cron", + "grace": 60, + "tz": "UTC" + } + + self.client.login(username="alice@example.org", password="password") + r = self.client.post(url, data=payload) + self.assertEqual(r.status_code, 400) + + def test_it_rejects_missing_tz(self): + url = "/checks/%s/timeout/" % self.check.code + # tz field is omitted so this should fail: + payload = { + "kind": "cron", + "schedule": "* * * * *", + "grace": 60 + } + + self.client.login(username="alice@example.org", password="password") + r = self.client.post(url, data=payload) + self.assertEqual(r.status_code, 400) + def test_team_access_works(self): url = "/checks/%s/timeout/" % self.check.code payload = {"kind": "simple", "timeout": 7200, "grace": 60}