Files
django-dav-events/dav_registration/tests/test_utils.py
heinzel 63026e429b
All checks were successful
buildbot/tox Build done.
Fix #9 Registrations: Add support for non members
2020-10-15 17:44:12 +02:00

71 lines
2.4 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',
}
registration_data = {
'personal_names': 'Participant',
'family_names': 'P.',
'address': 'Am Fächerbad 2',
'postal_code': '76131',
'city': 'Karlsruhe',
'phone_number': '555 5555',
'email_address': 'participant@localhost',
'dav_number': '1',
}
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):
d = registration_data
d['event'] = event
self.create_registration(d)
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)