diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/mock_socket.py | 3 | ||||
-rw-r--r-- | Lib/test/test_smtplib.py | 17 |
2 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/mock_socket.py b/Lib/test/mock_socket.py index 8036932..d09e78c 100644 --- a/Lib/test/mock_socket.py +++ b/Lib/test/mock_socket.py @@ -106,7 +106,8 @@ def socket(family=None, type=None, proto=None): return MockSocket() -def create_connection(address, timeout=socket_module._GLOBAL_DEFAULT_TIMEOUT): +def create_connection(address, timeout=socket_module._GLOBAL_DEFAULT_TIMEOUT, + source_address=None): try: int_port = int(address[1]) except ValueError: diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index 9f8a054..70654c5 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -72,6 +72,14 @@ class GeneralTests(unittest.TestCase): smtp = smtplib.SMTP(HOST, self.port) smtp.close() + def testSourceAddress(self): + mock_socket.reply_with(b"220 Hola mundo") + # connects + smtp = smtplib.SMTP(HOST, self.port, + source_address=('127.0.0.1',19876)) + self.assertEqual(smtp.source_address, ('127.0.0.1', 19876)) + smtp.close() + def testBasic2(self): mock_socket.reply_with(b"220 Hola mundo") # connects, include port in host name @@ -206,6 +214,15 @@ class DebuggingServerTests(unittest.TestCase): smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.quit() + def testSourceAddress(self): + # connect + smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3, + source_address=('127.0.0.1', 19876)) + self.assertEqual(smtp.source_address, ('127.0.0.1', 19876)) + self.assertEqual(smtp.local_hostname, 'localhost') + print(dir(smtp)) + smtp.quit() + def testNOOP(self): smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) expected = (250, b'Ok') |