|
|
@ -146,8 +146,13 @@ class NotifyTestCase(BaseTestCase): |
|
|
|
self.assertIsInstance(kwargs["data"], bytes) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_legacy_webhooks_handle_json_value(self, mock_request): |
|
|
|
definition = {"url_down": "http://foo.com", "post_data": "", "headers": {}} |
|
|
|
def test_webhooks_handle_json_value(self, mock_request): |
|
|
|
definition = { |
|
|
|
"method_down": "GET", |
|
|
|
"url_down": "http://foo.com", |
|
|
|
"body_down": "", |
|
|
|
"headers_down": {}, |
|
|
|
} |
|
|
|
self._setup_data("webhook", json.dumps(definition)) |
|
|
|
self.channel.notify(self.check) |
|
|
|
|
|
|
@ -156,23 +161,13 @@ class NotifyTestCase(BaseTestCase): |
|
|
|
"get", "http://foo.com", headers=headers, timeout=5 |
|
|
|
) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_legacy_webhooks_handle_json_up_event(self, mock_request): |
|
|
|
definition = {"url_up": "http://bar", "post_data": "", "headers": {}} |
|
|
|
|
|
|
|
self._setup_data("webhook", json.dumps(definition), status="up") |
|
|
|
self.channel.notify(self.check) |
|
|
|
|
|
|
|
headers = {"User-Agent": "healthchecks.io"} |
|
|
|
mock_request.assert_called_with("get", "http://bar", headers=headers, timeout=5) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_webhooks_handle_json_up_event(self, mock_request): |
|
|
|
definition = { |
|
|
|
"method_up": "GET", |
|
|
|
"url_up": "http://bar", |
|
|
|
"body_up": "", |
|
|
|
"headers_up": {} |
|
|
|
"headers_up": {}, |
|
|
|
} |
|
|
|
|
|
|
|
self._setup_data("webhook", json.dumps(definition), status="up") |
|
|
@ -181,22 +176,6 @@ class NotifyTestCase(BaseTestCase): |
|
|
|
headers = {"User-Agent": "healthchecks.io"} |
|
|
|
mock_request.assert_called_with("get", "http://bar", headers=headers, timeout=5) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_legacy_webhooks_handle_post_headers(self, mock_request): |
|
|
|
definition = { |
|
|
|
"url_down": "http://foo.com", |
|
|
|
"post_data": "data", |
|
|
|
"headers": {"Content-Type": "application/json"}, |
|
|
|
} |
|
|
|
|
|
|
|
self._setup_data("webhook", json.dumps(definition)) |
|
|
|
self.channel.notify(self.check) |
|
|
|
|
|
|
|
headers = {"User-Agent": "healthchecks.io", "Content-Type": "application/json"} |
|
|
|
mock_request.assert_called_with( |
|
|
|
"post", "http://foo.com", data=b"data", headers=headers, timeout=5 |
|
|
|
) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_webhooks_handle_post_headers(self, mock_request): |
|
|
|
definition = { |
|
|
@ -214,22 +193,6 @@ class NotifyTestCase(BaseTestCase): |
|
|
|
"post", "http://foo.com", data=b"data", headers=headers, timeout=5 |
|
|
|
) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_legacy_webhooks_handle_get_headers(self, mock_request): |
|
|
|
definition = { |
|
|
|
"url_down": "http://foo.com", |
|
|
|
"post_data": "", |
|
|
|
"headers": {"Content-Type": "application/json"}, |
|
|
|
} |
|
|
|
|
|
|
|
self._setup_data("webhook", json.dumps(definition)) |
|
|
|
self.channel.notify(self.check) |
|
|
|
|
|
|
|
headers = {"User-Agent": "healthchecks.io", "Content-Type": "application/json"} |
|
|
|
mock_request.assert_called_with( |
|
|
|
"get", "http://foo.com", headers=headers, timeout=5 |
|
|
|
) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_webhooks_handle_get_headers(self, mock_request): |
|
|
|
definition = { |
|
|
@ -247,22 +210,6 @@ class NotifyTestCase(BaseTestCase): |
|
|
|
"get", "http://foo.com", headers=headers, timeout=5 |
|
|
|
) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_legacy_webhooks_allow_user_agent_override(self, mock_request): |
|
|
|
definition = { |
|
|
|
"url_down": "http://foo.com", |
|
|
|
"post_data": "", |
|
|
|
"headers": {"User-Agent": "My-Agent"}, |
|
|
|
} |
|
|
|
|
|
|
|
self._setup_data("webhook", json.dumps(definition)) |
|
|
|
self.channel.notify(self.check) |
|
|
|
|
|
|
|
headers = {"User-Agent": "My-Agent"} |
|
|
|
mock_request.assert_called_with( |
|
|
|
"get", "http://foo.com", headers=headers, timeout=5 |
|
|
|
) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_webhooks_allow_user_agent_override(self, mock_request): |
|
|
|
definition = { |
|
|
|