diff --git a/hc/api/tests/test_notify_line.py b/hc/api/tests/test_notify_line.py new file mode 100644 index 00000000..f2f04e71 --- /dev/null +++ b/hc/api/tests/test_notify_line.py @@ -0,0 +1,38 @@ +# coding: utf-8 + +from datetime import timedelta as td +from unittest.mock import patch + +from django.utils.timezone import now +from hc.api.models import Channel, Check, Notification +from hc.test import BaseTestCase + + +class NotifyLineTestCase(BaseTestCase): + def setUp(self): + super().setUp() + + self.check = Check(project=self.project) + self.check.name = "Foo" + self.check.status = "down" + self.check.last_ping = now() - td(minutes=61) + self.check.save() + + self.channel = Channel(project=self.project) + self.channel.kind = "linenotify" + self.channel.value = "fake-token" + self.channel.save() + self.channel.checks.add(self.check) + + @patch("hc.api.transports.requests.request") + def test_it_works(self, mock_post): + mock_post.return_value.status_code = 200 + + self.channel.notify(self.check) + assert Notification.objects.count() == 1 + + args, kwargs = mock_post.call_args + headers = kwargs["headers"] + params = kwargs["params"] + self.assertEqual(headers["Authorization"], "Bearer fake-token") + self.assertIn("""The check "Foo" is DOWN""", params["message"]) diff --git a/hc/api/tests/test_notify_trello.py b/hc/api/tests/test_notify_trello.py new file mode 100644 index 00000000..1c12ebf0 --- /dev/null +++ b/hc/api/tests/test_notify_trello.py @@ -0,0 +1,48 @@ +from datetime import timedelta as td +import json +from unittest.mock import patch + +from django.utils.timezone import now +from django.test.utils import override_settings +from hc.api.models import Channel, Check, Notification +from hc.test import BaseTestCase + + +@override_settings(TRELLO_APP_KEY="fake-trello-app-key") +class NotifyTrelloTestCase(BaseTestCase): + def setUp(self): + super().setUp() + + self.check = Check(project=self.project) + self.check.name = "Foo" + self.check.status = "down" + self.check.last_ping = now() - td(minutes=61) + self.check.save() + + self.channel = Channel(project=self.project) + self.channel.kind = "trello" + self.channel.value = json.dumps( + { + "token": "fake-token", + "board_name": "My Board", + "list_name": "My List", + "list_id": "fake-list-id", + } + ) + self.channel.save() + self.channel.checks.add(self.check) + + @patch("hc.api.transports.requests.request") + def test_it_works(self, mock_post): + mock_post.return_value.status_code = 200 + + self.channel.notify(self.check) + assert Notification.objects.count() == 1 + + args, kwargs = mock_post.call_args + params = kwargs["params"] + self.assertEqual(params["idList"], "fake-list-id") + self.assertEqual(params["name"], "Down: Foo") + self.assertIn("Full Details", params["desc"]) + self.assertEqual(params["key"], "fake-trello-app-key") + self.assertEqual(params["token"], "fake-token") diff --git a/templates/accounts/success.html b/templates/accounts/success.html deleted file mode 100644 index 07cb3c4c..00000000 --- a/templates/accounts/success.html +++ /dev/null @@ -1,5 +0,0 @@ -{% extends "base.html" %} - -{% block content %} -

Success

-{% endblock %} \ No newline at end of file