Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Attributes
test.test_smtplib.SMTPSimTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def testBasic
def testEHLO
def testVRFY
def testEXPN
def testAUTH_PLAIN
def testAUTH_LOGIN
def testAUTH_CRAM_MD5

Public Attributes

 real_getfqdn
 serv_evt
 client_evt
 serv
 port
 thread

Private Attributes

 _threads

Detailed Description

Definition at line 642 of file test_smtplib.py.


Member Function Documentation

Definition at line 644 of file test_smtplib.py.

00644 
00645     def setUp(self):
00646         self.real_getfqdn = socket.getfqdn
00647         socket.getfqdn = mock_socket.getfqdn
00648         self._threads = support.threading_setup()
00649         self.serv_evt = threading.Event()
00650         self.client_evt = threading.Event()
00651         # Pick a random unused port by passing 0 for the port number
00652         self.serv = SimSMTPServer((HOST, 0), ('nowhere', -1))
00653         # Keep a note of what port was assigned
00654         self.port = self.serv.socket.getsockname()[1]
00655         serv_args = (self.serv, self.serv_evt, self.client_evt)
00656         self.thread = threading.Thread(target=debugging_server, args=serv_args)
00657         self.thread.start()
00658 
00659         # wait until server thread has assigned a port number
00660         self.serv_evt.wait()
00661         self.serv_evt.clear()

Here is the caller graph for this function:

Definition at line 662 of file test_smtplib.py.

00662 
00663     def tearDown(self):
00664         socket.getfqdn = self.real_getfqdn
00665         # indicate that the client is finished
00666         self.client_evt.set()
00667         # wait for the server thread to terminate
00668         self.serv_evt.wait()
00669         self.thread.join()
00670         support.threading_cleanup(*self._threads)

Here is the caller graph for this function:

Definition at line 750 of file test_smtplib.py.

00750 
00751     def testAUTH_CRAM_MD5(self):
00752         self.serv.add_feature("AUTH CRAM-MD5")
00753         smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
00754 
00755         try: smtp.login(sim_auth[0], sim_auth[1])
00756         except smtplib.SMTPAuthenticationError as err:
00757             self.assertIn(sim_auth_credentials['cram-md5'], str(err))
00758         smtp.close()

Here is the call graph for this function:

Definition at line 742 of file test_smtplib.py.

00742 
00743     def testAUTH_LOGIN(self):
00744         self.serv.add_feature("AUTH LOGIN")
00745         smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
00746         try: smtp.login(sim_auth[0], sim_auth[1])
00747         except smtplib.SMTPAuthenticationError as err:
00748             self.assertIn(sim_auth_login_password, str(err))
00749         smtp.close()

Here is the call graph for this function:

Definition at line 726 of file test_smtplib.py.

00726 
00727     def testAUTH_PLAIN(self):
00728         self.serv.add_feature("AUTH PLAIN")
00729         smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
00730 
00731         expected_auth_ok = (235, b'plain auth ok')
00732         self.assertEqual(smtp.login(sim_auth[0], sim_auth[1]), expected_auth_ok)
00733         smtp.close()

Here is the call graph for this function:

Definition at line 671 of file test_smtplib.py.

00671 
00672     def testBasic(self):
00673         # smoke test
00674         smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
00675         smtp.quit()

Definition at line 676 of file test_smtplib.py.

00676 
00677     def testEHLO(self):
00678         smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
00679 
00680         # no features should be present before the EHLO
00681         self.assertEqual(smtp.esmtp_features, {})
00682 
00683         # features expected from the test server
00684         expected_features = {'expn':'',
00685                              'size': '20000000',
00686                              'starttls': '',
00687                              'deliverby': '',
00688                              'help': '',
00689                              }
00690 
00691         smtp.ehlo()
00692         self.assertEqual(smtp.esmtp_features, expected_features)
00693         for k in expected_features:
00694             self.assertTrue(smtp.has_extn(k))
00695         self.assertFalse(smtp.has_extn('unsupported-feature'))
00696         smtp.quit()

Here is the call graph for this function:

Definition at line 711 of file test_smtplib.py.

00711 
00712     def testEXPN(self):
00713         smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
00714 
00715         for listname, members in sim_lists.items():
00716             users = []
00717             for m in members:
00718                 users.append('%s %s' % (sim_users[m], smtplib.quoteaddr(m)))
00719             expected_known = (250, bytes('\n'.join(users), "ascii"))
00720             self.assertEqual(smtp.expn(listname), expected_known)
00721 
00722         u = 'PSU-Members-List'
00723         expected_unknown = (550, b'No access for you!')
00724         self.assertEqual(smtp.expn(u), expected_unknown)
00725         smtp.quit()

Here is the call graph for this function:

Definition at line 697 of file test_smtplib.py.

00697 
00698     def testVRFY(self):
00699         smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
00700 
00701         for email, name in sim_users.items():
00702             expected_known = (250, bytes('%s %s' %
00703                                          (name, smtplib.quoteaddr(email)),
00704                                          "ascii"))
00705             self.assertEqual(smtp.vrfy(email), expected_known)
00706 
00707         u = 'nobody@nowhere.com'
00708         expected_unknown = (550, ('No such user: %s' % u).encode('ascii'))
00709         self.assertEqual(smtp.vrfy(u), expected_unknown)
00710         smtp.quit()

Here is the call graph for this function:


Member Data Documentation

Definition at line 647 of file test_smtplib.py.

Definition at line 649 of file test_smtplib.py.

Definition at line 653 of file test_smtplib.py.

Definition at line 645 of file test_smtplib.py.

Definition at line 651 of file test_smtplib.py.

Definition at line 648 of file test_smtplib.py.

Definition at line 655 of file test_smtplib.py.


The documentation for this class was generated from the following file: