mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Fix mixup between httplib and urllib3
This commit is contained in:
@@ -5,8 +5,10 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import pytest_httpbin
|
import pytest_httpbin
|
||||||
import vcr
|
import vcr
|
||||||
|
from vcr.patch import force_reset
|
||||||
from assertions import assert_cassette_empty, assert_is_json
|
from assertions import assert_cassette_empty, assert_is_json
|
||||||
urllib3 = pytest.importorskip("urllib3")
|
urllib3 = pytest.importorskip("urllib3")
|
||||||
|
cpool = pytest.importorskip("urllib3.connectionpool")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module')
|
@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):
|
def test_https_with_cert_validation_disabled(tmpdir, httpbin_secure, pool_mgr):
|
||||||
with vcr.use_cassette(str(tmpdir.join('cert_validation_disabled.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('cert_validation_disabled.yaml'))):
|
||||||
pool_mgr.request('GET', httpbin_secure.url)
|
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
|
||||||
|
|||||||
@@ -386,11 +386,11 @@ def reset_patchers():
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
yield mock.patch.object(cpool, 'VerifiedHTTPSConnection', _VerifiedHTTPSConnection)
|
yield mock.patch.object(cpool, 'VerifiedHTTPSConnection', _VerifiedHTTPSConnection)
|
||||||
yield mock.patch.object(cpool, 'HTTPConnection', _HTTPConnection)
|
yield mock.patch.object(cpool, 'HTTPConnection', _cpoolHTTPConnection)
|
||||||
yield mock.patch.object(cpool, 'HTTPSConnection', _HTTPSConnection)
|
yield mock.patch.object(cpool, 'HTTPSConnection', _cpoolHTTPSConnection)
|
||||||
if hasattr(cpool.HTTPConnectionPool, 'ConnectionCls'):
|
if hasattr(cpool.HTTPConnectionPool, 'ConnectionCls'):
|
||||||
yield mock.patch.object(cpool.HTTPConnectionPool, 'ConnectionCls', _HTTPConnection)
|
yield mock.patch.object(cpool.HTTPConnectionPool, 'ConnectionCls', _cpoolHTTPConnection)
|
||||||
yield mock.patch.object(cpool.HTTPSConnectionPool, 'ConnectionCls', _HTTPSConnection)
|
yield mock.patch.object(cpool.HTTPSConnectionPool, 'ConnectionCls', _cpoolHTTPSConnection)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import botocore.vendored.requests.packages.urllib3.connectionpool as cpool
|
import botocore.vendored.requests.packages.urllib3.connectionpool as cpool
|
||||||
|
|||||||
Reference in New Issue
Block a user