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.

52 lines
1.6 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")