]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Fix mixup between httplib and urllib3
authorLaurent Mazuel <lmazuel@microsoft.com>
Tue, 15 Aug 2017 23:39:33 +0000 (16:39 -0700)
committerLaurent Mazuel <lmazuel@microsoft.com>
Thu, 17 Aug 2017 15:37:11 +0000 (08:37 -0700)
tests/integration/test_urllib3.py
vcr/patch.py

index 0c02c40c56817346f989dbac1b4d399171f067e0..2884d3564783e2b2ca66033fc05e34f09900ecf6 100644 (file)
@@ -5,8 +5,10 @@
 import pytest
 import pytest_httpbin
 import vcr
+from vcr.patch import force_reset
 from assertions import assert_cassette_empty, assert_is_json
 urllib3 = pytest.importorskip("urllib3")
+cpool = pytest.importorskip("urllib3.connectionpool")
 
 
 @pytest.fixture(scope='module')
@@ -138,3 +140,20 @@ def test_gzip(tmpdir, httpbin_both, verify_pool_mgr):
 def test_https_with_cert_validation_disabled(tmpdir, httpbin_secure, pool_mgr):
     with vcr.use_cassette(str(tmpdir.join('cert_validation_disabled.yaml'))):
         pool_mgr.request('GET', httpbin_secure.url)
+
+
+def test_urllib3_force_reset():
+    http_original = cpool.HTTPConnection
+    https_original = cpool.HTTPSConnection
+    verified_https_original = cpool.VerifiedHTTPSConnection
+    with vcr.use_cassette(path='test'):
+        first_cassette_HTTPConnection = cpool.HTTPConnection
+        first_cassette_HTTPSConnection = cpool.HTTPSConnection
+        first_cassette_VerifiedHTTPSConnection = cpool.VerifiedHTTPSConnection
+        with force_reset():
+            assert cpool.HTTPConnection is http_original
+            assert cpool.HTTPSConnection is https_original
+            assert cpool.VerifiedHTTPSConnection is verified_https_original
+        assert cpool.HTTPConnection is first_cassette_HTTPConnection
+        assert cpool.HTTPSConnection is first_cassette_HTTPSConnection
+        assert cpool.VerifiedHTTPSConnection is first_cassette_VerifiedHTTPSConnection
index bc93ad98522304389caef884e5466ea88a473d52..434e45cf5fa98c36324c18fd41f3501619f025cb 100644 (file)
@@ -386,11 +386,11 @@ def reset_patchers():
         pass
     else:
         yield mock.patch.object(cpool, 'VerifiedHTTPSConnection', _VerifiedHTTPSConnection)
-        yield mock.patch.object(cpool, 'HTTPConnection', _HTTPConnection)
-        yield mock.patch.object(cpool, 'HTTPSConnection', _HTTPSConnection)
+        yield mock.patch.object(cpool, 'HTTPConnection', _cpoolHTTPConnection)
+        yield mock.patch.object(cpool, 'HTTPSConnection', _cpoolHTTPSConnection)
         if hasattr(cpool.HTTPConnectionPool, 'ConnectionCls'):
-            yield mock.patch.object(cpool.HTTPConnectionPool, 'ConnectionCls', _HTTPConnection)
-            yield mock.patch.object(cpool.HTTPSConnectionPool, 'ConnectionCls', _HTTPSConnection)
+            yield mock.patch.object(cpool.HTTPConnectionPool, 'ConnectionCls', _cpoolHTTPConnection)
+            yield mock.patch.object(cpool.HTTPSConnectionPool, 'ConnectionCls', _cpoolHTTPSConnection)
 
     try:
         import botocore.vendored.requests.packages.urllib3.connectionpool as cpool