From 166115ebfbcffd68ce7f6d2494657fff0e70575d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Sat, 17 Mar 2018 09:43:55 +0200 Subject: [PATCH] Allow setting 30 day timeouts and grace times through API. --- hc/api/schemas.py | 4 ++-- hc/api/tests/test_create_check.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hc/api/schemas.py b/hc/api/schemas.py index dd4733b6..db0b8df8 100644 --- a/hc/api/schemas.py +++ b/hc/api/schemas.py @@ -3,8 +3,8 @@ check = { "properties": { "name": {"type": "string", "maxLength": 100}, "tags": {"type": "string", "maxLength": 500}, - "timeout": {"type": "number", "minimum": 60, "maximum": 604800}, - "grace": {"type": "number", "minimum": 60, "maximum": 604800}, + "timeout": {"type": "number", "minimum": 60, "maximum": 2592000}, + "grace": {"type": "number", "minimum": 60, "maximum": 2592000}, "schedule": {"type": "string", "format": "cron", "maxLength": 100}, "tz": {"type": "string", "format": "timezone", "maxLength": 36}, "channels": {"type": "string"}, diff --git a/hc/api/tests/test_create_check.py b/hc/api/tests/test_create_check.py index 7c981b81..451520c5 100644 --- a/hc/api/tests/test_create_check.py +++ b/hc/api/tests/test_create_check.py @@ -42,13 +42,26 @@ class CreateCheckTestCase(BaseTestCase): self.assertTrue("schedule" not in doc) self.assertTrue("tz" not in doc) - self.assertEqual(Check.objects.count(), 1) check = Check.objects.get() self.assertEqual(check.name, "Foo") self.assertEqual(check.tags, "bar,baz") self.assertEqual(check.timeout.total_seconds(), 3600) self.assertEqual(check.grace.total_seconds(), 60) + def test_30_days_works(self): + r = self.post({ + "api_key": "abc", + "name": "Foo", + "timeout": 2592000, + "grace": 2592000 + }) + + self.assertEqual(r.status_code, 201) + + check = Check.objects.get() + self.assertEqual(check.timeout.total_seconds(), 2592000) + self.assertEqual(check.grace.total_seconds(), 2592000) + def test_it_accepts_api_key_in_header(self): payload = json.dumps({"name": "Foo"}) r = self.client.post(self.URL, payload, @@ -103,7 +116,7 @@ class CreateCheckTestCase(BaseTestCase): expected_fragment="timeout is too small") def test_it_rejects_large_timeout(self): - self.post({"api_key": "abc", "timeout": 604801}, + self.post({"api_key": "abc", "timeout": 2592001}, expected_fragment="timeout is too large") def test_it_rejects_non_number_timeout(self):