Browse Source

Fix bug with pinging webhook

pull/7/head
Pēteris Caune 9 years ago
parent
commit
7240ce9ba8
3 changed files with 26 additions and 2 deletions
  1. +1
    -1
      .travis.yml
  2. +1
    -1
      hc/api/models.py
  3. +24
    -0
      hc/api/tests/test_notify.py

+ 1
- 1
.travis.yml View File

@ -4,7 +4,7 @@ python:
- "3.4"
install:
- pip install -r requirements.txt
- pip install coveralls mysqlclient
- pip install coveralls mock mysqlclient
env:
- DB=sqlite
- DB=mysql


+ 1
- 1
hc/api/models.py View File

@ -117,7 +117,7 @@ class Channel(models.Model):
}
emails.alert(self.value, ctx)
n.save()
elif self.kind == "webhook" and self.status == "down":
elif self.kind == "webhook" and check.status == "down":
r = requests.get(self.value)
n.status = r.status_code
n.save()


+ 24
- 0
hc/api/tests/test_notify.py View File

@ -0,0 +1,24 @@
from django.contrib.auth.models import User
from django.test import TestCase
from mock import patch
from hc.api.models import Channel, Check
class NotifyTestCase(TestCase):
@patch("hc.api.models.requests")
def test_webhook(self, mock_requests):
alice = User(username="alice")
alice.save()
check = Check()
check.status = "down"
check.save()
channel = Channel(user=alice, kind="webhook", value="http://example")
channel.save()
channel.checks.add(check)
channel.notify(check)
mock_requests.get.assert_called_with(u"http://example")

Loading…
Cancel
Save