Fix Pushover and HipChat.

This commit is contained in:
Pēteris Caune 2016-01-31 20:41:04 +02:00
parent 2c04a42a57
commit a71ce64579
3 changed files with 17 additions and 4 deletions

View File

@ -141,7 +141,7 @@ class Channel(models.Model):
elif self.kind == "pd":
return transports.PagerDuty(self)
elif self.kind == "po":
return transports.Pushover()
return transports.Pushover(self)
else:
raise NotImplementedError("Unknown channel kind: %s" % self.kind)

View File

@ -131,6 +131,19 @@ class NotifyTestCase(BaseTestCase):
@patch("hc.api.transports.requests.post")
def test_hipchat(self, mock_post):
self._setup_data("hipchat", "123")
mock_post.return_value.status_code = 204
self.channel.notify(self.check)
n = Notification.objects.first()
self.assertEqual(n.error, "")
args, kwargs = mock_post.call_args
json = kwargs["json"]
self.assertIn("DOWN", json["message"])
@patch("hc.api.transports.requests.post")
def test_pushover(self, mock_post):
self._setup_data("po", "123|0")
mock_post.return_value.status_code = 200
self.channel.notify(self.check)
@ -138,4 +151,4 @@ class NotifyTestCase(BaseTestCase):
args, kwargs = mock_post.call_args
json = kwargs["json"]
self.assertIn("DOWN", json["message"])
self.assertIn("DOWN", json["title"])

View File

@ -67,7 +67,7 @@ class Webhook(Transport):
headers = {"User-Agent": "healthchecks.io"}
try:
r = requests.get(self.channel.value, timeout=5, headers=headers)
if r.status_code not in (200, 201):
if r.status_code not in (200, 201, 204):
return "Received status code %d" % r.status_code
except requests.exceptions.Timeout:
# Well, we tried
@ -81,7 +81,7 @@ class JsonTransport(Transport):
headers = {"User-Agent": "healthchecks.io"}
try:
r = requests.post(url, json=payload, timeout=5, headers=headers)
if r.status_code not in (200, 201):
if r.status_code not in (200, 201, 204):
return "Received status code %d" % r.status_code
except requests.exceptions.Timeout:
# Well, we tried