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.

86 lines
3.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  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, 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", user=self.alice, 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", user=self.alice, 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(user=self.alice, status="up", project=self.project)
  41. check.save()
  42. channel = Channel(user=self.alice, kind="email", project=self.project)
  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(user=self.alice, kind="email", project=self.project)
  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_sms_label(self):
  60. ch = Channel(kind="sms", user=self.alice, project=self.project)
  61. ch.value = json.dumps({"value": "+123", "label": "My Phone"})
  62. ch.save()
  63. self.client.login(username="[email protected]", password="password")
  64. r = self.client.get("/integrations/")
  65. self.assertEqual(r.status_code, 200)
  66. self.assertContains(r, "SMS to +123")