Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pole-Web
Website
Commits
888344f8
Verified
Commit
888344f8
authored
Nov 13, 2021
by
VAN ZUIJLEN Nils
Browse files
Add regression test for
#71
Signed-off-by:
Nils VAN ZUIJLEN
<
nils.van-zuijlen@mailo.com
>
parent
220d86d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
events/tests.py
View file @
888344f8
...
...
@@ -3,6 +3,7 @@ from datetime import timezone
from
freezegun
import
freeze_time
from
io
import
StringIO
import
uuid
from
zoneinfo
import
ZoneInfo
from
django.contrib.auth.models
import
User
from
django.core.management
import
call_command
from
django.templatetags.static
import
static
...
...
@@ -161,25 +162,54 @@ class TestEvent(TestCase):
self
.
event
.
save
()
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
self
.
event
.
save
()
re
=
RecurrentEvent
(
**
{
key
:
value
for
key
,
value
in
self
.
event
.
__dict__
.
items
()
if
key
not
in
(
'_state'
,
)})
re
.
save
()
class
TestRecurrentEvent
(
TestCase
):
@
freeze_time
(
"2021-11-13 18:00:00"
)
def
test_recurrent_events_dst_consistency
(
self
):
"""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
()
call_command
(
'create_recurrent_events'
,
stdout
=
out
)
last
=
None
for
event
in
Event
.
objects
.
filter
(
model
=
False
):
t
=
localtz
.
localize
(
event
.
start_time
.
replace
(
tzinfo
=
None
))
if
last
is
not
None
:
try
:
self
.
assertEqual
(
t
.
time
(),
last
.
time
())
except
AssertionError
:
print
(
t
,
last
)
raise
last
=
t
call_command
(
"create_recurrent_events"
,
stdout
=
out
)
local_start_time
=
re
.
start_time
.
astimezone
(
localtz
)
local_end_time
=
re
.
end_time
.
astimezone
(
localtz
)
local_end_inscriptions
=
re
.
end_inscriptions
.
astimezone
(
localtz
)
events
=
list
(
Event
.
objects
.
filter
(
model
=
False
))
for
event
in
events
:
with
self
.
subTest
(
event_start
=
event
.
start_time
):
self
.
assertEqual
(
local_start_time
.
hour
,
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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment