Verified Commit 888344f8 authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Add regression test for #71



Signed-off-by: VAN ZUIJLEN Nils's avatarNils VAN ZUIJLEN <nils.van-zuijlen@mailo.com>
parent 220d86d2
...@@ -3,6 +3,7 @@ from datetime import timezone ...@@ -3,6 +3,7 @@ from datetime import timezone
from freezegun import freeze_time from freezegun import freeze_time
from io import StringIO from io import StringIO
import uuid import uuid
from zoneinfo import ZoneInfo
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management import call_command from django.core.management import call_command
from django.templatetags.static import static from django.templatetags.static import static
...@@ -161,25 +162,54 @@ class TestEvent(TestCase): ...@@ -161,25 +162,54 @@ class TestEvent(TestCase):
self.event.save() self.event.save()
self.assertFalse(self.event.can_invite(u)) self.assertFalse(self.event.can_invite(u))
def test_recurrent_events_creation(self):
from pytz import timezone
localtz = timezone('Europe/Paris')
self.event.model = True class TestRecurrentEvent(TestCase):
self.event.save() @freeze_time("2021-11-13 18:00:00")
re = RecurrentEvent(**{key: value for key, value in self.event.__dict__.items() if key not in ('_state', )}) def test_recurrent_events_dst_consistency(self):
re.save() """Test that scheduled recurrent events are at the same local time, even with DST changes
First post-DST generated event is on 2021-11-05
"""
localtz = ZoneInfo("Europe/Paris")
re = RecurrentEvent.objects.create(
name="test",
start_time=datetime.datetime(2021, 10, 8, 11, 45, tzinfo=localtz),
end_time=datetime.datetime(2021, 10, 8, 14, 20, tzinfo=localtz),
end_inscriptions=datetime.datetime(2021, 10, 8, 11, 15, tzinfo=localtz),
location="location",
description="description",
delay=7,
model=True
)
re.refresh_from_db() # get UTC datetimes, as provided by default by the db
out = StringIO() out = StringIO()
call_command('create_recurrent_events', stdout=out) call_command("create_recurrent_events", stdout=out)
last = None local_start_time = re.start_time.astimezone(localtz)
for event in Event.objects.filter(model=False): local_end_time = re.end_time.astimezone(localtz)
t = localtz.localize(event.start_time.replace(tzinfo=None)) local_end_inscriptions = re.end_inscriptions.astimezone(localtz)
if last is not None:
try: events = list(Event.objects.filter(model=False))
self.assertEqual(t.time(), last.time()) for event in events:
except AssertionError: with self.subTest(event_start=event.start_time):
print(t, last) self.assertEqual(
raise local_start_time.hour,
last = t event.start_time.astimezone(localtz).hour,
"start_time",
)
self.assertEqual(
local_end_time.hour,
event.end_time.astimezone(localtz).hour,
"end_time",
)
self.assertEqual(
local_end_inscriptions.hour,
event.end_inscriptions.astimezone(localtz).hour,
"end_inscriptions",
)
for prev, curr in zip(events, events[1:]):
delta = curr.start_time - prev.start_time
self.assertEqual(delta.days, re.delay)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment