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.

92 lines
3.4 KiB

9 years ago
9 years ago
9 years ago
  1. import json
  2. from hc.api.models import Channel, Check, Notification, Ping
  3. from hc.test import BaseTestCase
  4. class LogTestCase(BaseTestCase):
  5. def setUp(self):
  6. super(LogTestCase, self).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/log/" % 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, "Browser's time zone", status_code=200)
  18. def test_team_access_works(self):
  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(self.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. self.client.login(username="[email protected]", password="password")
  37. r = self.client.get(self.url)
  38. self.assertEqual(r.status_code, 404)
  39. def test_it_shows_email_notification(self):
  40. ch = Channel(kind="email", project=self.project)
  41. ch.value = json.dumps({"value": "[email protected]", "up": True, "down": True})
  42. ch.save()
  43. Notification(owner=self.check, channel=ch, check_status="down").save()
  44. self.client.login(username="[email protected]", password="password")
  45. r = self.client.get(self.url)
  46. self.assertContains(r, "Sent email alert to [email protected]", status_code=200)
  47. def test_it_shows_pushover_notification(self):
  48. ch = Channel.objects.create(kind="po", project=self.project)
  49. Notification(owner=self.check, channel=ch, check_status="down").save()
  50. self.client.login(username="[email protected]", password="password")
  51. r = self.client.get(self.url)
  52. self.assertContains(r, "Sent a Pushover notification", status_code=200)
  53. def test_it_shows_webhook_notification(self):
  54. ch = Channel(kind="webhook", project=self.project)
  55. ch.value = "foo/$NAME"
  56. ch.save()
  57. Notification(owner=self.check, channel=ch, check_status="down").save()
  58. self.client.login(username="[email protected]", password="password")
  59. r = self.client.get(self.url)
  60. self.assertContains(r, "Called webhook foo/$NAME", status_code=200)
  61. def test_it_allows_cross_team_access(self):
  62. self.bobs_profile.current_project = None
  63. self.bobs_profile.save()
  64. self.client.login(username="[email protected]", password="password")
  65. r = self.client.get(self.url)
  66. self.assertEqual(r.status_code, 200)