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.

143 lines
5.2 KiB

  1. import json
  2. from hc.api.models import Channel
  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(self.channels_url)
  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(self.channels_url)
  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(self.channels_url)
  47. self.assertEqual(r.status_code, 200)
  48. self.assertContains(r, "(normal priority)")
  49. def test_it_shows_unconfirmed_email(self):
  50. channel = Channel(project=self.project, kind="email")
  51. channel.value = "[email protected]"
  52. channel.save()
  53. self.client.login(username="[email protected]", password="password")
  54. r = self.client.get(self.channels_url)
  55. self.assertEqual(r.status_code, 200)
  56. self.assertContains(r, "Unconfirmed")
  57. def test_it_shows_down_only_note_for_email(self):
  58. channel = Channel(project=self.project, kind="email")
  59. channel.value = json.dumps(
  60. {"value": "[email protected]", "up": False, "down": True}
  61. )
  62. channel.save()
  63. self.client.login(username="[email protected]", password="password")
  64. r = self.client.get(self.channels_url)
  65. self.assertEqual(r.status_code, 200)
  66. self.assertContains(r, "(down only)")
  67. def test_it_shows_up_only_note_for_email(self):
  68. channel = Channel(project=self.project, kind="email")
  69. channel.value = json.dumps(
  70. {"value": "[email protected]", "up": True, "down": False}
  71. )
  72. channel.save()
  73. self.client.login(username="[email protected]", password="password")
  74. r = self.client.get(self.channels_url)
  75. self.assertEqual(r.status_code, 200)
  76. self.assertContains(r, "(up only)")
  77. def test_it_shows_sms_number(self):
  78. ch = Channel(kind="sms", project=self.project)
  79. ch.value = json.dumps({"value": "+123"})
  80. ch.save()
  81. self.client.login(username="[email protected]", password="password")
  82. r = self.client.get(self.channels_url)
  83. self.assertEqual(r.status_code, 200)
  84. self.assertContains(r, "SMS to +123")
  85. def test_it_shows_channel_issues_indicator(self):
  86. Channel.objects.create(kind="sms", project=self.project, last_error="x")
  87. self.client.login(username="[email protected]", password="password")
  88. r = self.client.get(self.channels_url)
  89. self.assertContains(r, "broken-channels", status_code=200)
  90. def test_it_hides_actions_from_readonly_users(self):
  91. self.bobs_membership.rw = False
  92. self.bobs_membership.save()
  93. Channel.objects.create(project=self.project, kind="webhook", value="{}")
  94. self.client.login(username="[email protected]", password="password")
  95. r = self.client.get(self.channels_url)
  96. self.assertNotContains(r, "Add Integration", status_code=200)
  97. self.assertNotContains(r, "ic-delete")
  98. self.assertNotContains(r, "edit_webhook")
  99. def test_it_shows_down_only_note_for_sms(self):
  100. channel = Channel(project=self.project, kind="sms")
  101. channel.value = json.dumps({"value": "+123123123", "up": False, "down": True})
  102. channel.save()
  103. self.client.login(username="[email protected]", password="password")
  104. r = self.client.get(self.channels_url)
  105. self.assertEqual(r.status_code, 200)
  106. self.assertContains(r, "(down only)")
  107. def test_it_shows_up_only_note_for_sms(self):
  108. channel = Channel(project=self.project, kind="sms")
  109. channel.value = json.dumps({"value": "+123123123", "up": True, "down": False})
  110. channel.save()
  111. self.client.login(username="[email protected]", password="password")
  112. r = self.client.get(self.channels_url)
  113. self.assertEqual(r.status_code, 200)
  114. self.assertContains(r, "(up only)")