From 3b6d57e316bc932b6b1049b279ef849be32a8334 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Fri, 4 Oct 2013 17:49:51 +0200 Subject: Factor out HTTP(S)Connection -> ConnectionCls, and cleanup. Also removed the need to None-ify global `ssl` module in tests. --- test/with_dummyserver/test_https.py | 52 ++++++++++++------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) (limited to 'test/with_dummyserver/test_https.py') diff --git a/test/with_dummyserver/test_https.py b/test/with_dummyserver/test_https.py index 8e07f2f1..b99cb0d0 100644 --- a/test/with_dummyserver/test_https.py +++ b/test/with_dummyserver/test_https.py @@ -72,20 +72,14 @@ class TestHTTPS(HTTPSDummyServerTestCase): self.assertTrue("doesn't match" in str(e)) def test_no_ssl(self): - import urllib3.connectionpool - OriginalHTTPSConnection = urllib3.connectionpool.HTTPSConnection - OriginalSSL = urllib3.connectionpool.ssl - - urllib3.connectionpool.HTTPSConnection = None - urllib3.connectionpool.ssl = None + OriginalConnectionCls = self._pool.ConnectionCls + self._pool.ConnectionCls = None self.assertRaises(SSLError, self._pool._new_conn) - self.assertRaises(SSLError, self._pool.request, 'GET', '/') # Undo - urllib3.HTTPSConnection = OriginalHTTPSConnection - urllib3.connectionpool.ssl = OriginalSSL + self._pool.ConnectionCls = OriginalConnectionCls def test_cert_reqs_as_constant(self): https_pool = HTTPSConnectionPool(self.host, self.port, @@ -223,44 +217,35 @@ class TestHTTPS(HTTPSDummyServerTestCase): def test_enhanced_timeout(self): - import urllib3.connectionpool - OriginalHTTPSConnection = urllib3.connectionpool.HTTPSConnection - OriginalSSL = urllib3.connectionpool.ssl - - urllib3.connectionpool.ssl = None + def new_pool(timeout, cert_reqs='CERT_REQUIRED'): + https_pool = HTTPSConnectionPool(TARPIT_HOST, self.port, + timeout=timeout, + cert_reqs=cert_reqs) + return https_pool - timeout = Timeout(connect=0.001) - https_pool = HTTPSConnectionPool(TARPIT_HOST, self.port, - timeout=timeout, - cert_reqs='CERT_REQUIRED') + https_pool = new_pool(Timeout(connect=0.001)) conn = https_pool._new_conn() - self.assertEqual(conn.__class__, HTTPSConnection) self.assertRaises(ConnectTimeoutError, https_pool.request, 'GET', '/') self.assertRaises(ConnectTimeoutError, https_pool._make_request, conn, 'GET', '/') - timeout = Timeout(connect=5) - https_pool = HTTPSConnectionPool(TARPIT_HOST, self.port, - timeout=timeout, - cert_reqs='CERT_REQUIRED') + https_pool = new_pool(Timeout(connect=5)) self.assertRaises(ConnectTimeoutError, https_pool.request, 'GET', '/', timeout=Timeout(connect=0.001)) - timeout = Timeout(total=None) - https_pool = HTTPSConnectionPool(TARPIT_HOST, self.port, - timeout=timeout, - cert_reqs='CERT_REQUIRED') + t = Timeout(total=None) + https_pool = new_pool(t) conn = https_pool._new_conn() self.assertRaises(ConnectTimeoutError, https_pool.request, 'GET', '/', timeout=Timeout(total=None, connect=0.001)) - https_pool = HTTPSConnectionPool(self.host, self.port, - timeout=timeout, - cert_reqs='CERT_NONE') + # FIXME(kevinburke): What is this testing? It's currently broken. + """ + https_pool = new_pool(t, cert_reqs='CERT_NONE') conn = https_pool._new_conn() try: conn.set_tunnel(self.host, self.port) - except AttributeError: # python 2.6 + except AttributeError: # Python 2.6 conn._set_tunnel(self.host, self.port) conn._tunnel = mock.Mock() try: @@ -269,10 +254,7 @@ class TestHTTPS(HTTPSDummyServerTestCase): # wrap_socket unavailable when you mock out ssl pass conn._tunnel.assert_called_once_with() - - # Undo - urllib3.HTTPSConnection = OriginalHTTPSConnection - urllib3.connectionpool.ssl = OriginalSSL + """ def test_enhanced_ssl_connection(self): conn = VerifiedHTTPSConnection(self.host, self.port) -- cgit v1.2.1 From 33ecc78ebd2992d486f47dec100a9e30fcd1e11d Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Wed, 16 Oct 2013 11:23:28 +0200 Subject: New urllib3.connection module. --- test/with_dummyserver/test_https.py | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'test/with_dummyserver/test_https.py') diff --git a/test/with_dummyserver/test_https.py b/test/with_dummyserver/test_https.py index b99cb0d0..199bc973 100644 --- a/test/with_dummyserver/test_https.py +++ b/test/with_dummyserver/test_https.py @@ -239,23 +239,6 @@ class TestHTTPS(HTTPSDummyServerTestCase): self.assertRaises(ConnectTimeoutError, https_pool.request, 'GET', '/', timeout=Timeout(total=None, connect=0.001)) - # FIXME(kevinburke): What is this testing? It's currently broken. - """ - https_pool = new_pool(t, cert_reqs='CERT_NONE') - conn = https_pool._new_conn() - try: - conn.set_tunnel(self.host, self.port) - except AttributeError: # Python 2.6 - conn._set_tunnel(self.host, self.port) - conn._tunnel = mock.Mock() - try: - https_pool._make_request(conn, 'GET', '/') - except AttributeError: - # wrap_socket unavailable when you mock out ssl - pass - conn._tunnel.assert_called_once_with() - """ - def test_enhanced_ssl_connection(self): conn = VerifiedHTTPSConnection(self.host, self.port) https_pool = HTTPSConnectionPool(self.host, self.port, -- cgit v1.2.1