Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add tests showing issues with timezone handling for all-day events, re
Browse files Browse the repository at this point in the history
…#4

Add unit tests that demonstrate we cannot sort occurrences with all-day
ones first as we wish, and that the overlapping filter does not return
all-day events when they are created with start/end datestimes in
timezones other than the system timezone.
  • Loading branch information
jmurty committed Nov 1, 2016
1 parent 7a62286 commit 8afe594
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions icekit_events/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,136 @@ def test_same_day_occurrences(self):
)


class Timezones(TestCase):

def setUp(self):
# Occurrences based on Pacific timezone
self.occurrence_pacific_timed = G(
models.Occurrence,
event=G(SimpleEvent, title='Los Angeles Timed'),
start=djtz.datetime(2016, 10, 1, 9, 0, tzinfo='US/Pacific'),
end=djtz.datetime(2016, 10, 1, 13, 0, tzinfo='US/Pacific'),
)
self.occurrence_pacific_all_day = G(
models.Occurrence,
event=G(SimpleEvent, title='Los Angeles All-day'),
start=djtz.datetime(2016, 10, 1, 0, 0, tzinfo='US/Pacific'),
end=djtz.datetime(2016, 10, 1, 0, 0, tzinfo='US/Pacific'),
is_all_day=True,
)
# Occurrences based on UTC timezone
self.occurrence_utc_timed = G(
models.Occurrence,
event=G(SimpleEvent, title='UTC Timed'),
start=djtz.datetime(2016, 10, 1, 9, 0, tzinfo='UTC'),
end=djtz.datetime(2016, 10, 1, 13, 0, tzinfo='UTC'),
)
self.occurrence_utc_all_day = G(
models.Occurrence,
event=G(SimpleEvent, title='UTC All-day'),
start=djtz.datetime(2016, 10, 1, 0, 0, tzinfo='UTC'),
end=djtz.datetime(2016, 10, 1, 0, 0, tzinfo='UTC'),
is_all_day=True,
)
# Occurrences based on UK timezone
self.occurrence_uk_timed = G(
models.Occurrence,
event=G(SimpleEvent, title='London Timed'),
start=djtz.datetime(2016, 10, 1, 9, 0, tzinfo='Europe/London'),
end=djtz.datetime(2016, 10, 1, 13, 0, tzinfo='Europe/London'),
)
self.occurrence_uk_all_day = G(
models.Occurrence,
event=G(SimpleEvent, title='London All-day'),
start=djtz.datetime(2016, 10, 1, 0, 0, tzinfo='Europe/London'),
end=djtz.datetime(2016, 10, 1, 0, 0, tzinfo='Europe/London'),
is_all_day=True,
)
# Occurrences based on Australian Eastern timezone
self.occurrence_aest_timed = G(
models.Occurrence,
event=G(SimpleEvent, title='Sydney Timed'),
start=djtz.datetime(2016, 10, 1, 9, 0, tzinfo='Australia/Sydney'),
end=djtz.datetime(2016, 10, 1, 13, 0, tzinfo='Australia/Sydney'),
)
self.occurrence_aest_all_day = G(
models.Occurrence,
event=G(SimpleEvent, title='Sydney All-day'),
start=djtz.datetime(2016, 10, 1, 0, 0, tzinfo='Australia/Sydney'),
end=djtz.datetime(2016, 10, 1, 0, 0, tzinfo='Australia/Sydney'),
is_all_day=True,
)

def test_occurrence_default_ordering(self):
ordered_titles = [
o.event.title for o in models.Occurrence.objects.all()]
self.assertEqual(
# All-day occurrences are ordered first, by date then title
[u'London All-day',
u'Los Angeles All-day',
u'Sydney All-day',
u'UTC All-day',
# Timed occurrences are ordered after all-day occurrences, by
# datetime accounting for timezone
u'Los Angeles Timed',
u'UTC Timed',
u'London Timed',
u'Sydney Timed',
],
ordered_titles
)

def test_overlapping_filter(self):
self.assertEqual(
# All-day occurrences are included in overlapping result for date
[u'London All-day',
u'Los Angeles All-day',
u'Sydney All-day',
u'UTC All-day',
# Timed occurrences are included in overlapping result only when
# their start & end times overlap
u'Los Angeles Timed',
],
[o.event.title for o in models.Occurrence.objects.overlapping(
djtz.datetime(2016, 10, 1, 10, 0, tzinfo='US/Pacific'),
djtz.datetime(2016, 10, 1, 11, 0, tzinfo='US/Pacific'),
)]
)

self.assertEqual(
# All-day occurrences are included in overlapping result for date
[u'London All-day',
u'Los Angeles All-day',
u'Sydney All-day',
u'UTC All-day',
# Timed occurrences are included in overlapping result only when
# their start & end times overlap
u'Los Angeles Timed',
u'UTC Timed',
u'London Timed',
],
[o.event.title for o in models.Occurrence.objects.overlapping(
djtz.datetime(2016, 10, 1, 12, 59, tzinfo='US/Pacific'),
djtz.datetime(2016, 10, 1, 9, 1, tzinfo='Europe/London'),
)]
)

self.assertEqual(
# All-day occurrences are included in overlapping result for date
[u'London All-day',
u'Los Angeles All-day',
u'Sydney All-day',
u'UTC All-day',
# Timed occurrences are included in overlapping result only when
# their start & end times overlap
u'London Timed',
u'Sydney Timed',
],
[o.event.title for o in models.Occurrence.objects.overlapping(
djtz.datetime(2016, 10, 1, 13, 0, tzinfo='Europe/London'),
djtz.datetime(2016, 10, 1, 9, 0, tzinfo='Australia/Sydney'),
)]
)


class Time(TestCase):
Expand Down

0 comments on commit 8afe594

Please sign in to comment.