Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(169388)

Delta Between Two Patch Sets: Lib/test/test_smtplib.py

Issue 10321: Add support for Message objects and binary data to smtplib.sendmail
Left Patch Set: Created 8 years, 8 months ago
Right Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/smtplib.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import asyncore 1 import asyncore
2 import email.mime.text 2 import email.mime.text
3 import email.utils 3 import email.utils
4 import socket 4 import socket
5 import smtpd 5 import smtpd
6 import smtplib 6 import smtplib
7 import io 7 import io
8 import re 8 import re
9 import sys 9 import sys
10 import time 10 import time
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 self.client_evt.set() 275 self.client_evt.set()
276 self.serv_evt.wait() 276 self.serv_evt.wait()
277 self.output.flush() 277 self.output.flush()
278 mexpect = '%s%s\n%s' % (MSG_BEGIN, m.decode('ascii'), MSG_END) 278 mexpect = '%s%s\n%s' % (MSG_BEGIN, m.decode('ascii'), MSG_END)
279 self.assertEqual(self.output.getvalue(), mexpect) 279 self.assertEqual(self.output.getvalue(), mexpect)
280 280
281 def testSendMessage(self): 281 def testSendMessage(self):
282 m = email.mime.text.MIMEText('A test message') 282 m = email.mime.text.MIMEText('A test message')
283 smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout =3) 283 smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout =3)
284 smtp.sendmail('John', 'Sally', m) 284 smtp.send_message(m, from_addr='John', to_addrs='Sally')
285 # XXX (see comment in testSend) 285 # XXX (see comment in testSend)
286 time.sleep(0.01) 286 time.sleep(0.01)
287 smtp.quit() 287 smtp.quit()
288 288
289 self.client_evt.set() 289 self.client_evt.set()
290 self.serv_evt.wait() 290 self.serv_evt.wait()
291 self.output.flush() 291 self.output.flush()
292 # Add the X-Peer header that DebuggingServer adds 292 # Add the X-Peer header that DebuggingServer adds
293 # XXX: I'm not sure hardcoding this IP will work on linux-vserver. 293 # XXX: I'm not sure hardcoding this IP will work on linux-vserver.
294 m['X-Peer'] = '127.0.0.1' 294 m['X-Peer'] = '127.0.0.1'
295 mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END) 295 mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END)
296 self.assertEqual(self.output.getvalue(), mexpect) 296 self.assertEqual(self.output.getvalue(), mexpect)
297 297
298 def testSendMessageWithAddresses(self): 298 def testSendMessageWithAddresses(self):
299 m = email.mime.text.MIMEText('A test message') 299 m = email.mime.text.MIMEText('A test message')
300 m['From'] = 'foo@bar.com' 300 m['From'] = 'foo@bar.com'
301 m['To'] = 'John' 301 m['To'] = 'John'
302 m['CC'] = 'Sally, Fred' 302 m['CC'] = 'Sally, Fred'
303 m['Bcc'] = 'John Root <root@localhost>, "Dinsdale" <warped@silly.walks.c om>' 303 m['Bcc'] = 'John Root <root@localhost>, "Dinsdale" <warped@silly.walks.c om>'
304 smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout =3) 304 smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout =3)
305 smtp.sendmail(None, None, m) 305 smtp.send_message(m)
306 # XXX (see comment in testSend) 306 # XXX (see comment in testSend)
307 time.sleep(0.01) 307 time.sleep(0.01)
308 smtp.quit() 308 smtp.quit()
309 309
310 self.client_evt.set() 310 self.client_evt.set()
311 self.serv_evt.wait() 311 self.serv_evt.wait()
312 self.output.flush() 312 self.output.flush()
313 # Add the X-Peer header that DebuggingServer adds 313 # Add the X-Peer header that DebuggingServer adds
314 # XXX: I'm not sure hardcoding this IP will work on linux-vserver. 314 # XXX: I'm not sure hardcoding this IP will work on linux-vserver.
315 m['X-Peer'] = '127.0.0.1' 315 m['X-Peer'] = '127.0.0.1'
316 # The Bcc header is deleted before serialization. 316 # The Bcc header is deleted before serialization.
317 del m['Bcc'] 317 del m['Bcc']
318 mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END) 318 mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END)
319 self.assertEqual(self.output.getvalue(), mexpect) 319 self.assertEqual(self.output.getvalue(), mexpect)
320 debugout = smtpd.DEBUGSTREAM.getvalue() 320 debugout = smtpd.DEBUGSTREAM.getvalue()
321 sender = re.compile("^sender: foo@bar.com$", re.MULTILINE) 321 sender = re.compile("^sender: foo@bar.com$", re.MULTILINE)
322 self.assertRegexpMatches(debugout, sender) 322 self.assertRegexpMatches(debugout, sender)
323 for addr in ('John', 'Sally', 'Fred', 'root@localhost', 323 for addr in ('John', 'Sally', 'Fred', 'root@localhost',
324 'warped@silly.walks.com'): 324 'warped@silly.walks.com'):
325 to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr), 325 to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr),
326 re.MULTILINE) 326 re.MULTILINE)
327 self.assertRegexpMatches(debugout, to_addr) 327 self.assertRegexpMatches(debugout, to_addr)
328 328
329 def testSendMessageWithSomeAddresses(self): 329 def testSendMessageWithSomeAddresses(self):
330 # Make sure nothing breaks if not all of the three 'to' headers exist 330 # Make sure nothing breaks if not all of the three 'to' headers exist
331 m = email.mime.text.MIMEText('A test message') 331 m = email.mime.text.MIMEText('A test message')
332 m['From'] = 'foo@bar.com' 332 m['From'] = 'foo@bar.com'
333 m['To'] = 'John, Dinsdale' 333 m['To'] = 'John, Dinsdale'
334 smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout =3) 334 smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout =3)
335 smtp.sendmail(None, None, m) 335 smtp.send_message(m)
336 # XXX (see comment in testSend) 336 # XXX (see comment in testSend)
337 time.sleep(0.01) 337 time.sleep(0.01)
338 smtp.quit() 338 smtp.quit()
339 339
340 self.client_evt.set() 340 self.client_evt.set()
341 self.serv_evt.wait() 341 self.serv_evt.wait()
342 self.output.flush() 342 self.output.flush()
343 # Add the X-Peer header that DebuggingServer adds 343 # Add the X-Peer header that DebuggingServer adds
344 # XXX: I'm not sure hardcoding this IP will work on linux-vserver. 344 # XXX: I'm not sure hardcoding this IP will work on linux-vserver.
345 m['X-Peer'] = '127.0.0.1' 345 m['X-Peer'] = '127.0.0.1'
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 #test infrastructure can support it. 624 #test infrastructure can support it.
625 625
626 626
627 def test_main(verbose=None): 627 def test_main(verbose=None):
628 support.run_unittest(GeneralTests, DebuggingServerTests, 628 support.run_unittest(GeneralTests, DebuggingServerTests,
629 NonConnectingTests, 629 NonConnectingTests,
630 BadHELOServerTests, SMTPSimTests) 630 BadHELOServerTests, SMTPSimTests)
631 631
632 if __name__ == '__main__': 632 if __name__ == '__main__':
633 test_main() 633 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+