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.

86 lines
3.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. from hc.api.models import Channel, Check, Notification, Ping
  2. from hc.test import BaseTestCase
  3. class LogTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(LogTestCase, self).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. def test_it_works(self):
  13. url = "/checks/%s/log/" % self.check.code
  14. self.client.login(username="[email protected]", password="password")
  15. r = self.client.get(url)
  16. self.assertContains(r, "Local Time", status_code=200)
  17. def test_team_access_works(self):
  18. url = "/checks/%s/log/" % self.check.code
  19. # Logging in as bob, not alice. Bob has team access so this
  20. # should work.
  21. self.client.login(username="[email protected]", password="password")
  22. r = self.client.get(url)
  23. self.assertEqual(r.status_code, 200)
  24. def test_it_handles_bad_uuid(self):
  25. url = "/checks/not-uuid/log/"
  26. self.client.login(username="[email protected]", password="password")
  27. r = self.client.get(url)
  28. self.assertEqual(r.status_code, 404)
  29. def test_it_handles_missing_uuid(self):
  30. # Valid UUID but there is no check for it:
  31. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/log/"
  32. self.client.login(username="[email protected]", password="password")
  33. r = self.client.get(url)
  34. self.assertEqual(r.status_code, 404)
  35. def test_it_checks_ownership(self):
  36. url = "/checks/%s/log/" % self.check.code
  37. self.client.login(username="[email protected]", password="password")
  38. r = self.client.get(url)
  39. self.assertEqual(r.status_code, 404)
  40. def test_it_shows_pushover_notifications(self):
  41. ch = Channel.objects.create(kind="po", project=self.project)
  42. Notification(owner=self.check, channel=ch, check_status="down").save()
  43. url = "/checks/%s/log/" % self.check.code
  44. self.client.login(username="[email protected]", password="password")
  45. r = self.client.get(url)
  46. self.assertContains(r, "Sent a Pushover notification", status_code=200)
  47. def test_it_shows_webhook_notifications(self):
  48. ch = Channel(kind="webhook", project=self.project)
  49. ch.value = "foo/$NAME"
  50. ch.save()
  51. Notification(owner=self.check, channel=ch, check_status="down").save()
  52. url = "/checks/%s/log/" % self.check.code
  53. self.client.login(username="[email protected]", password="password")
  54. r = self.client.get(url)
  55. self.assertContains(r, "Called webhook foo/$NAME", status_code=200)
  56. def test_it_allows_cross_team_access(self):
  57. self.bobs_profile.current_project = None
  58. self.bobs_profile.save()
  59. url = "/checks/%s/log/" % self.check.code
  60. self.client.login(username="[email protected]", password="password")
  61. r = self.client.get(url)
  62. self.assertEqual(r.status_code, 200)