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.

79 lines
2.7 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(user=self.alice)
  7. self.check.save()
  8. ping = Ping(owner=self.check)
  9. ping.save()
  10. # Older MySQL versions don't store microseconds. This makes sure
  11. # the ping is older than any notifications we may create later:
  12. ping.created = "2000-01-01T00:00:00+00:00"
  13. ping.save()
  14. def test_it_works(self):
  15. url = "/checks/%s/log/" % self.check.code
  16. self.client.login(username="[email protected]", password="password")
  17. r = self.client.get(url)
  18. self.assertContains(r, "Local Time", status_code=200)
  19. def test_team_access_works(self):
  20. url = "/checks/%s/log/" % self.check.code
  21. # Logging in as bob, not alice. Bob has team access so this
  22. # should work.
  23. self.client.login(username="[email protected]", password="password")
  24. r = self.client.get(url)
  25. self.assertEqual(r.status_code, 200)
  26. def test_it_handles_bad_uuid(self):
  27. url = "/checks/not-uuid/log/"
  28. self.client.login(username="[email protected]", password="password")
  29. r = self.client.get(url)
  30. self.assertEqual(r.status_code, 404)
  31. def test_it_handles_missing_uuid(self):
  32. # Valid UUID but there is no check for it:
  33. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/log/"
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.get(url)
  36. assert r.status_code == 404
  37. def test_it_checks_ownership(self):
  38. url = "/checks/%s/log/" % self.check.code
  39. self.client.login(username="[email protected]", password="password")
  40. r = self.client.get(url)
  41. assert r.status_code == 403
  42. def test_it_shows_pushover_notifications(self):
  43. ch = Channel(kind="po", user=self.alice)
  44. ch.save()
  45. Notification(owner=self.check, channel=ch, check_status="down").save()
  46. url = "/checks/%s/log/" % self.check.code
  47. self.client.login(username="[email protected]", password="password")
  48. r = self.client.get(url)
  49. self.assertContains(r, "Sent a Pushover notification", status_code=200)
  50. def test_it_shows_webhook_notifications(self):
  51. ch = Channel(kind="webhook", user=self.alice, value="foo/$NAME")
  52. ch.save()
  53. Notification(owner=self.check, channel=ch, check_status="down").save()
  54. url = "/checks/%s/log/" % self.check.code
  55. self.client.login(username="[email protected]", password="password")
  56. r = self.client.get(url)
  57. self.assertContains(r, "Called webhook foo/$NAME", status_code=200)