test_maintenance.py 885 B

123456789101112131415161718192021222324252627
  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 freezegun import freeze_time
  6. from model_bakery import baker
  7. from ..maintenance import cleanup_old_issues
  8. from ..models import Issue, IssueEvent
  9. class MaintenanceTestCase(TestCase):
  10. def test_cleanup_old_issues(self):
  11. events = baker.make(
  12. "issue_events.IssueEvent", _quantity=5, _fill_optional=["issue"]
  13. )
  14. baker.make("issue_events.IssueEvent", issue=events[0].issue, _quantity=5)
  15. cleanup_old_issues()
  16. self.assertEqual(Issue.objects.count(), 5)
  17. IssueEvent.objects.all().delete()
  18. with freeze_time(
  19. now() + timedelta(days=settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS)
  20. ):
  21. cleanup_old_issues()
  22. self.assertEqual(Issue.objects.count(), 0)