test_tasks.py 1.1 KB

1234567891011121314151617181920212223242526272829
  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, TransactionGroup, Span
  8. from ..tasks import cleanup_old_transaction_events
  9. class TasksTestCase(TestCase):
  10. def test_cleanup_old_events(self):
  11. group = baker.make("performance.TransactionGroup")
  12. transactions = baker.make(
  13. "performance.TransactionEvent", group=group, _quantity=5
  14. )
  15. baker.make("performance.Span", transaction=transactions[0])
  16. cleanup_old_transaction_events()
  17. self.assertEqual(TransactionGroup.objects.count(), 1)
  18. self.assertEqual(TransactionEvent.objects.count(), 5)
  19. self.assertEqual(Span.objects.count(), 1)
  20. with freeze_time(
  21. now() + timedelta(days=settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS)
  22. ):
  23. cleanup_old_transaction_events()
  24. self.assertEqual(TransactionGroup.objects.count(), 0)
  25. self.assertEqual(TransactionEvent.objects.count(), 0)
  26. self.assertEqual(Span.objects.count(), 0)