Back to index

python3.2  3.2.2
Public Member Functions | Private Attributes
email.test.test_email.TestMIMEMessage Class Reference
Inheritance diagram for email.test.test_email.TestMIMEMessage:
Inheritance graph
[legend]
Collaboration diagram for email.test.test_email.TestMIMEMessage:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def test_type_error
def test_valid_argument
def test_bad_multipart
def test_generate
def test_parse_message_rfc822
def test_dsn
def test_epilogue
def test_no_nl_preamble
def test_default_type
def test_default_type_with_explicit_container_type
def test_default_type_non_parsed
def test_mime_attachments_in_constructor
def test_default_multipart_constructor
def ndiffAssertEqual

Private Attributes

 _text

Detailed Description

Definition at line 1980 of file test_email.py.


Member Function Documentation

def email.test.test_email.TestEmailBase.ndiffAssertEqual (   self,
  first,
  second 
) [inherited]
Like assertEqual except use ndiff for readable output.

Definition at line 57 of file test_email.py.

00057 
00058     def ndiffAssertEqual(self, first, second):
00059         """Like assertEqual except use ndiff for readable output."""
00060         if first != second:
00061             sfirst = str(first)
00062             ssecond = str(second)
00063             rfirst = [repr(line) for line in sfirst.splitlines()]
00064             rsecond = [repr(line) for line in ssecond.splitlines()]
00065             diff = difflib.ndiff(rfirst, rsecond)
00066             raise self.failureException(NL + NL.join(diff))

Here is the call graph for this function:

Definition at line 1981 of file test_email.py.

01981 
01982     def setUp(self):
01983         with openfile('msg_11.txt') as fp:
01984             self._text = fp.read()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2003 of file test_email.py.

02003 
02004     def test_bad_multipart(self):
02005         eq = self.assertEqual
02006         msg1 = Message()
02007         msg1['Subject'] = 'subpart 1'
02008         msg2 = Message()
02009         msg2['Subject'] = 'subpart 2'
02010         r = MIMEMessage(msg1)
02011         self.assertRaises(errors.MultipartConversionError, r.attach, msg2)

Here is the call graph for this function:

Definition at line 2275 of file test_email.py.

02275 
02276     def test_default_multipart_constructor(self):
02277         msg = MIMEMultipart()
02278         self.assertTrue(msg.is_multipart())
02279 
02280 
02281 # A general test of parser->model->generator idempotency.  IOW, read a message
02282 # in, parse it into a message object tree, then without touching the tree,
02283 # regenerate the plain text.  The original text and the transformed text
02284 # should be identical.  Note: that we ignore the Unix-From since that may
# contain a changed date.

Here is the call graph for this function:

Definition at line 2158 of file test_email.py.

02158 
02159     def test_default_type(self):
02160         eq = self.assertEqual
02161         with openfile('msg_30.txt') as fp:
02162             msg = email.message_from_file(fp)
02163         container1 = msg.get_payload(0)
02164         eq(container1.get_default_type(), 'message/rfc822')
02165         eq(container1.get_content_type(), 'message/rfc822')
02166         container2 = msg.get_payload(1)
02167         eq(container2.get_default_type(), 'message/rfc822')
02168         eq(container2.get_content_type(), 'message/rfc822')
02169         container1a = container1.get_payload(0)
02170         eq(container1a.get_default_type(), 'text/plain')
02171         eq(container1a.get_content_type(), 'text/plain')
02172         container2a = container2.get_payload(0)
02173         eq(container2a.get_default_type(), 'text/plain')
02174         eq(container2a.get_content_type(), 'text/plain')

Here is the call graph for this function:

Definition at line 2192 of file test_email.py.

02192 
02193     def test_default_type_non_parsed(self):
02194         eq = self.assertEqual
02195         neq = self.ndiffAssertEqual
02196         # Set up container
02197         container = MIMEMultipart('digest', 'BOUNDARY')
02198         container.epilogue = ''
02199         # Set up subparts
02200         subpart1a = MIMEText('message 1\n')
02201         subpart2a = MIMEText('message 2\n')
02202         subpart1 = MIMEMessage(subpart1a)
02203         subpart2 = MIMEMessage(subpart2a)
02204         container.attach(subpart1)
02205         container.attach(subpart2)
02206         eq(subpart1.get_content_type(), 'message/rfc822')
02207         eq(subpart1.get_default_type(), 'message/rfc822')
02208         eq(subpart2.get_content_type(), 'message/rfc822')
02209         eq(subpart2.get_default_type(), 'message/rfc822')
02210         neq(container.as_string(0), '''\
02211 Content-Type: multipart/digest; boundary="BOUNDARY"
02212 MIME-Version: 1.0
02213 
02214 --BOUNDARY
02215 Content-Type: message/rfc822
02216 MIME-Version: 1.0
02217 
02218 Content-Type: text/plain; charset="us-ascii"
02219 MIME-Version: 1.0
02220 Content-Transfer-Encoding: 7bit
02221 
02222 message 1
02223 
02224 --BOUNDARY
02225 Content-Type: message/rfc822
02226 MIME-Version: 1.0
02227 
02228 Content-Type: text/plain; charset="us-ascii"
02229 MIME-Version: 1.0
02230 Content-Transfer-Encoding: 7bit
02231 
02232 message 2
02233 
02234 --BOUNDARY--
02235 ''')
02236         del subpart1['content-type']
02237         del subpart1['mime-version']
02238         del subpart2['content-type']
02239         del subpart2['mime-version']
02240         eq(subpart1.get_content_type(), 'message/rfc822')
02241         eq(subpart1.get_default_type(), 'message/rfc822')
02242         eq(subpart2.get_content_type(), 'message/rfc822')
02243         eq(subpart2.get_default_type(), 'message/rfc822')
02244         neq(container.as_string(0), '''\
02245 Content-Type: multipart/digest; boundary="BOUNDARY"
02246 MIME-Version: 1.0
02247 
02248 --BOUNDARY
02249 
02250 Content-Type: text/plain; charset="us-ascii"
02251 MIME-Version: 1.0
02252 Content-Transfer-Encoding: 7bit
02253 
02254 message 1
02255 
02256 --BOUNDARY
02257 
02258 Content-Type: text/plain; charset="us-ascii"
02259 MIME-Version: 1.0
02260 Content-Transfer-Encoding: 7bit
02261 
02262 message 2
02263 
02264 --BOUNDARY--
02265 ''')

Here is the call graph for this function:

Definition at line 2175 of file test_email.py.

02175 
02176     def test_default_type_with_explicit_container_type(self):
02177         eq = self.assertEqual
02178         with openfile('msg_28.txt') as fp:
02179             msg = email.message_from_file(fp)
02180         container1 = msg.get_payload(0)
02181         eq(container1.get_default_type(), 'message/rfc822')
02182         eq(container1.get_content_type(), 'message/rfc822')
02183         container2 = msg.get_payload(1)
02184         eq(container2.get_default_type(), 'message/rfc822')
02185         eq(container2.get_content_type(), 'message/rfc822')
02186         container1a = container1.get_payload(0)
02187         eq(container1a.get_default_type(), 'text/plain')
02188         eq(container1a.get_content_type(), 'text/plain')
02189         container2a = container2.get_payload(0)
02190         eq(container2a.get_default_type(), 'text/plain')
02191         eq(container2a.get_content_type(), 'text/plain')

Here is the call graph for this function:

Definition at line 2045 of file test_email.py.

02045 
02046     def test_dsn(self):
02047         eq = self.assertEqual
02048         unless = self.assertTrue
02049         # msg 16 is a Delivery Status Notification, see RFC 1894
02050         msg = self._msgobj('msg_16.txt')
02051         eq(msg.get_content_type(), 'multipart/report')
02052         unless(msg.is_multipart())
02053         eq(len(msg.get_payload()), 3)
02054         # Subpart 1 is a text/plain, human readable section
02055         subpart = msg.get_payload(0)
02056         eq(subpart.get_content_type(), 'text/plain')
02057         eq(subpart.get_payload(), """\
02058 This report relates to a message you sent with the following header fields:
02059 
02060   Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
02061   Date: Sun, 23 Sep 2001 20:10:55 -0700
02062   From: "Ian T. Henry" <henryi@oxy.edu>
02063   To: SoCal Raves <scr@socal-raves.org>
02064   Subject: [scr] yeah for Ians!!
02065 
02066 Your message cannot be delivered to the following recipients:
02067 
02068   Recipient address: jangel1@cougar.noc.ucla.edu
02069   Reason: recipient reached disk quota
02070 
02071 """)
02072         # Subpart 2 contains the machine parsable DSN information.  It
02073         # consists of two blocks of headers, represented by two nested Message
02074         # objects.
02075         subpart = msg.get_payload(1)
02076         eq(subpart.get_content_type(), 'message/delivery-status')
02077         eq(len(subpart.get_payload()), 2)
02078         # message/delivery-status should treat each block as a bunch of
02079         # headers, i.e. a bunch of Message objects.
02080         dsn1 = subpart.get_payload(0)
02081         unless(isinstance(dsn1, Message))
02082         eq(dsn1['original-envelope-id'], '0GK500B4HD0888@cougar.noc.ucla.edu')
02083         eq(dsn1.get_param('dns', header='reporting-mta'), '')
02084         # Try a missing one <wink>
02085         eq(dsn1.get_param('nsd', header='reporting-mta'), None)
02086         dsn2 = subpart.get_payload(1)
02087         unless(isinstance(dsn2, Message))
02088         eq(dsn2['action'], 'failed')
02089         eq(dsn2.get_params(header='original-recipient'),
02090            [('rfc822', ''), ('jangel1@cougar.noc.ucla.edu', '')])
02091         eq(dsn2.get_param('rfc822', header='final-recipient'), '')
02092         # Subpart 3 is the original message
02093         subpart = msg.get_payload(2)
02094         eq(subpart.get_content_type(), 'message/rfc822')
02095         payload = subpart.get_payload()
02096         unless(isinstance(payload, list))
02097         eq(len(payload), 1)
02098         subsubpart = payload[0]
02099         unless(isinstance(subsubpart, Message))
02100         eq(subsubpart.get_content_type(), 'text/plain')
02101         eq(subsubpart['message-id'],
02102            '<002001c144a6$8752e060$56104586@oxy.edu>')

Here is the call graph for this function:

Definition at line 2103 of file test_email.py.

02103 
02104     def test_epilogue(self):
02105         eq = self.ndiffAssertEqual
02106         with openfile('msg_21.txt') as fp:
02107             text = fp.read()
02108         msg = Message()
02109         msg['From'] = 'aperson@dom.ain'
02110         msg['To'] = 'bperson@dom.ain'
02111         msg['Subject'] = 'Test'
02112         msg.preamble = 'MIME message'
02113         msg.epilogue = 'End of MIME message\n'
02114         msg1 = MIMEText('One')
02115         msg2 = MIMEText('Two')
02116         msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY')
02117         msg.attach(msg1)
02118         msg.attach(msg2)
02119         sfp = StringIO()
02120         g = Generator(sfp)
02121         g.flatten(msg)
02122         eq(sfp.getvalue(), text)

Here is the call graph for this function:

Definition at line 2012 of file test_email.py.

02012 
02013     def test_generate(self):
02014         # First craft the message to be encapsulated
02015         m = Message()
02016         m['Subject'] = 'An enclosed message'
02017         m.set_payload('Here is the body of the message.\n')
02018         r = MIMEMessage(m)
02019         r['Subject'] = 'The enclosing message'
02020         s = StringIO()
02021         g = Generator(s)
02022         g.flatten(r)
02023         self.assertEqual(s.getvalue(), """\
02024 Content-Type: message/rfc822
02025 MIME-Version: 1.0
02026 Subject: The enclosing message
02027 
02028 Subject: An enclosed message
02029 
02030 Here is the body of the message.
02031 """)

Here is the call graph for this function:

Definition at line 2266 of file test_email.py.

02266 
02267     def test_mime_attachments_in_constructor(self):
02268         eq = self.assertEqual
02269         text1 = MIMEText('')
02270         text2 = MIMEText('')
02271         msg = MIMEMultipart(_subparts=(text1, text2))
02272         eq(len(msg.get_payload()), 2)
02273         eq(msg.get_payload(0), text1)
02274         eq(msg.get_payload(1), text2)

Here is the call graph for this function:

Definition at line 2123 of file test_email.py.

02123 
02124     def test_no_nl_preamble(self):
02125         eq = self.ndiffAssertEqual
02126         msg = Message()
02127         msg['From'] = 'aperson@dom.ain'
02128         msg['To'] = 'bperson@dom.ain'
02129         msg['Subject'] = 'Test'
02130         msg.preamble = 'MIME message'
02131         msg.epilogue = ''
02132         msg1 = MIMEText('One')
02133         msg2 = MIMEText('Two')
02134         msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY')
02135         msg.attach(msg1)
02136         msg.attach(msg2)
02137         eq(msg.as_string(), """\
02138 From: aperson@dom.ain
02139 To: bperson@dom.ain
02140 Subject: Test
02141 Content-Type: multipart/mixed; boundary="BOUNDARY"
02142 
02143 MIME message
02144 --BOUNDARY
02145 Content-Type: text/plain; charset="us-ascii"
02146 MIME-Version: 1.0
02147 Content-Transfer-Encoding: 7bit
02148 
02149 One
02150 --BOUNDARY
02151 Content-Type: text/plain; charset="us-ascii"
02152 MIME-Version: 1.0
02153 Content-Transfer-Encoding: 7bit
02154 
02155 Two
02156 --BOUNDARY--
02157 """)

Here is the call graph for this function:

Definition at line 2032 of file test_email.py.

02032 
02033     def test_parse_message_rfc822(self):
02034         eq = self.assertEqual
02035         unless = self.assertTrue
02036         msg = self._msgobj('msg_11.txt')
02037         eq(msg.get_content_type(), 'message/rfc822')
02038         payload = msg.get_payload()
02039         unless(isinstance(payload, list))
02040         eq(len(payload), 1)
02041         submsg = payload[0]
02042         self.assertTrue(isinstance(submsg, Message))
02043         eq(submsg['subject'], 'An enclosed message')
02044         eq(submsg.get_payload(), 'Here is the body of the message.\n')

Here is the call graph for this function:

Definition at line 1985 of file test_email.py.

01985 
01986     def test_type_error(self):
01987         self.assertRaises(TypeError, MIMEMessage, 'a plain string')

Here is the call graph for this function:

Definition at line 1988 of file test_email.py.

01988 
01989     def test_valid_argument(self):
01990         eq = self.assertEqual
01991         unless = self.assertTrue
01992         subject = 'A sub-message'
01993         m = Message()
01994         m['Subject'] = subject
01995         r = MIMEMessage(m)
01996         eq(r.get_content_type(), 'message/rfc822')
01997         payload = r.get_payload()
01998         unless(isinstance(payload, list))
01999         eq(len(payload), 1)
02000         subpart = payload[0]
02001         unless(subpart is m)
02002         eq(subpart['subject'], subject)

Here is the call graph for this function:


Member Data Documentation

Definition at line 1983 of file test_email.py.


The documentation for this class was generated from the following file: