mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -16,6 +16,7 @@ env:
|
|||||||
- TOX_SUFFIX="requests211"
|
- TOX_SUFFIX="requests211"
|
||||||
- TOX_SUFFIX="requests213"
|
- TOX_SUFFIX="requests213"
|
||||||
- TOX_SUFFIX="requests216"
|
- TOX_SUFFIX="requests216"
|
||||||
|
- TOX_SUFFIX="requests218"
|
||||||
- TOX_SUFFIX="requests1"
|
- TOX_SUFFIX="requests1"
|
||||||
- TOX_SUFFIX="httplib2"
|
- TOX_SUFFIX="httplib2"
|
||||||
- TOX_SUFFIX="boto"
|
- TOX_SUFFIX="boto"
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ once
|
|||||||
file.
|
file.
|
||||||
|
|
||||||
It is similar to the new\_episodes record mode, but will prevent new,
|
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).
|
changed).
|
||||||
|
|
||||||
once is the default record mode, used when you do not set one.
|
once is the default record mode, used when you do not set one.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
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")
|
||||||
|
|
||||||
@@ -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):
|
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():
|
||||||
|
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]
|
[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]
|
[testenv:flakes]
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
@@ -20,6 +20,7 @@ deps =
|
|||||||
pytest-httpbin
|
pytest-httpbin
|
||||||
PyYAML
|
PyYAML
|
||||||
requests1: requests==1.2.3
|
requests1: requests==1.2.3
|
||||||
|
requests218: requests==2.18.4
|
||||||
requests216: requests==2.16.3
|
requests216: requests==2.16.3
|
||||||
requests213: requests==2.13.0
|
requests213: requests==2.13.0
|
||||||
requests211: requests==2.11.1
|
requests211: requests==2.11.1
|
||||||
|
|||||||
24
vcr/patch.py
24
vcr/patch.py
@@ -362,8 +362,22 @@ class ConnectionRemover(object):
|
|||||||
def reset_patchers():
|
def reset_patchers():
|
||||||
yield mock.patch.object(httplib, 'HTTPConnection', _HTTPConnection)
|
yield mock.patch.object(httplib, 'HTTPConnection', _HTTPConnection)
|
||||||
yield mock.patch.object(httplib, 'HTTPSConnection', _HTTPSConnection)
|
yield mock.patch.object(httplib, 'HTTPSConnection', _HTTPSConnection)
|
||||||
|
|
||||||
try:
|
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
|
except ImportError: # pragma: no cover
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -386,11 +400,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