UPD: dav_registration: added tests.
This commit is contained in:
64
dav_registration/tests/test_utils.py
Normal file
64
dav_registration/tests/test_utils.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import datetime
|
||||
from django.test import TestCase
|
||||
|
||||
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):
|
||||
today = datetime.date.today()
|
||||
one_day = datetime.timedelta(1)
|
||||
purge_after_days = 7
|
||||
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',
|
||||
}
|
||||
|
||||
# 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:
|
||||
data = common_event_data.copy()
|
||||
data['first_day'] = first_day
|
||||
|
||||
event = self.create_event(data)
|
||||
self.submit_event(event)
|
||||
self.accept_event(event)
|
||||
|
||||
self.create_registration({'event': event})
|
||||
self.create_registration({'event': 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)
|
||||
Reference in New Issue
Block a user