You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

  1. # coding: utf-8
  2. from datetime import timedelta as td
  3. from unittest.mock import patch
  4. from django.utils.timezone import now
  5. from hc.api.models import Channel, Check, Notification
  6. from hc.test import BaseTestCase
  7. class NotifyLineTestCase(BaseTestCase):
  8. def setUp(self):
  9. super().setUp()
  10. self.check = Check(project=self.project)
  11. self.check.name = "Foo"
  12. self.check.status = "down"
  13. self.check.last_ping = now() - td(minutes=61)
  14. self.check.save()
  15. self.channel = Channel(project=self.project)
  16. self.channel.kind = "linenotify"
  17. self.channel.value = "fake-token"
  18. self.channel.save()
  19. self.channel.checks.add(self.check)
  20. @patch("hc.api.transports.requests.request")
  21. def test_it_works(self, mock_post):
  22. mock_post.return_value.status_code = 200
  23. self.channel.notify(self.check)
  24. assert Notification.objects.count() == 1
  25. args, kwargs = mock_post.call_args
  26. headers = kwargs["headers"]
  27. params = kwargs["params"]
  28. self.assertEqual(headers["Authorization"], "Bearer fake-token")
  29. self.assertIn("""The check "Foo" is DOWN""", params["message"])