Browse Source

Fix Pushover and HipChat.

pull/40/head
Pēteris Caune 9 years ago
parent
commit
a71ce64579
3 changed files with 17 additions and 4 deletions
  1. +1
    -1
      hc/api/models.py
  2. +14
    -1
      hc/api/tests/test_notify.py
  3. +2
    -2
      hc/api/transports.py

+ 1
- 1
hc/api/models.py 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)


+ 14
- 1
hc/api/tests/test_notify.py 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"])

+ 2
- 2
hc/api/transports.py 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


Loading…
Cancel
Save