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.

48 lines
1.6 KiB

  1. from datetime import timedelta as td
  2. import json
  3. from unittest.mock import patch
  4. from django.utils.timezone import now
  5. from django.test.utils import override_settings
  6. from hc.api.models import Channel, Check, Notification
  7. from hc.test import BaseTestCase
  8. @override_settings(TRELLO_APP_KEY="fake-trello-app-key")
  9. class NotifyTrelloTestCase(BaseTestCase):
  10. def setUp(self):
  11. super().setUp()
  12. self.check = Check(project=self.project)
  13. self.check.name = "Foo"
  14. self.check.status = "down"
  15. self.check.last_ping = now() - td(minutes=61)
  16. self.check.save()
  17. self.channel = Channel(project=self.project)
  18. self.channel.kind = "trello"
  19. self.channel.value = json.dumps(
  20. {
  21. "token": "fake-token",
  22. "board_name": "My Board",
  23. "list_name": "My List",
  24. "list_id": "fake-list-id",
  25. }
  26. )
  27. self.channel.save()
  28. self.channel.checks.add(self.check)
  29. @patch("hc.api.transports.requests.request")
  30. def test_it_works(self, mock_post):
  31. mock_post.return_value.status_code = 200
  32. self.channel.notify(self.check)
  33. assert Notification.objects.count() == 1
  34. args, kwargs = mock_post.call_args
  35. params = kwargs["params"]
  36. self.assertEqual(params["idList"], "fake-list-id")
  37. self.assertEqual(params["name"], "Down: Foo")
  38. self.assertIn("Full Details", params["desc"])
  39. self.assertEqual(params["key"], "fake-trello-app-key")
  40. self.assertEqual(params["token"], "fake-token")