pykolab/xml tests/unit
Thomas Brüderli
bruederli at kolabsys.com
Wed Feb 18 13:46:17 CET 2015
pykolab/xml/event.py | 26 ++++++++++++++++++--------
tests/unit/test-003-event.py | 27 +++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 8 deletions(-)
New commits:
commit 967d68a6f672b7321d2f08c30792c73300f93d1d
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Tue Feb 17 06:12:08 2015 +0100
Write recurrence exceptions to iCal
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index c061bcb..a054053 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -220,6 +220,19 @@ class Event(object):
# TODO: Add timezone information using icalendar.?()
# Not sure if there is a class for it.
+ cal.add_component(self.to_ical())
+
+ # add recurrence exceptions
+ if len(self._exceptions) > 0 and not method == 'REPLY':
+ for exception in self._exceptions:
+ cal.add_component(exception.to_ical())
+
+ if hasattr(cal, 'to_ical'):
+ return cal.to_ical()
+ elif hasattr(cal, 'as_string'):
+ return cal.as_string()
+
+ def to_ical(self):
event = icalendar.Event()
# Required
@@ -259,12 +272,7 @@ class Event(object):
for cs in self.event.customProperties():
event.add(cs.identifier, cs.value)
- cal.add_component(event)
-
- if hasattr(cal, 'to_ical'):
- return cal.to_ical()
- elif hasattr(cal, 'as_string'):
- return cal.as_string()
+ return event
def delegate(self, delegators, delegatees, names=None):
if not isinstance(delegators, list):
@@ -343,8 +351,10 @@ class Event(object):
ical = "BEGIN:VCALENDAR\nVERSION:2.0\n" + ical + "\nEND:VCALENDAR"
from kolab.calendaring import EventCal
self.event = EventCal()
- self.event.fromICal(ical)
- self._load_exceptions()
+ success = self.event.fromICal(ical)
+ if success:
+ self._load_exceptions()
+ return success
def get_attendee_participant_status(self, attendee):
return attendee.get_participant_status()
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 02520e7..042d56a 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -668,6 +668,33 @@ END:VEVENT
occurrence = event.get_next_instance(event.get_start())
self.assertEqual(occurrence.get_summary(), "Exception")
+ def test_021_ical_exceptions(self):
+ self.event.set_summary("test")
+ self.event.set_start(datetime.datetime(2014, 05, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))
+ self.event.set_end(datetime.datetime(2014, 05, 23, 12, 30, 00, tzinfo=pytz.timezone("Europe/London")))
+
+ rrule = kolabformat.RecurrenceRule()
+ rrule.setFrequency(kolabformat.RecurrenceRule.Weekly)
+ self.event.set_recurrence(rrule)
+
+ xmlexception = Event(from_string=str(self.event))
+ xmlexception.set_start(datetime.datetime(2014, 05, 30, 14, 00, 00, tzinfo=pytz.timezone("Europe/London")))
+ xmlexception.set_end(datetime.datetime(2014, 05, 30, 16, 00, 00, tzinfo=pytz.timezone("Europe/London")))
+ xmlexception.set_recurrence_id(datetime.datetime(2014, 05, 30, 11, 0, 0), False)
+ self.event.add_exception(xmlexception)
+
+ ical = icalendar.Calendar.from_ical(self.event.as_string_itip())
+ vevents = ical.walk('VEVENT')
+ event = vevents[0]
+ exception = vevents[1]
+
+ self.assertEqual(event['uid'], self.event.get_uid())
+ self.assertEqual(event['summary'], "test")
+
+ self.assertEqual(exception['uid'], self.event.get_uid())
+ self.assertIsInstance(exception['recurrence-id'].dt, datetime.datetime)
+ self.assertEqual(exception['recurrence-id'].params.get('RANGE'), None)
+
def test_022_load_from_xml(self):
event = event_from_string(xml_event)
self.assertEqual(event.uid, '75c740bb-b3c6-442c-8021-ecbaeb0a025e')
More information about the commits
mailing list