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.

76 lines
2.8 KiB

  1. from hc.api.models import Check, Ping
  2. from hc.test import BaseTestCase
  3. class DetailsTestCase(BaseTestCase):
  4. def setUp(self):
  5. super().setUp()
  6. self.check = Check.objects.create(project=self.project)
  7. ping = Ping.objects.create(owner=self.check)
  8. # Older MySQL versions don't store microseconds. This makes sure
  9. # the ping is older than any notifications we may create later:
  10. ping.created = "2000-01-01T00:00:00+00:00"
  11. ping.save()
  12. self.url = "/checks/%s/details/" % self.check.code
  13. def test_it_works(self):
  14. self.client.login(username="[email protected]", password="password")
  15. r = self.client.get(self.url)
  16. self.assertContains(r, "How To Ping", status_code=200)
  17. # The page should contain timezone strings
  18. self.assertContains(r, "Europe/Riga")
  19. def test_it_checks_ownership(self):
  20. self.client.login(username="[email protected]", password="password")
  21. r = self.client.get(self.url)
  22. self.assertEqual(r.status_code, 404)
  23. def test_it_shows_cron_expression(self):
  24. self.check.kind = "cron"
  25. self.check.save()
  26. self.client.login(username="[email protected]", password="password")
  27. r = self.client.get(self.url)
  28. self.assertContains(r, "Cron Expression", status_code=200)
  29. def test_it_allows_cross_team_access(self):
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.get(self.url)
  32. self.assertEqual(r.status_code, 200)
  33. def test_it_shows_new_check_notice(self):
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.get(self.url + "?new")
  36. self.assertContains(r, "Your new check is ready!", status_code=200)
  37. def test_it_hides_actions_from_readonly_users(self):
  38. self.bobs_membership.rw = False
  39. self.bobs_membership.save()
  40. self.client.login(username="[email protected]", password="password")
  41. r = self.client.get(self.url)
  42. self.assertNotContains(r, "edit-name", status_code=200)
  43. self.assertNotContains(r, "edit-desc")
  44. self.assertNotContains(r, "Filtering Rules")
  45. self.assertNotContains(r, "pause-btn")
  46. self.assertNotContains(r, "Change Schedule")
  47. self.assertNotContains(r, "Create a Copy…")
  48. self.assertNotContains(r, "transfer-btn")
  49. self.assertNotContains(r, "details-remove-check")
  50. def test_it_hides_resume_action_from_readonly_users(self):
  51. self.bobs_membership.rw = False
  52. self.bobs_membership.save()
  53. self.check.status = "paused"
  54. self.check.manual_resume = True
  55. self.check.save()
  56. self.client.login(username="[email protected]", password="password")
  57. r = self.client.get(self.url)
  58. self.assertNotContains(r, "resume-btn", status_code=200)