Changeset View
Changeset View
Standalone View
Standalone View
tests/unit/test-004-icalendar.py
from email import message_from_string | from email import message_from_string | ||||
import icalendar | import icalendar | ||||
import unittest | import unittest | ||||
class TestICalendar(unittest.TestCase): | class TestICalendar(unittest.TestCase): | ||||
def test_001_from_message_recurrence(self): | def test_001_from_message_recurrence(self): | ||||
message = message_from_string("""Received: from localhost (localhost [127.0.0.1]) | message = message_from_string("""Received: from localhost (localhost [127.0.0.1]) | ||||
by kolab.example.org (Postfix) with ESMTP id 513B942E10 | by kolab.example.org (Postfix) with ESMTP id 513B942E10 | ||||
for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:16 +0200 (CEST) | for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:16 +0200 (CEST) | ||||
X-Virus-Scanned: amavisd-new at example.org | X-Virus-Scanned: amavisd-new at example.org | ||||
X-Spam-Flag: NO | X-Spam-Flag: NO | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
END:VEVENT | END:VEVENT | ||||
END:VCALENDAR | END:VCALENDAR | ||||
--=_c8894dbdb8baeedacae836230e3436fd-- | --=_c8894dbdb8baeedacae836230e3436fd-- | ||||
""") | """) | ||||
self.assertTrue(message.is_multipart()) | self.assertTrue(message.is_multipart()) | ||||
itip_methods = [ "REQUEST" ] | itip_methods = ["REQUEST"] | ||||
# Check each part | # Check each part | ||||
for part in message.walk(): | for part in message.walk(): | ||||
# The iTip part MUST be Content-Type: text/calendar (RFC 6047, | # The iTip part MUST be Content-Type: text/calendar (RFC 6047, | ||||
# section 2.4) | # section 2.4) | ||||
if part.get_content_type() == "text/calendar": | if part.get_content_type() == "text/calendar": | ||||
if not part.get_param('method') in itip_methods: | if not part.get_param('method') in itip_methods: | ||||
raise Exception, "method not interesting" | raise Exception("method not interesting") | ||||
# Get the itip_payload | # Get the itip_payload | ||||
itip_payload = part.get_payload(decode=True) | itip_payload = part.get_payload(decode=True) | ||||
# Python iCalendar prior to 3.0 uses "from_string". | # Python iCalendar prior to 3.0 uses "from_string". | ||||
if hasattr(icalendar.Calendar, 'from_ical'): | if hasattr(icalendar.Calendar, 'from_ical'): | ||||
cal = icalendar.Calendar.from_ical(itip_payload) | cal = icalendar.Calendar.from_ical(itip_payload) | ||||
elif hasattr(icalendar.Calendar, 'from_string'): | elif hasattr(icalendar.Calendar, 'from_string'): | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
END:VEVENT | END:VEVENT | ||||
END:VCALENDAR | END:VCALENDAR | ||||
--=_c8894dbdb8baeedacae836230e3436fd-- | --=_c8894dbdb8baeedacae836230e3436fd-- | ||||
""") | """) | ||||
self.assertTrue(message.is_multipart()) | self.assertTrue(message.is_multipart()) | ||||
itip_methods = [ "REQUEST" ] | itip_methods = ["REQUEST"] | ||||
# Check each part | # Check each part | ||||
for part in message.walk(): | for part in message.walk(): | ||||
# The iTip part MUST be Content-Type: text/calendar (RFC 6047, | # The iTip part MUST be Content-Type: text/calendar (RFC 6047, | ||||
# section 2.4) | # section 2.4) | ||||
if part.get_content_type() == "text/calendar": | if part.get_content_type() == "text/calendar": | ||||
if not part.get_param('method') in itip_methods: | if not part.get_param('method') in itip_methods: | ||||
raise Exception, "method not interesting" | raise Exception("method not interesting") | ||||
# Get the itip_payload | # Get the itip_payload | ||||
itip_payload = part.get_payload(decode=True) | itip_payload = part.get_payload(decode=True) | ||||
# Python iCalendar prior to 3.0 uses "from_string". | # Python iCalendar prior to 3.0 uses "from_string". | ||||
if hasattr(icalendar.Calendar, 'from_ical'): | if hasattr(icalendar.Calendar, 'from_ical'): | ||||
cal = icalendar.Calendar.from_ical(itip_payload) | cal = icalendar.Calendar.from_ical(itip_payload) | ||||
elif hasattr(icalendar.Calendar, 'from_string'): | elif hasattr(icalendar.Calendar, 'from_string'): | ||||
cal = icalendar.Calendar.from_string(itip_payload) | cal = icalendar.Calendar.from_string(itip_payload) | ||||
# If we can't read it, we're out | # If we can't read it, we're out | ||||
else: | else: | ||||
return [] | return [] |