From b9997137a6ff86ac43b0edc2868f84642a222be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 27 Jan 2021 09:46:33 +0200 Subject: [PATCH] Bump croniter version to 1.0.2 --- hc/front/tests/test_cron_preview.py | 5 +++++ hc/lib/jsonschema.py | 4 ++++ hc/lib/tests/test_jsonschema.py | 2 +- requirements.txt | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hc/front/tests/test_cron_preview.py b/hc/front/tests/test_cron_preview.py index aac3d09d..d8299f1d 100644 --- a/hc/front/tests/test_cron_preview.py +++ b/hc/front/tests/test_cron_preview.py @@ -48,3 +48,8 @@ class CronPreviewTestCase(BaseTestCase): payload = {"schedule": "0 3 * * *", "tz": "Europe/Riga"} r = self.client.post("/checks/cron_preview/", payload) self.assertNotContains(r, "Invalid cron expression", status_code=200) + + def test_it_handles_feb_29(self): + payload = {"schedule": "0 0 29 2 *", "tz": "UTC"} + r = self.client.post("/checks/cron_preview/", payload) + self.assertContains(r, "Feb 29") diff --git a/hc/lib/jsonschema.py b/hc/lib/jsonschema.py index 8051975f..4e562b47 100644 --- a/hc/lib/jsonschema.py +++ b/hc/lib/jsonschema.py @@ -22,6 +22,10 @@ def validate(obj, schema, obj_name="value"): raise ValidationError("%s is too long" % obj_name) if schema.get("format") == "cron": try: + # Does it have 5 components? + if len(obj.split()) != 5: + raise ValueError() + # Does croniter accept the schedule? it = croniter(obj) # Can it calculate the next datetime? diff --git a/hc/lib/tests/test_jsonschema.py b/hc/lib/tests/test_jsonschema.py index 4049787b..9af31845 100644 --- a/hc/lib/tests/test_jsonschema.py +++ b/hc/lib/tests/test_jsonschema.py @@ -74,7 +74,7 @@ class JsonSchemaTestCase(TestCase): validate("baz", {"enum": ["foo", "bar"]}) def test_it_checks_cron_format(self): - samples = ["x * * * *", "0 0 31 2 *"] + samples = ["x * * * *", "0 0 31 2 *", "* * * * * *"] for sample in samples: with self.assertRaises(ValidationError): validate(sample, {"type": "string", "format": "cron"}) diff --git a/requirements.txt b/requirements.txt index c1b8f12a..b1676ffe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ cron-descriptor==1.2.24 -croniter==0.3.31 +croniter==1.0.2 Django==3.1.5 django-compressor==2.4 fido2