59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
import datetime
|
|
from django.test import TestCase
|
|
from django.utils import timezone
|
|
|
|
from dav_events.tests.generic import EventMixin
|
|
|
|
from ..models import Registration
|
|
from ..utils import purge_registrations
|
|
|
|
from .generic import RegistrationMixin
|
|
|
|
|
|
class UtilsTestCase(RegistrationMixin, EventMixin, TestCase):
|
|
def test_purge(self):
|
|
now = timezone.now()
|
|
today = now.date()
|
|
one_day = datetime.timedelta(1)
|
|
registrations_per_event = 1
|
|
common_event_data = {
|
|
'title': 'Daytrip',
|
|
'description': 'Test',
|
|
'mode': 'joint',
|
|
'sport': 'W',
|
|
'level': 'beginner',
|
|
'country': 'DE',
|
|
'trainer_firstname': 'Trainer',
|
|
'trainer_familyname': 'One',
|
|
'trainer_email': 'trainer@localhost',
|
|
}
|
|
|
|
first_day = today - (one_day * 367)
|
|
while first_day < today:
|
|
first_day += one_day
|
|
data = common_event_data.copy()
|
|
data['first_day'] = first_day
|
|
|
|
event = self.create_event_by_model(data)
|
|
self.submit_event(event)
|
|
self.accept_event(event)
|
|
|
|
for i in range(0, registrations_per_event):
|
|
self.create_registration({'event': event})
|
|
|
|
purge_registrations()
|
|
|
|
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)
|