|
@ -13,12 +13,13 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
self.check.last_ping = timezone.now() |
|
|
self.check.last_ping = timezone.now() |
|
|
self.check.save() |
|
|
self.check.save() |
|
|
|
|
|
|
|
|
|
|
|
self.url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
|
|
|
def test_it_works(self): |
|
|
def test_it_works(self): |
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
payload = {"kind": "simple", "timeout": 3600, "grace": 60} |
|
|
payload = {"kind": "simple", "timeout": 3600, "grace": 60} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertRedirects(r, "/checks/") |
|
|
self.assertRedirects(r, "/checks/") |
|
|
|
|
|
|
|
|
self.check.refresh_from_db() |
|
|
self.check.refresh_from_db() |
|
@ -34,12 +35,11 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
self.check.status = "down" |
|
|
self.check.status = "down" |
|
|
self.check.save() |
|
|
self.check.save() |
|
|
|
|
|
|
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
# 1 week: |
|
|
# 1 week: |
|
|
payload = {"kind": "simple", "timeout": 3600 * 24 * 7, "grace": 60} |
|
|
payload = {"kind": "simple", "timeout": 3600 * 24 * 7, "grace": 60} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertRedirects(r, "/checks/") |
|
|
self.assertRedirects(r, "/checks/") |
|
|
|
|
|
|
|
|
self.check.refresh_from_db() |
|
|
self.check.refresh_from_db() |
|
@ -51,7 +51,6 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
self.assertEqual(flip.new_status, "up") |
|
|
self.assertEqual(flip.new_status, "up") |
|
|
|
|
|
|
|
|
def test_it_saves_cron_expression(self): |
|
|
def test_it_saves_cron_expression(self): |
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
payload = { |
|
|
payload = { |
|
|
"kind": "cron", |
|
|
"kind": "cron", |
|
|
"schedule": "5 * * * *", |
|
|
"schedule": "5 * * * *", |
|
@ -60,7 +59,7 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertRedirects(r, "/checks/") |
|
|
self.assertRedirects(r, "/checks/") |
|
|
|
|
|
|
|
|
self.check.refresh_from_db() |
|
|
self.check.refresh_from_db() |
|
@ -68,10 +67,6 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
self.assertEqual(self.check.schedule, "5 * * * *") |
|
|
self.assertEqual(self.check.schedule, "5 * * * *") |
|
|
|
|
|
|
|
|
def test_it_validates_cron_expression(self): |
|
|
def test_it_validates_cron_expression(self): |
|
|
self.check.last_ping = None |
|
|
|
|
|
self.check.save() |
|
|
|
|
|
|
|
|
|
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
payload = { |
|
|
payload = { |
|
|
"kind": "cron", |
|
|
"kind": "cron", |
|
|
"schedule": "* invalid *", |
|
|
"schedule": "* invalid *", |
|
@ -80,18 +75,30 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertEqual(r.status_code, 400) |
|
|
self.assertEqual(r.status_code, 400) |
|
|
|
|
|
|
|
|
# Check should still have its original data: |
|
|
# Check should still have its original data: |
|
|
self.check.refresh_from_db() |
|
|
self.check.refresh_from_db() |
|
|
self.assertEqual(self.check.kind, "simple") |
|
|
self.assertEqual(self.check.kind, "simple") |
|
|
|
|
|
|
|
|
def test_it_validates_tz(self): |
|
|
|
|
|
self.check.last_ping = None |
|
|
|
|
|
self.check.save() |
|
|
|
|
|
|
|
|
def test_it_rejects_six_field_cron_expression(self): |
|
|
|
|
|
payload = { |
|
|
|
|
|
"kind": "cron", |
|
|
|
|
|
"schedule": "* * * * * *", # six fields instead of five |
|
|
|
|
|
"tz": "UTC", |
|
|
|
|
|
"grace": 60 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
|
|
|
self.assertEqual(r.status_code, 400) |
|
|
|
|
|
|
|
|
|
|
|
# Check should still have its original data: |
|
|
|
|
|
self.check.refresh_from_db() |
|
|
|
|
|
self.assertEqual(self.check.kind, "simple") |
|
|
|
|
|
|
|
|
|
|
|
def test_it_validates_tz(self): |
|
|
payload = { |
|
|
payload = { |
|
|
"kind": "cron", |
|
|
"kind": "cron", |
|
|
"schedule": "* * * * *", |
|
|
"schedule": "* * * * *", |
|
@ -100,7 +107,7 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertEqual(r.status_code, 400) |
|
|
self.assertEqual(r.status_code, 400) |
|
|
|
|
|
|
|
|
# Check should still have its original data: |
|
|
# Check should still have its original data: |
|
@ -108,7 +115,6 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
self.assertEqual(self.check.kind, "simple") |
|
|
self.assertEqual(self.check.kind, "simple") |
|
|
|
|
|
|
|
|
def test_it_rejects_missing_schedule(self): |
|
|
def test_it_rejects_missing_schedule(self): |
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
# tz field is omitted so this should fail: |
|
|
# tz field is omitted so this should fail: |
|
|
payload = { |
|
|
payload = { |
|
|
"kind": "cron", |
|
|
"kind": "cron", |
|
@ -117,11 +123,10 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertEqual(r.status_code, 400) |
|
|
self.assertEqual(r.status_code, 400) |
|
|
|
|
|
|
|
|
def test_it_rejects_missing_tz(self): |
|
|
def test_it_rejects_missing_tz(self): |
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
# tz field is omitted so this should fail: |
|
|
# tz field is omitted so this should fail: |
|
|
payload = { |
|
|
payload = { |
|
|
"kind": "cron", |
|
|
"kind": "cron", |
|
@ -130,17 +135,16 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertEqual(r.status_code, 400) |
|
|
self.assertEqual(r.status_code, 400) |
|
|
|
|
|
|
|
|
def test_team_access_works(self): |
|
|
def test_team_access_works(self): |
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
payload = {"kind": "simple", "timeout": 7200, "grace": 60} |
|
|
payload = {"kind": "simple", "timeout": 7200, "grace": 60} |
|
|
|
|
|
|
|
|
# Logging in as bob, not alice. Bob has team access so this |
|
|
# Logging in as bob, not alice. Bob has team access so this |
|
|
# should work. |
|
|
# should work. |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
self.client.post(self.url, data=payload) |
|
|
|
|
|
|
|
|
check = Check.objects.get(code=self.check.code) |
|
|
check = Check.objects.get(code=self.check.code) |
|
|
assert check.timeout.total_seconds() == 7200 |
|
|
assert check.timeout.total_seconds() == 7200 |
|
@ -163,26 +167,23 @@ class UpdateTimeoutTestCase(BaseTestCase): |
|
|
assert r.status_code == 404 |
|
|
assert r.status_code == 404 |
|
|
|
|
|
|
|
|
def test_it_checks_ownership(self): |
|
|
def test_it_checks_ownership(self): |
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
payload = {"timeout": 3600, "grace": 60} |
|
|
payload = {"timeout": 3600, "grace": 60} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertEqual(r.status_code, 404) |
|
|
self.assertEqual(r.status_code, 404) |
|
|
|
|
|
|
|
|
def test_it_rejects_get(self): |
|
|
def test_it_rejects_get(self): |
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.get(url) |
|
|
|
|
|
|
|
|
r = self.client.get(self.url) |
|
|
self.assertEqual(r.status_code, 405) |
|
|
self.assertEqual(r.status_code, 405) |
|
|
|
|
|
|
|
|
def test_it_allows_cross_team_access(self): |
|
|
def test_it_allows_cross_team_access(self): |
|
|
self.bobs_profile.current_team = None |
|
|
self.bobs_profile.current_team = None |
|
|
self.bobs_profile.save() |
|
|
self.bobs_profile.save() |
|
|
|
|
|
|
|
|
url = "/checks/%s/timeout/" % self.check.code |
|
|
|
|
|
payload = {"kind": "simple", "timeout": 3600, "grace": 60} |
|
|
payload = {"kind": "simple", "timeout": 3600, "grace": 60} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(url, data=payload) |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, data=payload) |
|
|
self.assertRedirects(r, "/checks/") |
|
|
self.assertRedirects(r, "/checks/") |