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.

49 lines
1.4 KiB

  1. from datetime import timedelta as td
  2. from django.utils.timezone import now
  3. from hc.api.management.commands.sendreports import Command
  4. from hc.api.models import Check
  5. from hc.test import BaseTestCase
  6. class SendAlertsTestCase(BaseTestCase):
  7. def setUp(self):
  8. super(SendAlertsTestCase, self).setUp()
  9. # Make alice eligible for reports:
  10. # account needs to be more than one month old
  11. self.alice.date_joined = now() - td(days=365)
  12. self.alice.save()
  13. # And it needs at least one check that has been pinged.
  14. self.check = Check(user=self.alice, last_ping=now())
  15. self.check.save()
  16. def test_it_sends_report(self):
  17. sent = Command().handle_one_run()
  18. self.assertEqual(sent, 1)
  19. # Alice's profile should have been updated
  20. self.profile.refresh_from_db()
  21. self.assertTrue(self.profile.next_report_date > now())
  22. def test_it_obeys_next_report_date(self):
  23. self.profile.next_report_date = now() + td(days=1)
  24. self.profile.save()
  25. sent = Command().handle_one_run()
  26. self.assertEqual(sent, 0)
  27. def test_it_obeys_reports_allowed_flag(self):
  28. self.profile.reports_allowed = False
  29. self.profile.save()
  30. sent = Command().handle_one_run()
  31. self.assertEqual(sent, 0)
  32. def test_it_requires_pinged_checks(self):
  33. self.check.delete()
  34. sent = Command().handle_one_run()
  35. self.assertEqual(sent, 0)