[CalendarServer-changes] [7874] CalendarServer/branches/users/glyph/imip-and-admin-html/ twistedcaldav/test/test_mail.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 11 21:35:17 PDT 2011


Revision: 7874
          http://trac.macosforge.org/projects/calendarserver/changeset/7874
Author:   glyph at apple.com
Date:     2011-08-11 21:35:17 -0700 (Thu, 11 Aug 2011)
Log Message:
-----------
initial basic test for generateEmail

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/test/test_mail.py

Modified: CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/test/test_mail.py
===================================================================
--- CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/test/test_mail.py	2011-08-12 04:35:07 UTC (rev 7873)
+++ CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/test/test_mail.py	2011-08-12 04:35:17 UTC (rev 7874)
@@ -35,6 +35,22 @@
 def echo(*args):
     return args
 
+initialInviteText = u"""BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:CFDD5E46-4F74-478A-9311-B3FF905449C3
+DTSTART:20100325T154500Z
+DTEND:20100325T164500Z
+ATTENDEE;CN=Th\xe9 Attendee;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:attendee at example.com
+ATTENDEE;CN=Th\xe9 Organizer;CUTYPE=INDIVIDUAL;EMAIL=organizer at example.com;PARTSTAT=ACCEPTED:urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A
+ATTENDEE;CN=An Attendee without CUTYPE;EMAIL=nocutype at example.com;PARTSTAT=ACCEPTED:urn:uuid:4DB528DC-3E60-44FA-9546-2A00FCDCFFAB
+ATTENDEE;EMAIL=nocn at example.com;PARTSTAT=ACCEPTED:urn:uuid:A592CF8B-4FC8-4E4F-B543-B2F29A7EEB0B
+ORGANIZER;CN=Th\xe9 Organizer;EMAIL=organizer at example.com:urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A
+SUMMARY:t\xe9sting outbound( )
+END:VEVENT
+END:VCALENDAR
+"""
 
 class MailHandlerTests(TestCase):
 
@@ -267,22 +283,7 @@
         data = (
             # Initial invite
             (
-                u"""BEGIN:VCALENDAR
-VERSION:2.0
-METHOD:REQUEST
-BEGIN:VEVENT
-UID:CFDD5E46-4F74-478A-9311-B3FF905449C3
-DTSTART:20100325T154500Z
-DTEND:20100325T164500Z
-ATTENDEE;CN=Th\xe9 Attendee;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:mailto:attendee at example.com
-ATTENDEE;CN=Th\xe9 Organizer;CUTYPE=INDIVIDUAL;EMAIL=organizer at example.com;PARTSTAT=ACCEPTED:urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A
-ATTENDEE;CN=An Attendee without CUTYPE;EMAIL=nocutype at example.com;PARTSTAT=ACCEPTED:urn:uuid:4DB528DC-3E60-44FA-9546-2A00FCDCFFAB
-ATTENDEE;EMAIL=nocn at example.com;PARTSTAT=ACCEPTED:urn:uuid:A592CF8B-4FC8-4E4F-B543-B2F29A7EEB0B
-ORGANIZER;CN=Th\xe9 Organizer;EMAIL=organizer at example.com:urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A
-SUMMARY:t\xe9sting outbound( )
-END:VEVENT
-END:VCALENDAR
-""",
+                initialInviteText,
                 "CFDD5E46-4F74-478A-9311-B3FF905449C3",
                 "urn:uuid:C3B38B00-4166-11DD-B22C-A07C87E02F6A",
                 "mailto:attendee at example.com",
@@ -402,6 +403,33 @@
                 self.assertEquals(actualReplyTo, actualFrom)
 
 
+    def test_generateEmail(self):
+        """
+        L{MailHandler.generateEmail} generates a MIME-formatted email with a
+        text/plain part, a text/html part, and a text/calendar part.
+        """
+        calendar = Component.fromString(initialInviteText)
+        msgID, msgTxt = self.handler.generateEmail(
+            inviteState='new',
+            calendar=calendar,
+            orgEmail="user01 at localhost",
+            orgCN="User Zero One",
+            attendees=[("User 1", "user01 at localhost"),
+                       ("User 2", "user02 at localhost")],
+            fromAddress="user01 at localhost",
+            replyToAddress="imip-system at localhost",
+            toAddress="user03 at localhost",
+        )
+        message = email.message_from_string(msgTxt)
+        self.assertEquals(message['Message-ID'], msgID)
+        expectedTypes = set(["text/plain", "text/html", "text/calendar"])
+        actualTypes = set([
+            part.get_content_type() for part in message.walk()
+            if not part.get_content_type().startswith("multipart/")
+        ])
+        self.assertEquals(actualTypes, expectedTypes)
+
+
 class MailGatewayTokensDatabaseTests(TestCase):
 
     def setUp(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110811/b65f9c08/attachment-0001.html>


More information about the calendarserver-changes mailing list