test_tasks.py 879 B

1234567891011121314151617181920212223242526
  1. from datetime import timedelta
  2. from unittest import mock
  3. from django.conf import settings
  4. from django.utils.timezone import now
  5. from freezegun import freeze_time
  6. from model_bakery import baker
  7. from glitchtip.test_utils.test_case import GlitchTipTestCase
  8. from ..models import MonitorCheck
  9. from ..tasks import cleanup_old_monitor_checks
  10. class TasksTestCase(GlitchTipTestCase):
  11. @mock.patch("glitchtip.uptime.tasks.perform_checks.run")
  12. def test_cleanup_old_monitor_checks(self, _):
  13. baker.make(MonitorCheck, monitor__url="http://example.com", _quantity=2)
  14. cleanup_old_monitor_checks()
  15. self.assertEqual(MonitorCheck.objects.count(), 2)
  16. with freeze_time(
  17. now() + timedelta(days=settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS)
  18. ):
  19. cleanup_old_monitor_checks()
  20. self.assertEqual(MonitorCheck.objects.count(), 0)