From 4a76d06a534417920f76fae229c7130a12d2965f Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Sun, 6 Jul 2014 22:01:04 -0400 Subject: Load attendees list from libkolabxml container --- pykolab/xml/event.py | 5 +++ tests/unit/test-003-event.py | 87 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py index 9f0775b..ea84cc4 100644 --- a/pykolab/xml/event.py +++ b/pykolab/xml/event.py @@ -40,11 +40,16 @@ class Event(object): self.event = kolabformat.Event() else: self.event = kolabformat.readEvent(from_string, False) + self._load_attendees() else: self.from_ical(from_ical) self.uid = self.get_uid() + def _load_attendees(self): + for a in self.event.attendees(): + self._attendees.append(Attendee(a.contact().email(), a.contact().name(), a.rsvp(), a.role(), a.partStat(), a.cutype())) + def add_attendee(self, email, name=None, rsvp=False, role=None, participant_status=None, cutype="INDIVIDUAL", params=None): attendee = Attendee(email, name, rsvp, role, participant_status, cutype, params) self._attendees.append(attendee) diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py index 61ea8ec..a44c4ec 100644 --- a/tests/unit/test-003-event.py +++ b/tests/unit/test-003-event.py @@ -11,6 +11,7 @@ from pykolab.xml import EventIntegrityError from pykolab.xml import InvalidAttendeeParticipantStatusError from pykolab.xml import InvalidEventDateError from pykolab.xml import event_from_ical +from pykolab.xml import event_from_string class TestEventXML(unittest.TestCase): event = Event() @@ -149,12 +150,14 @@ END:VCALENDAR 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"))) + self.event.set_sequence(3) ical = icalendar.Calendar.from_ical(self.event.as_string_itip()) event = ical.walk('VEVENT')[0] self.assertEqual(event['uid'], self.event.get_uid()) self.assertEqual(event['summary'], "test") + self.assertEqual(event['sequence'], 3) self.assertIsInstance(event['dtstamp'].dt, datetime.datetime) def test_020_calendaring_recurrence(self): @@ -214,6 +217,90 @@ END:VCALENDAR self.assertEqual(self.event.get_next_occurence(_start), None) self.assertEqual(self.event.get_last_occurrence(), None) + def test_022_load_from_xml(self): + xml = """ + + + + + Libkolabxml-1.1 + + + 2.0 + + + 3.1.0 + + + + + + + 75c740bb-b3c6-442c-8021-ecbaeb0a025e + + + 2014-07-07T01:28:23Z + + + 2014-07-07T01:28:23Z + + + 1 + + + PUBLIC + + + + + /kolab.org/Europe/London + + + 2014-08-13T10:00:00 + + + + /kolab.org/Europe/London + + 2014-08-13T14:00:00 + + + test + + + + Doe, John + + mailto:%3Cjohn%40example.org%3E + + + + ACCEPTED + REQ-PARTICIPANT + true + + mailto:%3Cjane%40example.org%3E + + + + TENTATIVE + OPT-PARTICIPANT + + mailto:%3Csomebody%40else.com%3E + + + + + + +""" + event = event_from_string(xml) + self.assertEqual(event.uid, '75c740bb-b3c6-442c-8021-ecbaeb0a025e') + self.assertEqual(event.get_attendee_by_email("jane@example.org").get_participant_status(), kolabformat.PartAccepted) + self.assertEqual(event.get_sequence(), 1) + self.assertIsInstance(event.get_start(), datetime.datetime) + self.assertEqual(str(event.get_start()), "2014-08-13 10:00:00+00:00") + if __name__ == '__main__': unittest.main() -- cgit v1.1