mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -16,6 +16,7 @@ env:
|
||||
- TOX_SUFFIX="requests211"
|
||||
- TOX_SUFFIX="requests213"
|
||||
- TOX_SUFFIX="requests216"
|
||||
- TOX_SUFFIX="requests218"
|
||||
- TOX_SUFFIX="requests1"
|
||||
- TOX_SUFFIX="httplib2"
|
||||
- TOX_SUFFIX="boto"
|
||||
|
||||
@@ -57,7 +57,7 @@ once
|
||||
file.
|
||||
|
||||
It is similar to the new\_episodes record mode, but will prevent new,
|
||||
unexpected requests from being made (i.e. because the request URI
|
||||
unexpected requests from being made (e.g. because the request URI
|
||||
changed).
|
||||
|
||||
once is the default record mode, used when you do not set one.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
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")
|
||||
|
||||
@@ -138,3 +139,21 @@ 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():
|
||||
cpool = urllib3.connectionpool
|
||||
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
|
||||
|
||||
3
tox.ini
3
tox.ini
@@ -1,5 +1,5 @@
|
||||
[tox]
|
||||
envlist = {py26,py27,py35,py36,pypy,pypy3}-{flakes,requests216,requests213,requests211,requests27,requests26,requests25,requests24,requests23,requests22,requests1,httplib2,urllib319,urllib3110,urllib3121,tornado3,tornado4,boto,boto3,aiohttp}
|
||||
envlist = {py26,py27,py35,py36,pypy,pypy3}-{flakes,requests218,requests216,requests213,requests211,requests27,requests26,requests25,requests24,requests23,requests22,requests1,httplib2,urllib319,urllib3110,urllib3121,tornado3,tornado4,boto,boto3,aiohttp}
|
||||
|
||||
[testenv:flakes]
|
||||
skipsdist = True
|
||||
@@ -20,6 +20,7 @@ deps =
|
||||
pytest-httpbin
|
||||
PyYAML
|
||||
requests1: requests==1.2.3
|
||||
requests218: requests==2.18.4
|
||||
requests216: requests==2.16.3
|
||||
requests213: requests==2.13.0
|
||||
requests211: requests==2.11.1
|
||||
|
||||
24
vcr/patch.py
24
vcr/patch.py
@@ -362,8 +362,22 @@ class ConnectionRemover(object):
|
||||
def reset_patchers():
|
||||
yield mock.patch.object(httplib, 'HTTPConnection', _HTTPConnection)
|
||||
yield mock.patch.object(httplib, 'HTTPSConnection', _HTTPSConnection)
|
||||
|
||||
try:
|
||||
import requests.packages.urllib3.connectionpool as cpool
|
||||
import requests
|
||||
if requests.__build__ < 0x021603:
|
||||
# Avoid double unmock if requests 2.16.3
|
||||
# First, this is pointless, requests.packages.urllib3 *IS* urllib3 (see packages.py)
|
||||
# Second, this is unmocking twice the same classes with different namespaces
|
||||
# and is creating weird issues and bugs:
|
||||
# > AssertionError: assert <class 'urllib3.connection.HTTPConnection'>
|
||||
# > is <class 'requests.packages.urllib3.connection.HTTPConnection'>
|
||||
# This assert should work!!!
|
||||
# Note that this also means that now, requests.packages is never imported
|
||||
# if requests 2.16.3 or greater is used with VCRPy.
|
||||
import requests.packages.urllib3.connectionpool as cpool
|
||||
else:
|
||||
raise ImportError("Skip requests not vendored anymore")
|
||||
except ImportError: # pragma: no cover
|
||||
pass
|
||||
else:
|
||||
@@ -386,11 +400,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
|
||||
|
||||
Reference in New Issue
Block a user