UPD: change grace period for purging registration and participant data.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import datetime
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from dav_events.tests.generic import EventMixin
|
||||
|
||||
@@ -13,9 +14,10 @@ from .generic import RegistrationMixin
|
||||
|
||||
class UtilsTestCase(RegistrationMixin, EventMixin, TestCase):
|
||||
def test_purge(self):
|
||||
today = datetime.date.today()
|
||||
now = timezone.now()
|
||||
today = now.date()
|
||||
one_day = datetime.timedelta(1)
|
||||
purge_after_days = 7
|
||||
registrations_per_event = 1
|
||||
common_event_data = {
|
||||
'title': 'Daytrip',
|
||||
'description': 'Test',
|
||||
@@ -28,21 +30,9 @@ class UtilsTestCase(RegistrationMixin, EventMixin, TestCase):
|
||||
'trainer_email': 'trainer@localhost',
|
||||
}
|
||||
|
||||
# We will create 4 events with different dates in the past
|
||||
# 1. an event, that is happening right now -> we would still need the participants data
|
||||
# 2. an event that will be finished few days ago, but the grace period were we have to keep
|
||||
# the participants data is not over right now -> do not purge registrations
|
||||
# 3. an event that will be finished long enough, so that we can purge the registrations
|
||||
# 4. event will be finished even longer ago
|
||||
# To all events, we will create some registrations
|
||||
event_data = (
|
||||
(True, today),
|
||||
(True, today - one_day * (purge_after_days - 1)),
|
||||
(False, today - one_day * purge_after_days),
|
||||
(False, today - one_day * (purge_after_days + 1)),
|
||||
)
|
||||
events = []
|
||||
for registrations_still_needed, first_day in event_data:
|
||||
first_day = today - (one_day * 367)
|
||||
while first_day < today:
|
||||
first_day += one_day
|
||||
data = common_event_data.copy()
|
||||
data['first_day'] = first_day
|
||||
|
||||
@@ -50,15 +40,19 @@ class UtilsTestCase(RegistrationMixin, EventMixin, TestCase):
|
||||
self.submit_event(event)
|
||||
self.accept_event(event)
|
||||
|
||||
self.create_registration({'event': event})
|
||||
self.create_registration({'event': event})
|
||||
self.create_registration({'event': event})
|
||||
for i in range(0, registrations_per_event):
|
||||
self.create_registration({'event': event})
|
||||
|
||||
events.append((event, registrations_still_needed))
|
||||
|
||||
# Now we purge obsolete registrations
|
||||
purge_registrations()
|
||||
|
||||
# Now we test for all 4 events, if there are still registrations
|
||||
for event, registrations_still_needed in events:
|
||||
self.assertEqual(Registration.objects.filter(event=event).exists(), registrations_still_needed)
|
||||
registrations = Registration.objects.all()
|
||||
n_registrations = registrations.count()
|
||||
# We keep registrations at min three months (min 90 days)
|
||||
# So there should be at least the registrations of the events in the last 90 days left.
|
||||
self.assertGreater(n_registrations, registrations_per_event * 90)
|
||||
# We keep registrations at max nine months (max 276 days)
|
||||
# So there should be no more registrations left, than of the events from the last 276 days.
|
||||
self.assertGreater(registrations_per_event * 276, n_registrations)
|
||||
|
||||
for registration in registrations:
|
||||
self.assertGreater(registration.purge_at, now)
|
||||
|
||||
Reference in New Issue
Block a user