diff --git a/.travis.yml b/.travis.yml index da576b87..a01d93a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/hc/api/models.py b/hc/api/models.py index 71c39584..8dd38195 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -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() diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py new file mode 100644 index 00000000..8d5fd745 --- /dev/null +++ b/hc/api/tests/test_notify.py @@ -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")