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.

39 lines
1.2 KiB

  1. from datetime import timedelta
  2. from django.utils import timezone
  3. from hc.api.management.commands.sendalerts import Command
  4. from hc.api.models import Check
  5. from hc.test import BaseTestCase
  6. from mock import patch
  7. class SendAlertsTestCase(BaseTestCase):
  8. @patch("hc.api.management.commands.sendalerts.Command.handle_one")
  9. def test_it_handles_few(self, mock):
  10. yesterday = timezone.now() - timedelta(days=1)
  11. names = ["Check %d" % d for d in range(0, 10)]
  12. for name in names:
  13. check = Check(user=self.alice, name=name)
  14. check.alert_after = yesterday
  15. check.status = "up"
  16. check.save()
  17. result = Command().handle_many()
  18. assert result, "handle_many should return True"
  19. handled_names = []
  20. for args, kwargs in mock.call_args_list:
  21. handled_names.append(args[0].name)
  22. assert set(names) == set(handled_names)
  23. def test_it_handles_grace_period(self):
  24. check = Check(user=self.alice, status="up")
  25. # 1 day 30 minutes after ping the check is in grace period:
  26. check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
  27. check.save()
  28. # Expect no exceptions--
  29. Command().handle_one(check)