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.

114 lines
3.9 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", project=self.project)
  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", project=self.project)
  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, "http://down.example.com")
  29. self.assertContains(r, "http://up.example.com")
  30. self.assertContains(r, "foobar")
  31. def test_it_shows_pushover_details(self):
  32. ch = Channel(kind="po", project=self.project)
  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, "(normal priority)")
  39. def test_it_shows_disabled_email(self):
  40. check = Check(project=self.project, status="up")
  41. check.save()
  42. channel = Channel(project=self.project, kind="email")
  43. channel.value = "[email protected]"
  44. channel.save()
  45. n = Notification(owner=check, channel=channel, error="Invalid address")
  46. n.save()
  47. self.client.login(username="[email protected]", password="password")
  48. r = self.client.get("/integrations/")
  49. self.assertEqual(r.status_code, 200)
  50. self.assertContains(r, "Disabled")
  51. def test_it_shows_unconfirmed_email(self):
  52. channel = Channel(project=self.project, kind="email")
  53. channel.value = "[email protected]"
  54. channel.save()
  55. self.client.login(username="[email protected]", password="password")
  56. r = self.client.get("/integrations/")
  57. self.assertEqual(r.status_code, 200)
  58. self.assertContains(r, "Unconfirmed")
  59. def test_it_shows_down_only_note_for_email(self):
  60. channel = Channel(project=self.project, kind="email")
  61. channel.value = json.dumps({
  62. "value": "[email protected]",
  63. "up": False,
  64. "down": True
  65. })
  66. channel.save()
  67. self.client.login(username="[email protected]", password="password")
  68. r = self.client.get("/integrations/")
  69. self.assertEqual(r.status_code, 200)
  70. self.assertContains(r, "(down only)")
  71. def test_it_shows_up_only_note_for_email(self):
  72. channel = Channel(project=self.project, kind="email")
  73. channel.value = json.dumps({
  74. "value": "[email protected]",
  75. "up": True,
  76. "down": False
  77. })
  78. channel.save()
  79. self.client.login(username="[email protected]", password="password")
  80. r = self.client.get("/integrations/")
  81. self.assertEqual(r.status_code, 200)
  82. self.assertContains(r, "(up only)")
  83. def test_it_shows_sms_label(self):
  84. ch = Channel(kind="sms", project=self.project)
  85. ch.value = json.dumps({"value": "+123", "label": "My Phone"})
  86. ch.save()
  87. self.client.login(username="[email protected]", password="password")
  88. r = self.client.get("/integrations/")
  89. self.assertEqual(r.status_code, 200)
  90. self.assertContains(r, "SMS to +123")