Fix bug with pinging webhook

This commit is contained in:
Pēteris Caune 2015-08-14 12:37:02 +03:00
parent 058101b941
commit 7240ce9ba8
3 changed files with 26 additions and 2 deletions

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

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()

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")