|
|
@ -534,67 +534,3 @@ class NotifyTestCase(BaseTestCase): |
|
|
|
|
|
|
|
self.channel.notify(self.check) |
|
|
|
self.assertTrue(mock_post.called) |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
def test_zendesk_down(self, mock_post): |
|
|
|
v = json.dumps({"access_token": "fake-token", "subdomain": "foo"}) |
|
|
|
self._setup_data("zendesk", v) |
|
|
|
mock_post.return_value.status_code = 200 |
|
|
|
|
|
|
|
self.channel.notify(self.check) |
|
|
|
assert Notification.objects.count() == 1 |
|
|
|
|
|
|
|
args, kwargs = mock_post.call_args |
|
|
|
method, url = args |
|
|
|
self.assertEqual(method, "post") |
|
|
|
self.assertTrue("foo.zendesk.com" in url) |
|
|
|
|
|
|
|
payload = kwargs["json"] |
|
|
|
self.assertEqual(payload["request"]["type"], "incident") |
|
|
|
self.assertTrue("down" in payload["request"]["subject"]) |
|
|
|
|
|
|
|
headers = kwargs["headers"] |
|
|
|
self.assertEqual(headers["Authorization"], "Bearer fake-token") |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
@patch("hc.api.transports.requests.get") |
|
|
|
def test_zendesk_up(self, mock_get, mock_post): |
|
|
|
v = json.dumps({"access_token": "fake-token", "subdomain": "foo"}) |
|
|
|
self._setup_data("zendesk", v, status="up") |
|
|
|
|
|
|
|
mock_post.return_value.status_code = 200 |
|
|
|
mock_get.return_value.status_code = 200 |
|
|
|
mock_get.return_value.json.return_value = { |
|
|
|
"requests": [{ |
|
|
|
"url": "https://foo.example.org/comment", |
|
|
|
"description": "code is %s" % self.check.code |
|
|
|
}] |
|
|
|
} |
|
|
|
|
|
|
|
self.channel.notify(self.check) |
|
|
|
assert Notification.objects.count() == 1 |
|
|
|
|
|
|
|
args, kwargs = mock_post.call_args |
|
|
|
self.assertTrue("foo.example.org" in args[1]) |
|
|
|
|
|
|
|
payload = kwargs["json"] |
|
|
|
self.assertEqual(payload["request"]["type"], "incident") |
|
|
|
self.assertTrue("UP" in payload["request"]["subject"]) |
|
|
|
|
|
|
|
headers = kwargs["headers"] |
|
|
|
self.assertEqual(headers["Authorization"], "Bearer fake-token") |
|
|
|
|
|
|
|
@patch("hc.api.transports.requests.request") |
|
|
|
@patch("hc.api.transports.requests.get") |
|
|
|
def test_zendesk_up_with_no_existing_ticket(self, mock_get, mock_post): |
|
|
|
v = json.dumps({"access_token": "fake-token", "subdomain": "foo"}) |
|
|
|
self._setup_data("zendesk", v, status="up") |
|
|
|
|
|
|
|
mock_get.return_value.status_code = 200 |
|
|
|
mock_get.return_value.json.return_value = {"requests": []} |
|
|
|
|
|
|
|
self.channel.notify(self.check) |
|
|
|
n = Notification.objects.get() |
|
|
|
self.assertEqual(n.error, "Could not find a ticket to update") |
|
|
|
|
|
|
|
self.assertFalse(mock_post.called) |