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

Unified Diff: Lib/test/test_smtplib.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_signal.py ('k') | Lib/test/test_socketserver.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_smtplib.py Tue Jul 26 09:37:46 2011 +0300
+++ b/Lib/test/test_smtplib.py Mon Jul 25 09:47:18 2011 -0400
@@ -293,23 +293,6 @@
mexpect = '%s%s\n%s' % (MSG_BEGIN, m, MSG_END)
self.assertEqual(self.output.getvalue(), mexpect)
- def testSendNullSender(self):
- m = 'A test message'
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
- smtp.sendmail('<>', 'Sally', m)
- # XXX (see comment in testSend)
- time.sleep(0.01)
- smtp.quit()
-
- self.client_evt.set()
- self.serv_evt.wait()
- self.output.flush()
- mexpect = '%s%s\n%s' % (MSG_BEGIN, m, MSG_END)
- self.assertEqual(self.output.getvalue(), mexpect)
- debugout = smtpd.DEBUGSTREAM.getvalue()
- sender = re.compile("^sender: <>$", re.MULTILINE)
- self.assertRegex(debugout, sender)
-
def testSendMessage(self):
m = email.mime.text.MIMEText('A test message')
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
@@ -337,16 +320,13 @@
# XXX (see comment in testSend)
time.sleep(0.01)
smtp.quit()
- # make sure the Bcc header is still in the message.
- self.assertEqual(m['Bcc'], 'John Root <root@localhost>, "Dinsdale" '
- '<warped@silly.walks.com>')
self.client_evt.set()
self.serv_evt.wait()
self.output.flush()
# Add the X-Peer header that DebuggingServer adds
m['X-Peer'] = socket.gethostbyname('localhost')
- # The Bcc header should not be transmitted.
+ # The Bcc header is deleted before serialization.
del m['Bcc']
mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END)
self.assertEqual(self.output.getvalue(), mexpect)
@@ -385,112 +365,6 @@
re.MULTILINE)
self.assertRegex(debugout, to_addr)
- def testSendMessageWithSpecifiedAddresses(self):
- # Make sure addresses specified in call override those in message.
- m = email.mime.text.MIMEText('A test message')
- m['From'] = 'foo@bar.com'
- m['To'] = 'John, Dinsdale'
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
- smtp.send_message(m, from_addr='joe@example.com', to_addrs='foo@example.net')
- # XXX (see comment in testSend)
- time.sleep(0.01)
- smtp.quit()
-
- self.client_evt.set()
- self.serv_evt.wait()
- self.output.flush()
- # Add the X-Peer header that DebuggingServer adds
- m['X-Peer'] = socket.gethostbyname('localhost')
- mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END)
- self.assertEqual(self.output.getvalue(), mexpect)
- debugout = smtpd.DEBUGSTREAM.getvalue()
- sender = re.compile("^sender: joe@example.com$", re.MULTILINE)
- self.assertRegex(debugout, sender)
- for addr in ('John', 'Dinsdale'):
- to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr),
- re.MULTILINE)
- self.assertNotRegex(debugout, to_addr)
- recip = re.compile(r"^recips: .*'foo@example.net'.*$", re.MULTILINE)
- self.assertRegex(debugout, recip)
-
- def testSendMessageWithMultipleFrom(self):
- # Sender overrides To
- m = email.mime.text.MIMEText('A test message')
- m['From'] = 'Bernard, Bianca'
- m['Sender'] = 'the_rescuers@Rescue-Aid-Society.com'
- m['To'] = 'John, Dinsdale'
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
- smtp.send_message(m)
- # XXX (see comment in testSend)
- time.sleep(0.01)
- smtp.quit()
-
- self.client_evt.set()
- self.serv_evt.wait()
- self.output.flush()
- # Add the X-Peer header that DebuggingServer adds
- m['X-Peer'] = socket.gethostbyname('localhost')
- mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END)
- self.assertEqual(self.output.getvalue(), mexpect)
- debugout = smtpd.DEBUGSTREAM.getvalue()
- sender = re.compile("^sender: the_rescuers@Rescue-Aid-Society.com$", re.MULTILINE)
- self.assertRegex(debugout, sender)
- for addr in ('John', 'Dinsdale'):
- to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr),
- re.MULTILINE)
- self.assertRegex(debugout, to_addr)
-
- def testSendMessageResent(self):
- m = email.mime.text.MIMEText('A test message')
- m['From'] = 'foo@bar.com'
- m['To'] = 'John'
- m['CC'] = 'Sally, Fred'
- m['Bcc'] = 'John Root <root@localhost>, "Dinsdale" <warped@silly.walks.com>'
- m['Resent-Date'] = 'Thu, 1 Jan 1970 17:42:00 +0000'
- m['Resent-From'] = 'holy@grail.net'
- m['Resent-To'] = 'Martha <my_mom@great.cooker.com>, Jeff'
- m['Resent-Bcc'] = 'doe@losthope.net'
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
- smtp.send_message(m)
- # XXX (see comment in testSend)
- time.sleep(0.01)
- smtp.quit()
-
- self.client_evt.set()
- self.serv_evt.wait()
- self.output.flush()
- # The Resent-Bcc headers are deleted before serialization.
- del m['Bcc']
- del m['Resent-Bcc']
- # Add the X-Peer header that DebuggingServer adds
- m['X-Peer'] = socket.gethostbyname('localhost')
- mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END)
- self.assertEqual(self.output.getvalue(), mexpect)
- debugout = smtpd.DEBUGSTREAM.getvalue()
- sender = re.compile("^sender: holy@grail.net$", re.MULTILINE)
- self.assertRegex(debugout, sender)
- for addr in ('my_mom@great.cooker.com', 'Jeff', 'doe@losthope.net'):
- to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr),
- re.MULTILINE)
- self.assertRegex(debugout, to_addr)
-
- def testSendMessageMultipleResentRaises(self):
- m = email.mime.text.MIMEText('A test message')
- m['From'] = 'foo@bar.com'
- m['To'] = 'John'
- m['CC'] = 'Sally, Fred'
- m['Bcc'] = 'John Root <root@localhost>, "Dinsdale" <warped@silly.walks.com>'
- m['Resent-Date'] = 'Thu, 1 Jan 1970 17:42:00 +0000'
- m['Resent-From'] = 'holy@grail.net'
- m['Resent-To'] = 'Martha <my_mom@great.cooker.com>, Jeff'
- m['Resent-Bcc'] = 'doe@losthope.net'
- m['Resent-Date'] = 'Thu, 2 Jan 1970 17:42:00 +0000'
- m['Resent-To'] = 'holy@grail.net'
- m['Resent-From'] = 'Martha <my_mom@great.cooker.com>, Jeff'
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
- with self.assertRaises(ValueError):
- smtp.send_message(m)
- smtp.close()
class NonConnectingTests(unittest.TestCase):
@@ -540,7 +414,7 @@
sim_users = {'Mr.A@somewhere.com':'John A',
- 'Ms.B@xn--fo-fka.com':'Sally B',
+ 'Ms.B@somewhere.com':'Sally B',
'Mrs.C@somewhereesle.com':'Ruth C',
}
@@ -556,7 +430,7 @@
sim_auth_login_password = 'C29TZXBHC3N3B3JK'
sim_lists = {'list-1':['Mr.A@somewhere.com','Mrs.C@somewhereesle.com'],
- 'list-2':['Ms.B@xn--fo-fka.com',],
+ 'list-2':['Ms.B@somewhere.com',],
}
# Simulated SMTP channel & server
@@ -580,14 +454,15 @@
self.push(resp)
def smtp_VRFY(self, arg):
- # For max compatibility smtplib should be sending the raw address.
- if arg in sim_users:
- self.push('250 %s %s' % (sim_users[arg], smtplib.quoteaddr(arg)))
+ raw_addr = email.utils.parseaddr(arg)[1]
+ quoted_addr = smtplib.quoteaddr(arg)
+ if raw_addr in sim_users:
+ self.push('250 %s %s' % (sim_users[raw_addr], quoted_addr))
else:
self.push('550 No such user: %s' % arg)
def smtp_EXPN(self, arg):
- list_name = arg.lower()
+ list_name = email.utils.parseaddr(arg)[1].lower()
if list_name in sim_lists:
user_list = sim_lists[list_name]
for n, user_email in enumerate(user_list):
@@ -719,7 +594,8 @@
self.assertEqual(smtp.vrfy(email), expected_known)
u = 'nobody@nowhere.com'
- expected_unknown = (550, ('No such user: %s' % u).encode('ascii'))
+ expected_unknown = (550, ('No such user: %s'
+ % smtplib.quoteaddr(u)).encode('ascii'))
self.assertEqual(smtp.vrfy(u), expected_unknown)
smtp.quit()
« no previous file with comments | « Lib/test/test_signal.py ('k') | Lib/test/test_socketserver.py » ('j') | no next file with comments »

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