feat() adds tests for default tz on all day events

pull/79/head
Martin Eigenmann 2021-03-28 12:47:01 +02:00
rodzic 7720a49dac
commit d06beb8c66
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 069D1EE3806CA368
4 zmienionych plików z 86 dodań i 6 usunięć

Wyświetl plik

@ -270,7 +270,7 @@ def parse_events(content, start=None, end=None, default_span=timedelta(days=7)):
# Keep track of the timezones defined in the calendar # Keep track of the timezones defined in the calendar
timezones = {} timezones = {}
if 'X-WR-TIMEZONE' in calendar: if 'X-WR-TIMEZONE' in calendar:
timezones[str(calendar['X-WR-TIMEZONE'])] = str(calendar['X-WR-TIMEZONE']) timezones[str(calendar['X-WR-TIMEZONE'])] = gettz(str(calendar['X-WR-TIMEZONE']))
for c in calendar.walk('VTIMEZONE'): for c in calendar.walk('VTIMEZONE'):
name = str(c['TZID']) name = str(c['TZID'])
@ -287,7 +287,7 @@ def parse_events(content, start=None, end=None, default_span=timedelta(days=7)):
# assume it applies globally, otherwise UTC # assume it applies globally, otherwise UTC
if len(timezones) == 1: if len(timezones) == 1:
cal_tz = gettz(list(timezones)[0]) cal_tz = gettz(list(timezones)[0])
if not cal_tz and timezone in WINDOWS_TO_OLSON: if not cal_tz and str(c['TZID']) in WINDOWS_TO_OLSON:
cal_tz = gettz(WINDOWS_TO_OLSON[str(c['TZID'])]) cal_tz = gettz(WINDOWS_TO_OLSON[str(c['TZID'])])
else: else:
cal_tz = UTC cal_tz = UTC
@ -320,8 +320,7 @@ def parse_events(content, start=None, end=None, default_span=timedelta(days=7)):
# use it; otherwise, attempt to load the rules from pytz. # use it; otherwise, attempt to load the rules from pytz.
start_tz = None start_tz = None
end_tz = None end_tz = None
if e.all_day and e.recurring:
if e.all_day:
# Start and end times for all day events must not have # Start and end times for all day events must not have
# a timezone because the specification forbids the # a timezone because the specification forbids the
# RRULE UNTIL from having a timezone. On the other # RRULE UNTIL from having a timezone. On the other

Wyświetl plik

@ -0,0 +1,17 @@
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:test
X-WR-TIMEZONE:Europe/Zurich
BEGIN:VEVENT
DTSTART;VALUE=DATE:20210324
DTEND;VALUE=DATE:20210327
DTSTAMP:20210328T094322Z
UID:1gn1mvk5325euprb9fcf7ndpdn@google.com
ATTENDEE;X-NUM-GUESTS=0:mailto:hst9ma4s2h5hf2iafmrqffki9o@group.calendar.go
ogle.com
SUMMARY:Busy
END:VEVENT
END:VCALENDAR

Wyświetl plik

@ -0,0 +1,42 @@
BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:Microsoft Exchange Server 2010
VERSION:2.0
X-WR-CALNAME:test
BEGIN:VTIMEZONE
TZID:W. Europe Standard Time
BEGIN:STANDARD
DTSTART:16010101T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
UID:040000008200E00074C5B7101A82E0080000000007E56CFC7E1DD701000000000000000
01000000068B41E0ADF04374687B1104CB913D622
SUMMARY:Busy
DTSTART;VALUE=DATE:20210324
DTEND;VALUE=DATE:20210327
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20210328T104140Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:0
X-MICROSOFT-DONOTFORWARDMEETING:FALSE
X-MICROSOFT-DISALLOW-COUNTER:FALSE
END:VEVENT
END:VCALENDAR

Wyświetl plik

@ -3,7 +3,7 @@ from icalevents import icalevents
from datetime import date, timedelta, datetime from datetime import date, timedelta, datetime
from time import sleep from time import sleep
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from dateutil.tz import UTC from dateutil.tz import UTC, gettz
from re import search from re import search
@ -260,3 +260,25 @@ class ICalEventsTests(unittest.TestCase):
events = icalevents.events(url=None, file=ical, start=start, end=end) events = icalevents.events(url=None, file=ical, start=start, end=end)
self.assertEqual(events[0].categories, ["In19-S04-IT2403"], "event 1 is not equal") self.assertEqual(events[0].categories, ["In19-S04-IT2403"], "event 1 is not equal")
self.assertEqual(events[1].categories, ["In19-S04-IT2406", "In19-S04-IT2405"], "event 2 is not equal") self.assertEqual(events[1].categories, ["In19-S04-IT2406", "In19-S04-IT2405"], "event 2 is not equal")
def test_google_timezone(self):
ical = "test/test_data/google_tz.ics"
start = date(2021, 1, 1)
end = date(2021, 12, 31)
evs = icalevents.events(file=ical, start=start, end=end)
e1 = evs[0]
self.assertEqual(e1.start.hour, 0, "check start of the day")
self.assertEqual(e1.start.tzinfo, gettz('Europe/Zurich'), "check tz as specified in calendar")
def test_ms_timezone(self):
ical = "test/test_data/ms_tz.ics"
start = date(2021, 1, 1)
end = date(2021, 12, 31)
evs = icalevents.events(file=ical, start=start, end=end)
e1 = evs[0]
self.assertEqual(e1.start.hour, 0, "check start of the day")
self.assertEqual(e1.start.tzinfo, gettz('Europe/Berlin'), "check tz as specified in calendar")