Require valid "schedule" and "tz" fields for cron checks.

This commit is contained in:
Pēteris Caune 2017-05-01 22:22:49 +03:00
parent f99c222ebf
commit 810089d183
2 changed files with 28 additions and 3 deletions

View File

@ -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)

View File

@ -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}