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.

107 lines
3.9 KiB

  1. from datetime import timedelta as td
  2. from hc.api.models import Check, Ping
  3. from hc.test import BaseTestCase
  4. class DetailsTestCase(BaseTestCase):
  5. def setUp(self):
  6. super().setUp()
  7. self.check = Check.objects.create(project=self.project)
  8. ping = Ping.objects.create(owner=self.check)
  9. # Older MySQL versions don't store microseconds. This makes sure
  10. # the ping is older than any notifications we may create later:
  11. ping.created = "2000-01-01T00:00:00+00:00"
  12. ping.save()
  13. self.url = "/checks/%s/details/" % self.check.code
  14. def test_it_works(self):
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.get(self.url)
  17. self.assertContains(r, "How To Ping", status_code=200)
  18. # The page should contain timezone strings
  19. self.assertContains(r, "Europe/Riga")
  20. def test_it_checks_ownership(self):
  21. self.client.login(username="[email protected]", password="password")
  22. r = self.client.get(self.url)
  23. self.assertEqual(r.status_code, 404)
  24. def test_it_shows_cron_expression(self):
  25. self.check.kind = "cron"
  26. self.check.save()
  27. self.client.login(username="[email protected]", password="password")
  28. r = self.client.get(self.url)
  29. self.assertContains(r, "Cron Expression", status_code=200)
  30. def test_it_allows_cross_team_access(self):
  31. self.client.login(username="[email protected]", password="password")
  32. r = self.client.get(self.url)
  33. self.assertEqual(r.status_code, 200)
  34. def test_it_shows_new_check_notice(self):
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.get(self.url + "?new")
  37. self.assertContains(r, "Your new check is ready!", status_code=200)
  38. def test_it_hides_actions_from_readonly_users(self):
  39. self.bobs_membership.rw = False
  40. self.bobs_membership.save()
  41. self.client.login(username="[email protected]", password="password")
  42. r = self.client.get(self.url)
  43. self.assertNotContains(r, "edit-name", status_code=200)
  44. self.assertNotContains(r, "edit-desc")
  45. self.assertNotContains(r, "Filtering Rules")
  46. self.assertNotContains(r, "pause-btn")
  47. self.assertNotContains(r, "Change Schedule")
  48. self.assertNotContains(r, "Create a Copy…")
  49. self.assertNotContains(r, "transfer-btn")
  50. self.assertNotContains(r, "details-remove-check")
  51. def test_it_hides_resume_action_from_readonly_users(self):
  52. self.bobs_membership.rw = False
  53. self.bobs_membership.save()
  54. self.check.status = "paused"
  55. self.check.manual_resume = True
  56. self.check.save()
  57. self.client.login(username="[email protected]", password="password")
  58. r = self.client.get(self.url)
  59. self.assertNotContains(r, "resume-btn", status_code=200)
  60. def test_crontab_example_guesses_schedules(self):
  61. self.client.login(username="[email protected]", password="password")
  62. pairs = [
  63. (td(minutes=1), "* * * * *"),
  64. (td(minutes=12), "*/12 * * * *"),
  65. (td(hours=1), "0 * * * *"),
  66. (td(hours=6), "0 */6 * * *"),
  67. (td(days=1), "0 0 * * *"),
  68. ]
  69. for timeout, expression in pairs:
  70. self.check.timeout = timeout
  71. self.check.save()
  72. r = self.client.get(self.url)
  73. self.assertContains(r, f"{expression} /your/command.sh")
  74. self.assertNotContains(r, 'FIXME: replace "* * * * *"')
  75. def test_crontab_example_handles_unsupported_timeout_values(self):
  76. self.client.login(username="[email protected]", password="password")
  77. self.check.timeout = td(minutes=13)
  78. self.check.save()
  79. r = self.client.get(self.url)
  80. self.assertContains(r, f"* * * * * /your/command.sh")
  81. self.assertContains(r, 'FIXME: replace "* * * * *"')