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.

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