mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bd3fbd2c6 | ||
|
|
cd715f37c6 | ||
|
|
9a1147196a | ||
|
|
a23c5d8508 | ||
|
|
868a974900 | ||
|
|
c56de472cd |
@@ -7,6 +7,7 @@ env:
|
||||
matrix:
|
||||
- WITH_LIB="requests2.2"
|
||||
- WITH_LIB="requests2.3"
|
||||
- WITH_LIB="requests2.4"
|
||||
- WITH_LIB="requests1.x"
|
||||
- WITH_LIB="httplib2"
|
||||
- WITH_LIB="boto"
|
||||
@@ -31,6 +32,7 @@ install:
|
||||
- if [ $WITH_LIB = "requests1.x" ] ; then pip install requests==1.2.3; fi
|
||||
- if [ $WITH_LIB = "requests2.2" ] ; then pip install requests==2.2.1; fi
|
||||
- if [ $WITH_LIB = "requests2.3" ] ; then pip install requests==2.3.0; fi
|
||||
- if [ $WITH_LIB = "requests2.4" ] ; then pip install requests==2.4.0; fi
|
||||
- if [ $WITH_LIB = "httplib2" ] ; then pip install httplib2; fi
|
||||
- if [ $WITH_LIB = "boto" ] ; then pip install boto; fi
|
||||
script: python setup.py test
|
||||
|
||||
@@ -51,7 +51,7 @@ You can also use VCR.py as a decorator. The same request above would look like
|
||||
this:
|
||||
|
||||
```python
|
||||
@vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml'):
|
||||
@vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml')
|
||||
def test_iana():
|
||||
response = urllib2.urlopen('http://www.iana.org/domains/reserved').read()
|
||||
assert 'Example domains' in response
|
||||
@@ -423,6 +423,8 @@ API in version 1.0.x
|
||||
|
||||
|
||||
## Changelog
|
||||
* 1.0.3: Fix an issue with requests 2.4 and make sure case sensitivity is
|
||||
consistent across python versions
|
||||
* 1.0.2: Fix an issue with requests 2.3
|
||||
* 1.0.1: Fix a bug with the new ignore requests feature and the once
|
||||
record mode
|
||||
|
||||
2
setup.py
2
setup.py
@@ -20,7 +20,7 @@ class PyTest(TestCommand):
|
||||
|
||||
setup(
|
||||
name='vcrpy',
|
||||
version='1.0.2',
|
||||
version='1.0.3',
|
||||
description=(
|
||||
"Automatically mock your HTTP interactions to simplify and "
|
||||
"speed up testing"
|
||||
|
||||
@@ -145,3 +145,7 @@ def test_session_and_connection_close(tmpdir, scheme):
|
||||
|
||||
resp = session.get('http://httpbin.org/get', headers={'Connection': 'close'})
|
||||
resp = session.get('http://httpbin.org/get', headers={'Connection': 'close'})
|
||||
|
||||
def test_https_with_cert_validation_disabled(tmpdir):
|
||||
with vcr.use_cassette(str(tmpdir.join('cert_validation_disabled.yaml'))):
|
||||
requests.get('https://httpbin.org', verify=False)
|
||||
|
||||
26
tests/integration/test_stubs.py
Normal file
26
tests/integration/test_stubs.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import vcr
|
||||
import six.moves.http_client as httplib
|
||||
|
||||
def _headers_are_case_insensitive():
|
||||
conn = httplib.HTTPConnection('httpbin.org')
|
||||
conn.request('GET', "/cookies/set?k1=v1")
|
||||
r1 = conn.getresponse()
|
||||
cookie_data1 = r1.getheader('set-cookie')
|
||||
conn = httplib.HTTPConnection('httpbin.org')
|
||||
conn.request('GET', "/cookies/set?k1=v1")
|
||||
r2 = conn.getresponse()
|
||||
cookie_data2 = r2.getheader('Set-Cookie')
|
||||
return cookie_data1 == cookie_data2
|
||||
|
||||
def test_case_insensitivity(tmpdir):
|
||||
testfile = str(tmpdir.join('case_insensitivity.yml'))
|
||||
# check if headers are case insensitive outside of vcrpy
|
||||
outside = _headers_are_case_insensitive()
|
||||
with vcr.use_cassette(testfile):
|
||||
# check if headers are case insensitive inside of vcrpy
|
||||
inside = _headers_are_case_insensitive()
|
||||
# check if headers are case insensitive after vcrpy deserializes headers
|
||||
inside2 = _headers_are_case_insensitive()
|
||||
|
||||
# behavior should be the same both inside and outside
|
||||
assert outside == inside == inside2
|
||||
50
tox.ini
50
tox.ini
@@ -10,6 +10,10 @@ envlist =
|
||||
py33,
|
||||
py34,
|
||||
pypy,
|
||||
py26requests24,
|
||||
py27requests24,
|
||||
py34requests24,
|
||||
pypyrequests24,
|
||||
py26requests23,
|
||||
py27requests23,
|
||||
py34requests23,
|
||||
@@ -73,6 +77,52 @@ deps =
|
||||
PyYAML
|
||||
requests==1.2.3
|
||||
|
||||
[testenv:py26requests24]
|
||||
basepython = python2.6
|
||||
deps =
|
||||
mock
|
||||
pytest
|
||||
pytest-localserver
|
||||
PyYAML
|
||||
requests==2.4.0
|
||||
|
||||
[testenv:py27requests24]
|
||||
basepython = python2.7
|
||||
deps =
|
||||
mock
|
||||
pytest
|
||||
pytest-localserver
|
||||
PyYAML
|
||||
requests==2.4.0
|
||||
|
||||
[testenv:py33requests24]
|
||||
basepython = python3.4
|
||||
deps =
|
||||
mock
|
||||
pytest
|
||||
pytest-localserver
|
||||
PyYAML
|
||||
requests==2.4.0
|
||||
|
||||
[testenv:py34requests24]
|
||||
basepython = python3.4
|
||||
deps =
|
||||
mock
|
||||
pytest
|
||||
pytest-localserver
|
||||
PyYAML
|
||||
requests==2.4.0
|
||||
|
||||
[testenv:pypyrequests24]
|
||||
basepython = pypy
|
||||
deps =
|
||||
mock
|
||||
pytest
|
||||
pytest-localserver
|
||||
PyYAML
|
||||
requests==2.4.0
|
||||
|
||||
|
||||
[testenv:py26requests23]
|
||||
basepython = python2.6
|
||||
deps =
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from __future__ import print_function
|
||||
from operator import itemgetter
|
||||
from heapq import nlargest
|
||||
from itertools import repeat, ifilter
|
||||
@@ -189,5 +190,5 @@ class Counter(dict):
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
print doctest.testmod()
|
||||
print(doctest.testmod())
|
||||
|
||||
|
||||
@@ -56,15 +56,16 @@ def install(cassette):
|
||||
# patch requests v1.x
|
||||
try:
|
||||
import requests.packages.urllib3.connectionpool as cpool
|
||||
from .stubs.requests_stubs import VCRVerifiedHTTPSConnection
|
||||
cpool.VerifiedHTTPSConnection = VCRVerifiedHTTPSConnection
|
||||
from .stubs.requests_stubs import VCRRequestsHTTPConnection, VCRRequestsHTTPSConnection
|
||||
cpool.VerifiedHTTPSConnection = VCRRequestsHTTPSConnection
|
||||
cpool.HTTPConnection = VCRRequestsHTTPConnection
|
||||
cpool.VerifiedHTTPSConnection.cassette = cassette
|
||||
cpool.HTTPConnection = VCRHTTPConnection
|
||||
cpool.HTTPConnection.cassette = cassette
|
||||
# patch requests v2.x
|
||||
cpool.HTTPConnectionPool.ConnectionCls = VCRHTTPConnection
|
||||
cpool.HTTPConnectionPool.ConnectionCls = VCRRequestsHTTPConnection
|
||||
cpool.HTTPConnectionPool.cassette = cassette
|
||||
cpool.HTTPSConnectionPool.ConnectionCls = VCRHTTPSConnection
|
||||
cpool.HTTPSConnectionPool.ConnectionCls = VCRRequestsHTTPSConnection
|
||||
cpool.HTTPSConnectionPool.cassette = cassette
|
||||
except ImportError: # pragma: no cover
|
||||
pass
|
||||
|
||||
@@ -111,8 +111,8 @@ class VCRHTTPResponse(HTTPResponse):
|
||||
return compat.get_header_items(message)
|
||||
|
||||
def getheader(self, header, default=None):
|
||||
headers = dict(((k, v) for k, v in self.getheaders()))
|
||||
return headers.get(header, default)
|
||||
headers = dict(((k.lower(), v) for k, v in self.getheaders()))
|
||||
return headers.get(header.lower(), default)
|
||||
|
||||
|
||||
class VCRConnection:
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
'''Stubs for requests'''
|
||||
|
||||
from requests.packages.urllib3.connectionpool import VerifiedHTTPSConnection
|
||||
from ..stubs import VCRHTTPSConnection
|
||||
from requests.packages.urllib3.connectionpool import HTTPConnection, VerifiedHTTPSConnection
|
||||
from ..stubs import VCRHTTPConnection, VCRHTTPSConnection
|
||||
|
||||
# urllib3 defines its own HTTPConnection classes, which requests goes ahead and assumes
|
||||
# you're using. It includes some polyfills for newer features missing in older pythons.
|
||||
|
||||
class VCRVerifiedHTTPSConnection(VCRHTTPSConnection, VerifiedHTTPSConnection):
|
||||
class VCRRequestsHTTPConnection(VCRHTTPConnection, HTTPConnection):
|
||||
_baseclass = HTTPConnection
|
||||
|
||||
class VCRRequestsHTTPSConnection(VCRHTTPSConnection, VerifiedHTTPSConnection):
|
||||
_baseclass = VerifiedHTTPSConnection
|
||||
|
||||
Reference in New Issue
Block a user