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
930 B

  1. from datetime import timedelta
  2. from django.utils import timezone
  3. from mock import patch
  4. from hc.api.management.commands.sendalerts import Command
  5. from hc.api.models import Check
  6. from hc.test import BaseTestCase
  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)