MCPcopy Index your code
hub / github.com/python/cpython / testSendMessageWithAddresses

Method testSendMessageWithAddresses

Lib/test/test_smtplib.py:516–550  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

514 self.assertEqual(test_output, mexpect)
515
516 def testSendMessageWithAddresses(self):
517 m = email.mime.text.MIMEText('A test message')
518 m['From'] = 'foo@bar.com'
519 m['To'] = 'John'
520 m['CC'] = 'Sally, Fred'
521 m['Bcc'] = 'John Root <root@localhost>, "Dinsdale" <warped@silly.walks.com>'
522 smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost',
523 timeout=support.LOOPBACK_TIMEOUT)
524 self.addCleanup(smtp.close)
525 smtp.send_message(m)
526 # XXX (see comment in testSend)
527 time.sleep(0.01)
528 smtp.quit()
529 # make sure the Bcc header is still in the message.
530 self.assertEqual(m['Bcc'], 'John Root <root@localhost>, "Dinsdale" '
531 '<warped@silly.walks.com>')
532
533 self.client_evt.set()
534 self.serv_evt.wait()
535 self.output.flush()
536 # Remove the X-Peer header that DebuggingServer adds.
537 test_output = self.get_output_without_xpeer()
538 del m['X-Peer']
539 # The Bcc header should not be transmitted.
540 del m['Bcc']
541 mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END)
542 self.assertEqual(test_output, mexpect)
543 debugout = smtpd.DEBUGSTREAM.getvalue()
544 sender = re.compile("^sender: foo@bar.com$", re.MULTILINE)
545 self.assertRegex(debugout, sender)
546 for addr in ('John', 'Sally', 'Fred', 'root@localhost',
547 'warped@silly.walks.com'):
548 to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr),
549 re.MULTILINE)
550 self.assertRegex(debugout, to_addr)
551
552 def testSendMessageWithSomeAddresses(self):
553 # Make sure nothing breaks if not all of the three 'to' headers exist

Callers

nothing calls this directly

Calls 14

send_messageMethod · 0.95
quitMethod · 0.95
addCleanupMethod · 0.80
assertRegexMethod · 0.80
sleepMethod · 0.45
assertEqualMethod · 0.45
setMethod · 0.45
waitMethod · 0.45
flushMethod · 0.45
as_stringMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected