summaryrefslogtreecommitdiff
path: root/Lib/test/test_smtpnet.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-05-18 18:03:09 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2011-05-18 18:03:09 +0200
commite065020680af75bb3b10fe1084c0273208a7f7f5 (patch)
treecee99e14841eac5c960cac56f08786a9f22d559b /Lib/test/test_smtpnet.py
parent5f3b1c4979fc03624b2f54ef8b156dd652b85c5c (diff)
downloadcpython-git-e065020680af75bb3b10fe1084c0273208a7f7f5.tar.gz
Issue #8809: The SMTP_SSL constructor and SMTP.starttls() now support
passing a `context` argument pointing to an ssl.SSLContext instance. Patch by Kasun Herath.
Diffstat (limited to 'Lib/test/test_smtpnet.py')
-rw-r--r--Lib/test/test_smtpnet.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_smtpnet.py b/Lib/test/test_smtpnet.py
index 0198ab669e..ca31c1efb0 100644
--- a/Lib/test/test_smtpnet.py
+++ b/Lib/test/test_smtpnet.py
@@ -3,12 +3,29 @@
import unittest
from test import support
import smtplib
+import ssl
support.requires("network")
+
+class SmtpTest(unittest.TestCase):
+ testServer = 'smtp.gmail.com'
+ remotePort = 25
+ context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+
+ def test_connect_starttls(self):
+ support.get_attribute(smtplib, 'SMTP_SSL')
+ with support.transient_internet(self.testServer):
+ server = smtplib.SMTP(self.testServer, self.remotePort)
+ server.starttls(context=self.context)
+ server.ehlo()
+ server.quit()
+
+
class SmtpSSLTest(unittest.TestCase):
testServer = 'smtp.gmail.com'
remotePort = 465
+ context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
def test_connect(self):
support.get_attribute(smtplib, 'SMTP_SSL')
@@ -24,8 +41,16 @@ class SmtpSSLTest(unittest.TestCase):
server.ehlo()
server.quit()
+ def test_connect_using_sslcontext(self):
+ support.get_attribute(smtplib, 'SMTP_SSL')
+ with support.transient_internet(self.testServer):
+ server = smtplib.SMTP_SSL(self.testServer, self.remotePort, context=self.context)
+ server.ehlo()
+ server.quit()
+
+
def test_main():
- support.run_unittest(SmtpSSLTest)
+ support.run_unittest(SmtpTest, SmtpSSLTest)
if __name__ == "__main__":
test_main()