You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.2 KiB

  1. from hc.test import BaseTestCase
  2. class CronPreviewTestCase(BaseTestCase):
  3. def test_it_works(self):
  4. payload = {
  5. "schedule": "* * * * *",
  6. "tz": "UTC"
  7. }
  8. r = self.client.post("/checks/cron_preview/", payload)
  9. self.assertContains(r, "cron-preview-title", status_code=200)
  10. def test_it_handles_invalid_cron_expression(self):
  11. for schedule in [None, "", "*", "100 100 100 100 100"]:
  12. payload = {"schedule": schedule, "tz": "UTC"}
  13. r = self.client.post("/checks/cron_preview/", payload)
  14. self.assertContains(r, "Invalid cron expression", status_code=200)
  15. def test_it_handles_invalid_timezone(self):
  16. for tz in [None, "", "not-a-timezone"]:
  17. payload = {"schedule": "* * * * *", "tz": tz}
  18. r = self.client.post("/checks/cron_preview/", payload)
  19. self.assertContains(r, "Invalid timezone", status_code=200)
  20. def test_it_handles_missing_arguments(self):
  21. r = self.client.post("/checks/cron_preview/", {})
  22. self.assertContains(r, "Invalid cron expression", status_code=200)
  23. def test_it_rejects_get(self):
  24. r = self.client.get("/checks/cron_preview/", {})
  25. self.assertEqual(r.status_code, 400)