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.

32 lines
946 B

  1. from datetime import datetime
  2. from django.contrib.auth.models import User
  3. from django.test import TestCase
  4. from hc.api.management.commands.sendalerts import Command
  5. from hc.api.models import Check
  6. from mock import patch
  7. class SendAlertsTestCase(TestCase):
  8. @patch("hc.api.management.commands.sendalerts.Command.handle_one")
  9. def test_it_handles_few(self, mock):
  10. alice = User(username="alice")
  11. alice.save()
  12. names = ["Check %d" % d for d in range(0, 10)]
  13. for name in names:
  14. check = Check(user=alice, name=name)
  15. check.alert_after = datetime(2000, 1, 1)
  16. check.status = "up"
  17. check.save()
  18. result = Command().handle_many()
  19. assert result, "handle_many should return True"
  20. handled_names = []
  21. for args, kwargs in mock.call_args_list:
  22. handled_names.append(args[0].name)
  23. assert set(names) == set(handled_names)