test_tasks.py 748 B

123456789101112131415161718192021
  1. from datetime import timedelta
  2. from django.conf import settings
  3. from django.test import TestCase
  4. from django.utils.timezone import now
  5. from model_bakery import baker
  6. from freezegun import freeze_time
  7. from ..models import TransactionEvent
  8. from ..tasks import cleanup_old_transaction_events
  9. class TasksTestCase(TestCase):
  10. def test_cleanup_old_events(self):
  11. baker.make("performance.TransactionEvent", _quantity=5)
  12. cleanup_old_transaction_events()
  13. self.assertEqual(TransactionEvent.objects.count(), 5)
  14. with freeze_time(
  15. now() + timedelta(days=settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS)
  16. ):
  17. cleanup_old_transaction_events()
  18. self.assertEqual(TransactionEvent.objects.count(), 0)