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.

74 lines
2.5 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. def test_it_works(self):
  11. url = "/checks/%s/log/" % self.check.code
  12. self.client.login(username="[email protected]", password="password")
  13. r = self.client.get(url)
  14. self.assertContains(r, "Local Time", status_code=200)
  15. def test_team_access_works(self):
  16. url = "/checks/%s/log/" % self.check.code
  17. # Logging in as bob, not alice. Bob has team access so this
  18. # should work.
  19. self.client.login(username="[email protected]", password="password")
  20. r = self.client.get(url)
  21. self.assertEqual(r.status_code, 200)
  22. def test_it_handles_bad_uuid(self):
  23. url = "/checks/not-uuid/log/"
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.get(url)
  26. assert r.status_code == 400
  27. def test_it_handles_missing_uuid(self):
  28. # Valid UUID but there is no check for it:
  29. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/log/"
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.get(url)
  32. assert r.status_code == 404
  33. def test_it_checks_ownership(self):
  34. url = "/checks/%s/log/" % self.check.code
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.get(url)
  37. assert r.status_code == 403
  38. def test_it_shows_pushover_notifications(self):
  39. ch = Channel(kind="po", user=self.alice)
  40. ch.save()
  41. Notification(owner=self.check, channel=ch, check_status="down").save()
  42. url = "/checks/%s/log/" % self.check.code
  43. self.client.login(username="[email protected]", password="password")
  44. r = self.client.get(url)
  45. self.assertContains(r, "Sent a Pushover notification", status_code=200)
  46. def test_it_shows_webhook_notifications(self):
  47. ch = Channel(kind="webhook", user=self.alice, value="foo/$NAME")
  48. ch.save()
  49. Notification(owner=self.check, channel=ch, check_status="down").save()
  50. url = "/checks/%s/log/" % self.check.code
  51. self.client.login(username="[email protected]", password="password")
  52. r = self.client.get(url)
  53. self.assertContains(r, "Called webhook foo/$NAME", status_code=200)