diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2014-07-07 18:43:25 -0400 |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2014-07-07 18:43:25 -0400 |
commit | a674289628249f45ec46c3096b1c476692943ff3 (patch) | |
tree | 56a6085d94514a2098eaca41e847e39cb50e693a | |
parent | 6e137a89f6f29975133633e2e70557b3954d4220 (diff) | |
download | pykolab-a674289628249f45ec46c3096b1c476692943ff3.tar.gz |
Use new pykolab.xml.event_from_message() function in wallace modules and verify that attachments survive event updates
-rw-r--r-- | tests/functional/test_wallace/test_005_resource_invitation.py | 18 | ||||
-rw-r--r-- | tests/functional/test_wallace/test_007_invitationpolicy.py | 27 | ||||
-rw-r--r-- | wallace/module_invitationpolicy.py | 43 | ||||
-rw-r--r-- | wallace/module_resources.py | 39 |
4 files changed, 64 insertions, 63 deletions
diff --git a/tests/functional/test_wallace/test_005_resource_invitation.py b/tests/functional/test_wallace/test_005_resource_invitation.py index 946cb5f..d9f2d41 100644 --- a/tests/functional/test_wallace/test_005_resource_invitation.py +++ b/tests/functional/test_wallace/test_005_resource_invitation.py @@ -8,6 +8,7 @@ import uuid from pykolab.imap import IMAP from wallace import module_resources +from pykolab.xml import event_from_message from email import message_from_string from twisted.trial import unittest @@ -23,7 +24,7 @@ CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT UID:%s -DTSTAMP:20140213T1254140 +DTSTAMP:20140213T125414Z DTSTART;TZID=Europe/London:%s DTEND;TZID=Europe/London:%s SUMMARY:test @@ -43,7 +44,7 @@ CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT UID:%s -DTSTAMP:20140215T1254140 +DTSTAMP:20140215T125414Z DTSTART;TZID=Europe/London:%s DTEND;TZID=Europe/London:%s SEQUENCE:2 @@ -90,7 +91,7 @@ CALSCALE:GREGORIAN METHOD:CANCEL BEGIN:VEVENT UID:%s -DTSTAMP:20140218T1254140 +DTSTAMP:20140218T125414Z DTSTART;TZID=Europe/London:20120713T100000 DTEND;TZID=Europe/London:20120713T110000 SUMMARY:test @@ -112,7 +113,7 @@ CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT UID:%s -DTSTAMP:20140213T1254140 +DTSTAMP:20140213T125414Z DTSTART;VALUE=DATE:%s DTEND;VALUE=DATE:%s SUMMARY:test @@ -133,7 +134,7 @@ CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT UID:%s -DTSTAMP:20140213T1254140 +DTSTAMP:20140213T125414Z DTSTART;TZID=Europe/Zurich:%s DTEND;TZID=Europe/Zurich:%s RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=10 @@ -328,12 +329,7 @@ class TestResourceInvitation(unittest.TestCase): if uid and event_message['subject'] != uid: continue - for part in event_message.walk(): - if part.get_content_type() == "application/calendar+xml": - payload = part.get_payload(decode=True) - found = pykolab.xml.event_from_string(payload) - break - + found = event_from_message(event_message) if found: break diff --git a/tests/functional/test_wallace/test_007_invitationpolicy.py b/tests/functional/test_wallace/test_007_invitationpolicy.py index 4fd61a7..3b68aef 100644 --- a/tests/functional/test_wallace/test_007_invitationpolicy.py +++ b/tests/functional/test_wallace/test_007_invitationpolicy.py @@ -11,6 +11,7 @@ from pykolab.imap import IMAP from wallace import module_resources from pykolab.translate import _ +from pykolab.xml import event_from_message from email import message_from_string from twisted.trial import unittest @@ -26,7 +27,7 @@ CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT UID:%(uid)s -DTSTAMP:20140213T1254140 +DTSTAMP:20140213T125414Z DTSTART;TZID=Europe/Berlin:%(start)s DTEND;TZID=Europe/Berlin:%(end)s SUMMARY:%(summary)s @@ -48,7 +49,7 @@ CALSCALE:GREGORIAN METHOD:CANCEL BEGIN:VEVENT UID:%(uid)s -DTSTAMP:20140218T1254140 +DTSTAMP:20140218T125414Z DTSTART;TZID=Europe/Berlin:20120713T100000 DTEND;TZID=Europe/Berlin:20120713T110000 SUMMARY:%(summary)s @@ -69,7 +70,7 @@ CALSCALE:GREGORIAN METHOD:REQUEST BEGIN:VEVENT UID:%(uid)s -DTSTAMP:20140213T1254140 +DTSTAMP:20140213T125414Z DTSTART;TZID=Europe/Zurich:%(start)s DTEND;TZID=Europe/Zurich:%(end)s RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=10 @@ -295,6 +296,14 @@ class TestWallaceInvitationpolicy(unittest.TestCase): event.set_summary(summary) event.set_sequence(sequence) + # create event with attachment + vattach = event.get_attachments() + attachment = kolabformat.Attachment() + attachment.setLabel('attach.txt') + attachment.setData('This is a text attachment', 'text/plain') + vattach.append(attachment) + event.event.setAttachments(vattach) + imap = IMAP() imap.connect() @@ -365,12 +374,7 @@ class TestWallaceInvitationpolicy(unittest.TestCase): if uid and event_message['subject'] != uid: continue - for part in event_message.walk(): - if part.get_content_type() == "application/calendar+xml": - payload = part.get_payload(decode=True) - found = pykolab.xml.event_from_string(payload) - break - + found = event_from_message(event_message) if found: break @@ -506,6 +510,11 @@ class TestWallaceInvitationpolicy(unittest.TestCase): self.assertIsInstance(attendee, pykolab.xml.Attendee) self.assertEqual(attendee.get_participant_status(), kolabformat.PartAccepted) + # check attachments in update event + attachments = event.get_attachments() + self.assertEqual(len(attachments), 1) + self.assertEqual(event.get_attachment_data(0), 'This is a text attachment') + def test_007_invitation_cancel(self): self.purge_mailbox(self.john['mailbox']) diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py index a141251..7375d2d 100644 --- a/wallace/module_invitationpolicy.py +++ b/wallace/module_invitationpolicy.py @@ -39,7 +39,7 @@ from pykolab.auth import Auth from pykolab.conf import Conf from pykolab.imap import IMAP from pykolab.xml import to_dt -from pykolab.xml import event_from_string +from pykolab.xml import event_from_message from pykolab.itip import events_from_message from pykolab.itip import check_event_conflict from pykolab.itip import send_reply @@ -619,15 +619,12 @@ def find_existing_event(itip_event, user_rec): for num in reversed(data[0].split()): typ, data = imap.imap.m.fetch(num, '(RFC822)') - event_message = message_from_string(data[0][1]) - - if event_message.is_multipart(): - for part in event_message.walk(): - if part.get_content_type() == "application/calendar+xml": - payload = part.get_payload(decode=True) - event = event_from_string(payload) - setattr(event, '_imap_folder', folder) - break + try: + event = event_from_message(message_from_string(data[0][1])) + setattr(event, '_imap_folder', folder) + except Exception, e: + log.error(_("Failed to parse event from message %s/%s: %r") % (folder, num, e)) + continue if event and event.uid == itip_event['uid']: return event @@ -659,20 +656,18 @@ def check_availability(itip_event, receiving_user): event = None typ, data = imap.imap.m.fetch(num, '(RFC822)') - event_message = message_from_string(data[0][1]) - - if event_message.is_multipart(): - for part in event_message.walk(): - if part.get_content_type() == "application/calendar+xml": - payload = part.get_payload(decode=True) - event = event_from_string(payload) - break - - if event and event.uid: - conflict = check_event_conflict(event, itip_event) - if conflict: - log.info(_("Existing event %r conflicts with invitation %r") % (event.uid, itip_event['uid'])) - break + try: + event = event_from_message(message_from_string(data[0][1])) + setattr(event, '_imap_folder', folder) + except Exception, e: + log.error(_("Failed to parse event from message %s/%s: %r") % (folder, num, e)) + continue + + if event and event.uid: + conflict = check_event_conflict(event, itip_event) + if conflict: + log.info(_("Existing event %r conflicts with invitation %r") % (event.uid, itip_event['uid'])) + break if conflict: break diff --git a/wallace/module_resources.py b/wallace/module_resources.py index f398120..3864f7c 100644 --- a/wallace/module_resources.py +++ b/wallace/module_resources.py @@ -40,8 +40,8 @@ import kolabformat from pykolab.auth import Auth from pykolab.conf import Conf from pykolab.imap import IMAP -from pykolab.xml import event_from_string from pykolab.xml import to_dt +from pykolab.xml import event_from_message from pykolab.itip import events_from_message from pykolab.itip import check_event_conflict from pykolab.translate import _ @@ -467,28 +467,29 @@ def read_resource_calendar(resource_rec, itip_events): event_message = message_from_string(data[0][1]) - if event_message.is_multipart(): - for part in event_message.walk(): - if part.get_content_type() == "application/calendar+xml": - payload = part.get_payload(decode=True) - event = pykolab.xml.event_from_string(payload) + try: + event = event_from_message(message_from_string(data[0][1])) + except Exception, e: + log.error(_("Failed to parse event from message %s/%s: %r") % (mailbox, num, e)) + continue - for itip in itip_events: - conflict = check_event_conflict(event, itip) + if event: + for itip in itip_events: + conflict = check_event_conflict(event, itip) - if event.get_uid() == itip['uid']: - resource_rec['existing_events'].append(itip['uid']) + if event.get_uid() == itip['uid']: + resource_rec['existing_events'].append(itip['uid']) - if conflict: - log.info( - _("Event %r conflicts with event %r") % ( - itip['xml'].get_uid(), - event.get_uid() - ) - ) + if conflict: + log.info( + _("Event %r conflicts with event %r") % ( + itip['xml'].get_uid(), + event.get_uid() + ) + ) - resource_rec['conflicting_events'].append(event.get_uid()) - resource_rec['conflict'] = True + resource_rec['conflicting_events'].append(event.get_uid()) + resource_rec['conflict'] = True return num_messages |