kopia lustrzana https://github.com/collective/icalendar
Merge pull request #488 from jacadzaca/refactor_test_reccurence
Refactor test recurrencepull/491/head
commit
eeb9714d3b
|
|
@ -0,0 +1,7 @@
|
||||||
|
BEGIN:VEVENT
|
||||||
|
DTSTART:19960401T010000
|
||||||
|
DTEND:19960401T020000
|
||||||
|
RRULE:FREQ=DAILY;COUNT=100
|
||||||
|
EXDATE:19960402T010000Z,19960403T010000Z,19960404T010000Z
|
||||||
|
SUMMARY:A recurring event with exdates
|
||||||
|
END:VEVENT
|
||||||
|
|
@ -1,14 +1,3 @@
|
||||||
BEGIN:VCALENDAR
|
|
||||||
METHOD:Request
|
|
||||||
PRODID:-//My product//mxm.dk/
|
|
||||||
VERSION:2.0
|
|
||||||
BEGIN:VEVENT
|
|
||||||
DTSTART:19960401T010000
|
|
||||||
DTEND:19960401T020000
|
|
||||||
RRULE:FREQ=DAILY;COUNT=100
|
|
||||||
EXDATE:19960402T010000Z,19960403T010000Z,19960404T010000Z
|
|
||||||
SUMMARY:A recurring event with exdates
|
|
||||||
END:VEVENT
|
|
||||||
BEGIN:VEVENT
|
BEGIN:VEVENT
|
||||||
DTSTART;TZID=Europe/Vienna:20120327T100000
|
DTSTART;TZID=Europe/Vienna:20120327T100000
|
||||||
DTEND;TZID=Europe/Vienna:20120327T180000
|
DTEND;TZID=Europe/Vienna:20120327T180000
|
||||||
|
|
@ -21,4 +10,3 @@ EXDATE;TZID=Europe/Vienna:20120417T100000
|
||||||
DTSTAMP:20130716T120638Z
|
DTSTAMP:20130716T120638Z
|
||||||
SUMMARY:A Recurring event with multiple exdates, one per line.
|
SUMMARY:A Recurring event with multiple exdates, one per line.
|
||||||
END:VEVENT
|
END:VEVENT
|
||||||
END:VCALENDAR
|
|
||||||
|
|
@ -1,61 +1,42 @@
|
||||||
from icalendar.caselessdict import CaselessDict
|
from datetime import datetime
|
||||||
import unittest
|
|
||||||
|
|
||||||
import datetime
|
import pytest
|
||||||
import icalendar
|
|
||||||
import os
|
|
||||||
import pytz
|
|
||||||
|
|
||||||
|
def test_recurrence_properly_parsed(events):
|
||||||
|
assert events.event_with_recurrence['rrule'] == {'COUNT': [100], 'FREQ': ['DAILY']}
|
||||||
|
|
||||||
class TestRecurrence(unittest.TestCase):
|
@pytest.mark.parametrize('i, exception_date', [
|
||||||
|
(0, datetime(1996, 4, 2, 1, 0)),
|
||||||
|
(1, datetime(1996, 4, 3, 1, 0)),
|
||||||
|
(2, datetime(1996, 4, 4, 1, 0))
|
||||||
|
])
|
||||||
|
def test_exdate_properly_parsed(events, i, exception_date, in_timezone):
|
||||||
|
assert events.event_with_recurrence['exdate'].dts[i].dt == in_timezone(exception_date, 'UTC')
|
||||||
|
|
||||||
def setUp(self):
|
def test_exdate_properly_marshalled(events):
|
||||||
directory = os.path.dirname(__file__)
|
actual = events.event_with_recurrence['exdate'].to_ical()
|
||||||
with open(os.path.join(directory, 'recurrence.ics'), 'rb') as fp:
|
assert actual == b'19960402T010000Z,19960403T010000Z,19960404T010000Z'
|
||||||
data = fp.read()
|
|
||||||
self.cal = icalendar.Calendar.from_ical(data)
|
|
||||||
|
|
||||||
def test_recurrence_exdates_one_line(self):
|
# TODO: DOCUMENT BETTER!
|
||||||
first_event = self.cal.walk('vevent')[0]
|
# In this case we have multiple EXDATE definitions, one per line.
|
||||||
|
# Icalendar makes a list out of this instead of zipping it into one
|
||||||
|
# vDDDLists object. Actually, this feels correct for me, as it also
|
||||||
|
# allows to define different timezones per exdate line - but client
|
||||||
|
# code has to handle this as list and not blindly expecting to be able
|
||||||
|
# to call event['EXDATE'].to_ical() on it:
|
||||||
|
def test_exdate_formed_from_exdates_on_multiple_lines_is_a_list(events):
|
||||||
|
exdate = events.event_with_recurrence_exdates_on_different_lines['exdate']
|
||||||
|
assert isinstance(exdate, list)
|
||||||
|
|
||||||
self.assertIsInstance(first_event, CaselessDict)
|
@pytest.mark.parametrize('i, exception_date, exception_date_ics', [
|
||||||
self.assertEqual(
|
(0, datetime(2012, 5, 29, 10, 0), b'20120529T100000'),
|
||||||
first_event['rrule'], {'COUNT': [100], 'FREQ': ['DAILY']}
|
(1, datetime(2012, 4, 3, 10, 0), b'20120403T100000'),
|
||||||
)
|
(2, datetime(2012, 4, 10, 10, 0), b'20120410T100000'),
|
||||||
|
(3, datetime(2012, 5, 1, 10, 0), b'20120501T100000'),
|
||||||
|
(4, datetime(2012, 4, 17, 10, 0), b'20120417T100000')
|
||||||
|
])
|
||||||
|
def test_list_exdate_to_ical_is_inverse_of_from_ical(events, i, exception_date, exception_date_ics, in_timezone):
|
||||||
|
exdate = events.event_with_recurrence_exdates_on_different_lines['exdate']
|
||||||
|
assert exdate[i].dts[0].dt == in_timezone(exception_date, 'Europe/Vienna')
|
||||||
|
assert exdate[i].to_ical() == exception_date_ics
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
first_event['exdate'].to_ical(),
|
|
||||||
b'19960402T010000Z,19960403T010000Z,19960404T010000Z'
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
first_event['exdate'].dts[0].dt,
|
|
||||||
pytz.utc.localize(datetime.datetime(1996, 4, 2, 1, 0))
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
first_event['exdate'].dts[1].dt,
|
|
||||||
pytz.utc.localize(datetime.datetime(1996, 4, 3, 1, 0))
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
first_event['exdate'].dts[2].dt,
|
|
||||||
pytz.utc.localize(datetime.datetime(1996, 4, 4, 1, 0))
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_recurrence_exdates_multiple_lines(self):
|
|
||||||
event = self.cal.walk('vevent')[1]
|
|
||||||
|
|
||||||
exdate = event['exdate']
|
|
||||||
|
|
||||||
# TODO: DOCUMENT BETTER!
|
|
||||||
# In this case we have multiple EXDATE definitions, one per line.
|
|
||||||
# Icalendar makes a list out of this instead of zipping it into one
|
|
||||||
# vDDDLists object. Actually, this feels correct for me, as it also
|
|
||||||
# allows to define different timezones per exdate line - but client
|
|
||||||
# code has to handle this as list and not blindly expecting to be able
|
|
||||||
# to call event['EXDATE'].to_ical() on it:
|
|
||||||
self.assertEqual(isinstance(exdate, list), True) # multiple EXDATE
|
|
||||||
self.assertEqual(exdate[0].to_ical(), b'20120529T100000')
|
|
||||||
|
|
||||||
# TODO: test for embedded timezone information!
|
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue