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.6 KiB

  1. import json
  2. from hc.api.models import Check, Channel, Notification
  3. from hc.test import BaseTestCase
  4. class ChannelsTestCase(BaseTestCase):
  5. def test_it_formats_complex_slack_value(self):
  6. ch = Channel(kind="slack", user=self.alice)
  7. ch.value = json.dumps({
  8. "ok": True,
  9. "team_name": "foo-team",
  10. "incoming_webhook": {
  11. "url": "http://example.org",
  12. "channel": "#bar"
  13. }
  14. })
  15. ch.save()
  16. self.client.login(username="[email protected]", password="password")
  17. r = self.client.get("/integrations/")
  18. self.assertContains(r, "foo-team", status_code=200)
  19. self.assertContains(r, "#bar")
  20. def test_it_shows_webhook_post_data(self):
  21. ch = Channel(kind="webhook", user=self.alice)
  22. ch.value = "http://down.example.com\nhttp://up.example.com\nfoobar"
  23. ch.save()
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.get("/integrations/")
  26. self.assertEqual(r.status_code, 200)
  27. # These are inside a modal:
  28. self.assertContains(r, "<code>http://down.example.com</code>")
  29. self.assertContains(r, "<code>http://up.example.com</code>")
  30. self.assertContains(r, "<code>foobar</code>")
  31. def test_it_shows_pushover_details(self):
  32. ch = Channel(kind="po", user=self.alice)
  33. ch.value = "fake-key|0"
  34. ch.save()
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.get("/integrations/")
  37. self.assertEqual(r.status_code, 200)
  38. self.assertContains(r, "fake-key")
  39. self.assertContains(r, "(normal priority)")
  40. def test_it_shows_disabled_email(self):
  41. check = Check(user=self.alice, status="up")
  42. check.save()
  43. channel = Channel(user=self.alice, kind="email")
  44. channel.value = "[email protected]"
  45. channel.save()
  46. n = Notification(owner=check, channel=channel, error="Invalid address")
  47. n.save()
  48. self.client.login(username="[email protected]", password="password")
  49. r = self.client.get("/integrations/")
  50. self.assertEqual(r.status_code, 200)
  51. self.assertContains(r, "(bounced, disabled)")
  52. def test_it_shows_unconfirmed_email(self):
  53. channel = Channel(user=self.alice, kind="email")
  54. channel.value = "[email protected]"
  55. channel.save()
  56. self.client.login(username="[email protected]", password="password")
  57. r = self.client.get("/integrations/")
  58. self.assertEqual(r.status_code, 200)
  59. self.assertContains(r, "(unconfirmed)")