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.

134 lines
4.7 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. {
  9. "ok": True,
  10. "team_name": "foo-team",
  11. "incoming_webhook": {"url": "http://example.org", "channel": "#bar"},
  12. }
  13. )
  14. ch.save()
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.get("/integrations/")
  17. self.assertContains(r, "foo-team", status_code=200)
  18. self.assertContains(r, "#bar")
  19. def test_it_shows_webhook_post_data(self):
  20. ch = Channel(kind="webhook", project=self.project)
  21. ch.value = json.dumps(
  22. {
  23. "method_down": "POST",
  24. "url_down": "http://down.example.com",
  25. "body_down": "foobar",
  26. "headers_down": {},
  27. "method_up": "GET",
  28. "url_up": "http://up.example.com",
  29. "body_up": "",
  30. "headers_up": {},
  31. }
  32. )
  33. ch.save()
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.get("/integrations/")
  36. self.assertEqual(r.status_code, 200)
  37. # These are inside a modal:
  38. self.assertContains(r, "http://down.example.com")
  39. self.assertContains(r, "http://up.example.com")
  40. self.assertContains(r, "foobar")
  41. def test_it_shows_pushover_details(self):
  42. ch = Channel(kind="po", project=self.project)
  43. ch.value = "fake-key|0"
  44. ch.save()
  45. self.client.login(username="[email protected]", password="password")
  46. r = self.client.get("/integrations/")
  47. self.assertEqual(r.status_code, 200)
  48. self.assertContains(r, "(normal priority)")
  49. def test_it_shows_disabled_email(self):
  50. check = Check(project=self.project, status="up")
  51. check.save()
  52. channel = Channel(project=self.project, kind="email")
  53. channel.value = "[email protected]"
  54. channel.save()
  55. n = Notification(owner=check, channel=channel, error="Invalid address")
  56. n.save()
  57. self.client.login(username="[email protected]", password="password")
  58. r = self.client.get("/integrations/")
  59. self.assertEqual(r.status_code, 200)
  60. self.assertContains(r, "Disabled")
  61. def test_it_shows_unconfirmed_email(self):
  62. channel = Channel(project=self.project, kind="email")
  63. channel.value = "[email protected]"
  64. channel.save()
  65. self.client.login(username="[email protected]", password="password")
  66. r = self.client.get("/integrations/")
  67. self.assertEqual(r.status_code, 200)
  68. self.assertContains(r, "Unconfirmed")
  69. def test_it_shows_down_only_note_for_email(self):
  70. channel = Channel(project=self.project, kind="email")
  71. channel.value = json.dumps(
  72. {"value": "[email protected]", "up": False, "down": True}
  73. )
  74. channel.save()
  75. self.client.login(username="[email protected]", password="password")
  76. r = self.client.get("/integrations/")
  77. self.assertEqual(r.status_code, 200)
  78. self.assertContains(r, "(down only)")
  79. def test_it_shows_up_only_note_for_email(self):
  80. channel = Channel(project=self.project, kind="email")
  81. channel.value = json.dumps(
  82. {"value": "[email protected]", "up": True, "down": False}
  83. )
  84. channel.save()
  85. self.client.login(username="[email protected]", password="password")
  86. r = self.client.get("/integrations/")
  87. self.assertEqual(r.status_code, 200)
  88. self.assertContains(r, "(up only)")
  89. def test_it_shows_sms_number(self):
  90. ch = Channel(kind="sms", project=self.project)
  91. ch.value = json.dumps({"value": "+123"})
  92. ch.save()
  93. self.client.login(username="[email protected]", password="password")
  94. r = self.client.get("/integrations/")
  95. self.assertEqual(r.status_code, 200)
  96. self.assertContains(r, "SMS to +123")
  97. def test_it_requires_current_project(self):
  98. self.profile.current_project = None
  99. self.profile.save()
  100. self.client.login(username="[email protected]", password="password")
  101. r = self.client.get("/integrations/")
  102. self.assertRedirects(r, "/")
  103. def test_it_shows_broken_channel_indicator(self):
  104. Channel.objects.create(kind="sms", project=self.project, last_error="x")
  105. self.client.login(username="[email protected]", password="password")
  106. r = self.client.get("/integrations/")
  107. self.assertContains(r, "broken-channels", status_code=200)