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.

62 lines
2.0 KiB

6 years ago
  1. import json
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. class ChannelModelTestCase(BaseTestCase):
  5. def test_webhook_spec_handles_mixed(self):
  6. c = Channel(kind="webhook")
  7. c.value = json.dumps(
  8. {
  9. "method_down": "GET",
  10. "url_down": "http://example.org",
  11. "body_down": "",
  12. "headers_down": {"X-Status": "X"},
  13. "method_up": "POST",
  14. "url_up": "http://example.org/up/",
  15. "body_up": "hello world",
  16. "headers_up": {"X-Status": "OK"},
  17. }
  18. )
  19. self.assertEqual(
  20. c.down_webhook_spec,
  21. {
  22. "method": "GET",
  23. "url": "http://example.org",
  24. "body": "",
  25. "headers": {"X-Status": "X"},
  26. },
  27. )
  28. self.assertEqual(
  29. c.up_webhook_spec,
  30. {
  31. "method": "POST",
  32. "url": "http://example.org/up/",
  33. "body": "hello world",
  34. "headers": {"X-Status": "OK"},
  35. },
  36. )
  37. def test_it_handles_legacy_opsgenie_value(self):
  38. c = Channel(kind="opsgenie", value="foo123")
  39. self.assertEqual(c.opsgenie_key, "foo123")
  40. self.assertEqual(c.opsgenie_region, "us")
  41. def test_it_handles_json_opsgenie_value(self):
  42. c = Channel(kind="opsgenie")
  43. c.value = json.dumps({"key": "abc", "region": "eu"})
  44. self.assertEqual(c.opsgenie_key, "abc")
  45. self.assertEqual(c.opsgenie_region, "eu")
  46. def test_it_handles_legacy_sms_value(self):
  47. c = Channel(kind="sms", value="+123123123")
  48. self.assertTrue(c.sms_notify_down)
  49. self.assertFalse(c.sms_notify_up)
  50. def test_it_handles_legacy_sms_json_value(self):
  51. c = Channel(kind="sms", value=json.dumps({"value": "+123123123"}))
  52. self.assertTrue(c.sms_notify_down)
  53. self.assertFalse(c.sms_notify_up)