Kaydet (Commit) 6a9e6bbf authored tarafından Richard Jones's avatar Richard Jones

fix test_smtplib/test_smtpd collision through pre-loaded reply data in mock_socket

üst 62f68ed3
...@@ -36,6 +36,7 @@ class MockSocket: ...@@ -36,6 +36,7 @@ class MockSocket:
self.lines = [] self.lines = []
if _reply_data: if _reply_data:
self.lines.append(_reply_data) self.lines.append(_reply_data)
_reply_data = None
self.conn = None self.conn = None
self.timeout = None self.timeout = None
......
...@@ -189,8 +189,8 @@ class SMTPDChannelTest(TestCase): ...@@ -189,8 +189,8 @@ class SMTPDChannelTest(TestCase):
self.write_line(b'RCPT To:ham@example') self.write_line(b'RCPT To:ham@example')
self.write_line(b'DATA') self.write_line(b'DATA')
self.write_line(b'data\r\n.') self.write_line(b'data\r\n.')
self.assertEqual(self.server.messages[-1], self.assertEqual(self.server.messages,
('peer', 'eggs@example', ['spam@example','ham@example'], 'data')) [('peer', 'eggs@example', ['spam@example','ham@example'], 'data')])
def test_manual_status(self): def test_manual_status(self):
# checks that the Channel is able to return a custom status message # checks that the Channel is able to return a custom status message
...@@ -209,8 +209,8 @@ class SMTPDChannelTest(TestCase): ...@@ -209,8 +209,8 @@ class SMTPDChannelTest(TestCase):
self.write_line(b'RCPT To:eggs@example') self.write_line(b'RCPT To:eggs@example')
self.write_line(b'DATA') self.write_line(b'DATA')
self.write_line(b'data\r\n.') self.write_line(b'data\r\n.')
self.assertEqual(self.server.messages[0], self.assertEqual(self.server.messages,
('peer', 'foo@example', ['eggs@example'], 'data')) [('peer', 'foo@example', ['eggs@example'], 'data')])
def test_RSET_syntax(self): def test_RSET_syntax(self):
self.write_line(b'RSET hi') self.write_line(b'RSET hi')
......
...@@ -64,17 +64,20 @@ class GeneralTests(unittest.TestCase): ...@@ -64,17 +64,20 @@ class GeneralTests(unittest.TestCase):
smtp.close() smtp.close()
def testBasic2(self): def testBasic2(self):
mock_socket.reply_with(b"220 Hola mundo")
# connects, include port in host name # connects, include port in host name
smtp = smtplib.SMTP("%s:%s" % (HOST, self.port)) smtp = smtplib.SMTP("%s:%s" % (HOST, self.port))
smtp.close() smtp.close()
def testLocalHostName(self): def testLocalHostName(self):
mock_socket.reply_with(b"220 Hola mundo")
# check that supplied local_hostname is used # check that supplied local_hostname is used
smtp = smtplib.SMTP(HOST, self.port, local_hostname="testhost") smtp = smtplib.SMTP(HOST, self.port, local_hostname="testhost")
self.assertEqual(smtp.local_hostname, "testhost") self.assertEqual(smtp.local_hostname, "testhost")
smtp.close() smtp.close()
def testTimeoutDefault(self): def testTimeoutDefault(self):
mock_socket.reply_with(b"220 Hola mundo")
self.assertTrue(mock_socket.getdefaulttimeout() is None) self.assertTrue(mock_socket.getdefaulttimeout() is None)
mock_socket.setdefaulttimeout(30) mock_socket.setdefaulttimeout(30)
self.assertEqual(mock_socket.getdefaulttimeout(), 30) self.assertEqual(mock_socket.getdefaulttimeout(), 30)
...@@ -86,6 +89,7 @@ class GeneralTests(unittest.TestCase): ...@@ -86,6 +89,7 @@ class GeneralTests(unittest.TestCase):
smtp.close() smtp.close()
def testTimeoutNone(self): def testTimeoutNone(self):
mock_socket.reply_with(b"220 Hola mundo")
self.assertTrue(socket.getdefaulttimeout() is None) self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30) socket.setdefaulttimeout(30)
try: try:
...@@ -96,6 +100,7 @@ class GeneralTests(unittest.TestCase): ...@@ -96,6 +100,7 @@ class GeneralTests(unittest.TestCase):
smtp.close() smtp.close()
def testTimeoutValue(self): def testTimeoutValue(self):
mock_socket.reply_with(b"220 Hola mundo")
smtp = smtplib.SMTP(HOST, self.port, timeout=30) smtp = smtplib.SMTP(HOST, self.port, timeout=30)
self.assertEqual(smtp.sock.gettimeout(), 30) self.assertEqual(smtp.sock.gettimeout(), 30)
smtp.close() smtp.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment