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.

31 lines
1.0 KiB

  1. # coding: utf-8
  2. from datetime import timedelta as td
  3. from django.utils.timezone import now
  4. from hc.api.models import Channel, Check, Notification
  5. from hc.test import BaseTestCase
  6. from django.test.utils import override_settings
  7. class NotifyTestCase(BaseTestCase):
  8. def _setup_data(self, value, status="down", email_verified=True):
  9. self.check = Check(project=self.project)
  10. self.check.status = status
  11. self.check.last_ping = now() - td(minutes=61)
  12. self.check.save()
  13. self.channel = Channel(project=self.project)
  14. self.channel.kind = "mattermost"
  15. self.channel.value = value
  16. self.channel.email_verified = email_verified
  17. self.channel.save()
  18. self.channel.checks.add(self.check)
  19. @override_settings(MATTERMOST_ENABLED=False)
  20. def test_it_requires_mattermost_enabled(self):
  21. self._setup_data("123")
  22. self.channel.notify(self.check)
  23. n = Notification.objects.get()
  24. self.assertEqual(n.error, "Mattermost notifications are not enabled.")