]> granicus.if.org Git - python/commitdiff
Merge from 3.2 (Issue #15095: Use better assertions in test_imaplib)
authorNick Coghlan <ncoghlan@gmail.com>
Sun, 17 Jun 2012 11:15:45 +0000 (21:15 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Sun, 17 Jun 2012 11:15:45 +0000 (21:15 +1000)
1  2 
Lib/test/test_imaplib.py

index 50b2da10df15db7bff34497375a697bb828d204c,5c99a58570ea5507b4d32c29fddfdafc00ffa481..e629cb1f66b6bd164fe9338bb3d4469440208043
@@@ -265,58 -265,11 +265,58 @@@ class RemoteIMAP_SSLTest(RemoteIMAPTest
      port = 993
      imap_class = IMAP4_SSL
  
-             self.assertFalse('LOGINDISABLED' in server.capabilities)
-             self.assertTrue('AUTH=PLAIN' in server.capabilities)
 +    def setUp(self):
 +        pass
 +
 +    def tearDown(self):
 +        pass
 +
 +    def create_ssl_context(self):
 +        ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
 +        ssl_context.load_cert_chain(CERTFILE)
 +        return ssl_context
 +
 +    def check_logincapa(self, server):
 +        try:
 +            for cap in server.capabilities:
 +                self.assertIsInstance(cap, str)
++            self.assertNotIn('LOGINDISABLED', server.capabilities)
++            self.assertIn('AUTH=PLAIN', server.capabilities)
 +            rs = server.login(self.username, self.password)
 +            self.assertEqual(rs[0], 'OK')
 +        finally:
 +            server.logout()
 +
      def test_logincapa(self):
 -        for cap in self.server.capabilities:
 -            self.assertIsInstance(cap, str)
 -        self.assertNotIn('LOGINDISABLED', self.server.capabilities)
 -        self.assertIn('AUTH=PLAIN', self.server.capabilities)
 +        with transient_internet(self.host):
 +            _server = self.imap_class(self.host, self.port)
 +            self.check_logincapa(_server)
 +
 +    def test_logincapa_with_client_certfile(self):
 +        with transient_internet(self.host):
 +            _server = self.imap_class(self.host, self.port, certfile=CERTFILE)
 +            self.check_logincapa(_server)
 +
 +    def test_logincapa_with_client_ssl_context(self):
 +        with transient_internet(self.host):
 +            _server = self.imap_class(self.host, self.port, ssl_context=self.create_ssl_context())
 +            self.check_logincapa(_server)
 +
 +    def test_logout(self):
 +        with transient_internet(self.host):
 +            _server = self.imap_class(self.host, self.port)
 +            rs = _server.logout()
 +            self.assertEqual(rs[0], 'BYE')
 +
 +    def test_ssl_context_certfile_exclusive(self):
 +        with transient_internet(self.host):
 +            self.assertRaises(ValueError, self.imap_class, self.host, self.port,
 +                              certfile=CERTFILE, ssl_context=self.create_ssl_context())
 +
 +    def test_ssl_context_keyfile_exclusive(self):
 +        with transient_internet(self.host):
 +            self.assertRaises(ValueError, self.imap_class, self.host, self.port,
 +                              keyfile=CERTFILE, ssl_context=self.create_ssl_context())
  
  
  def test_main():