mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Use {[testenv]deps}, instead of repeating testing requirements. Write another failing test for #109
This commit is contained in:
@@ -24,30 +24,30 @@ def scheme(request):
|
|||||||
def test_status_code(scheme, tmpdir):
|
def test_status_code(scheme, tmpdir):
|
||||||
'''Ensure that we can read the status code'''
|
'''Ensure that we can read the status code'''
|
||||||
url = scheme + '://httpbin.org/'
|
url = scheme + '://httpbin.org/'
|
||||||
with vcr.use_cassette(str(tmpdir.join('atts.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
|
||||||
status_code = requests.get(url).status_code
|
status_code = requests.get(url).status_code
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('atts.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('atts.yaml'))):
|
||||||
assert status_code == requests.get(url).status_code
|
assert status_code == requests.get(url).status_code
|
||||||
|
|
||||||
|
|
||||||
def test_headers(scheme, tmpdir):
|
def test_headers(scheme, tmpdir):
|
||||||
'''Ensure that we can read the headers back'''
|
'''Ensure that we can read the headers back'''
|
||||||
url = scheme + '://httpbin.org/'
|
url = scheme + '://httpbin.org/'
|
||||||
with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
|
||||||
headers = requests.get(url).headers
|
headers = requests.get(url).headers
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('headers.yaml'))):
|
||||||
assert headers == requests.get(url).headers
|
assert headers == requests.get(url).headers
|
||||||
|
|
||||||
|
|
||||||
def test_body(tmpdir, scheme):
|
def test_body(tmpdir, scheme):
|
||||||
'''Ensure the responses are all identical enough'''
|
'''Ensure the responses are all identical enough'''
|
||||||
url = scheme + '://httpbin.org/bytes/1024'
|
url = scheme + '://httpbin.org/bytes/1024'
|
||||||
with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
|
||||||
content = requests.get(url).content
|
content = requests.get(url).content
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('body.yaml'))):
|
||||||
assert content == requests.get(url).content
|
assert content == requests.get(url).content
|
||||||
|
|
||||||
|
|
||||||
@@ -55,10 +55,10 @@ def test_auth(tmpdir, scheme):
|
|||||||
'''Ensure that we can handle basic auth'''
|
'''Ensure that we can handle basic auth'''
|
||||||
auth = ('user', 'passwd')
|
auth = ('user', 'passwd')
|
||||||
url = scheme + '://httpbin.org/basic-auth/user/passwd'
|
url = scheme + '://httpbin.org/basic-auth/user/passwd'
|
||||||
with vcr.use_cassette(str(tmpdir.join('auth.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('auth.yaml'))):
|
||||||
one = requests.get(url, auth=auth)
|
one = requests.get(url, auth=auth)
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('auth.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('auth.yaml'))):
|
||||||
two = requests.get(url, auth=auth)
|
two = requests.get(url, auth=auth)
|
||||||
assert one.content == two.content
|
assert one.content == two.content
|
||||||
assert one.status_code == two.status_code
|
assert one.status_code == two.status_code
|
||||||
@@ -68,7 +68,7 @@ def test_auth_failed(tmpdir, scheme):
|
|||||||
'''Ensure that we can save failed auth statuses'''
|
'''Ensure that we can save failed auth statuses'''
|
||||||
auth = ('user', 'wrongwrongwrong')
|
auth = ('user', 'wrongwrongwrong')
|
||||||
url = scheme + '://httpbin.org/basic-auth/user/passwd'
|
url = scheme + '://httpbin.org/basic-auth/user/passwd'
|
||||||
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))):
|
||||||
# Ensure that this is empty to begin with
|
# Ensure that this is empty to begin with
|
||||||
assert_cassette_empty(cass)
|
assert_cassette_empty(cass)
|
||||||
one = requests.get(url, auth=auth)
|
one = requests.get(url, auth=auth)
|
||||||
@@ -81,10 +81,10 @@ def test_post(tmpdir, scheme):
|
|||||||
'''Ensure that we can post and cache the results'''
|
'''Ensure that we can post and cache the results'''
|
||||||
data = {'key1': 'value1', 'key2': 'value2'}
|
data = {'key1': 'value1', 'key2': 'value2'}
|
||||||
url = scheme + '://httpbin.org/post'
|
url = scheme + '://httpbin.org/post'
|
||||||
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))):
|
||||||
req1 = requests.post(url, data).content
|
req1 = requests.post(url, data).content
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))):
|
||||||
req2 = requests.post(url, data).content
|
req2 = requests.post(url, data).content
|
||||||
|
|
||||||
assert req1 == req2
|
assert req1 == req2
|
||||||
@@ -93,7 +93,7 @@ def test_post(tmpdir, scheme):
|
|||||||
def test_redirects(tmpdir, scheme):
|
def test_redirects(tmpdir, scheme):
|
||||||
'''Ensure that we can handle redirects'''
|
'''Ensure that we can handle redirects'''
|
||||||
url = scheme + '://httpbin.org/redirect-to?url=bytes/1024'
|
url = scheme + '://httpbin.org/redirect-to?url=bytes/1024'
|
||||||
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))):
|
||||||
content = requests.get(url).content
|
content = requests.get(url).content
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('requests.yaml'))) as cass:
|
||||||
@@ -124,11 +124,11 @@ def test_gzip(tmpdir, scheme):
|
|||||||
url = scheme + '://httpbin.org/gzip'
|
url = scheme + '://httpbin.org/gzip'
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))):
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
assert_is_json(response.content)
|
assert_is_json(response.content)
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))) as cass:
|
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))):
|
||||||
assert_is_json(response.content)
|
assert_is_json(response.content)
|
||||||
|
|
||||||
|
|
||||||
@@ -143,8 +143,8 @@ def test_session_and_connection_close(tmpdir, scheme):
|
|||||||
with vcr.use_cassette(str(tmpdir.join('session_connection_closed.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('session_connection_closed.yaml'))):
|
||||||
session = requests.session()
|
session = requests.session()
|
||||||
|
|
||||||
resp = session.get('http://httpbin.org/get', headers={'Connection': 'close'})
|
session.get('http://httpbin.org/get', headers={'Connection': 'close'})
|
||||||
resp = session.get('http://httpbin.org/get', headers={'Connection': 'close'})
|
session.get('http://httpbin.org/get', headers={'Connection': 'close'})
|
||||||
|
|
||||||
|
|
||||||
def test_https_with_cert_validation_disabled(tmpdir):
|
def test_https_with_cert_validation_disabled(tmpdir):
|
||||||
@@ -164,9 +164,28 @@ def test_session_can_make_requests_after_requests_unpatched(tmpdir):
|
|||||||
session.get('http://httpbin.org/status/200')
|
session.get('http://httpbin.org/status/200')
|
||||||
|
|
||||||
|
|
||||||
def test_nested_context_managers_with_session_created_before_first_nesting(scheme, tmpdir):
|
def test_session_created_before_use_cassette_is_patched(tmpdir, scheme):
|
||||||
|
url = scheme + '://httpbin.org/bytes/1024'
|
||||||
|
# Record arbitrary, random data to the cassette
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('session_created_outside.yaml'))):
|
||||||
|
session = requests.session()
|
||||||
|
body = session.get(url).content
|
||||||
|
|
||||||
|
# Create a session outside of any cassette context manager
|
||||||
|
session = requests.session()
|
||||||
|
# Make a request to make sure that a connectionpool is instantiated
|
||||||
|
session.get(scheme + '://httpbin.org/get')
|
||||||
|
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('session_created_outside.yaml'))):
|
||||||
|
# These should only be the same if the patching succeeded.
|
||||||
|
assert session.get(url).content == body
|
||||||
|
|
||||||
|
|
||||||
|
def test_nested_cassettes_with_session_created_before_nesting(scheme, tmpdir):
|
||||||
'''
|
'''
|
||||||
This tests ensures that a session that was created while one cassette was
|
This tests ensures that a session that was created while one cassette was
|
||||||
|
active is patched to the use the responses of a second cassette when it
|
||||||
|
is enabled.
|
||||||
'''
|
'''
|
||||||
url = scheme + '://httpbin.org/bytes/1024'
|
url = scheme + '://httpbin.org/bytes/1024'
|
||||||
with vcr.use_cassette(str(tmpdir.join('first_nested.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('first_nested.yaml'))):
|
||||||
|
|||||||
122
tox.ini
122
tox.ini
@@ -40,220 +40,150 @@ deps =
|
|||||||
pytest
|
pytest
|
||||||
pytest-localserver
|
pytest-localserver
|
||||||
PyYAML
|
PyYAML
|
||||||
|
ipdb
|
||||||
|
|
||||||
[testenv:py26requests1]
|
[testenv:py26requests1]
|
||||||
basepython = python2.6
|
basepython = python2.6
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==1.2.3
|
requests==1.2.3
|
||||||
|
|
||||||
[testenv:py27requests1]
|
[testenv:py27requests1]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==1.2.3
|
requests==1.2.3
|
||||||
|
|
||||||
[testenv:py33requests1]
|
[testenv:py33requests1]
|
||||||
basepython = python3.3
|
basepython = python3.3
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==1.2.3
|
requests==1.2.3
|
||||||
|
|
||||||
[testenv:pypyrequests1]
|
[testenv:pypyrequests1]
|
||||||
basepython = pypy
|
basepython = pypy
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==1.2.3
|
requests==1.2.3
|
||||||
|
|
||||||
[testenv:py26requests24]
|
[testenv:py26requests24]
|
||||||
basepython = python2.6
|
basepython = python2.6
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.4.0
|
requests==2.4.0
|
||||||
|
|
||||||
[testenv:py27requests24]
|
[testenv:py27requests24]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.4.0
|
requests==2.4.0
|
||||||
|
|
||||||
[testenv:py33requests24]
|
[testenv:py33requests24]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.4.0
|
requests==2.4.0
|
||||||
|
|
||||||
[testenv:py34requests24]
|
[testenv:py34requests24]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.4.0
|
requests==2.4.0
|
||||||
|
|
||||||
[testenv:pypyrequests24]
|
[testenv:pypyrequests24]
|
||||||
basepython = pypy
|
basepython = pypy
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.4.0
|
requests==2.4.0
|
||||||
|
|
||||||
|
|
||||||
[testenv:py26requests23]
|
[testenv:py26requests23]
|
||||||
basepython = python2.6
|
basepython = python2.6
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.3.0
|
requests==2.3.0
|
||||||
|
|
||||||
[testenv:py27requests23]
|
[testenv:py27requests23]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.3.0
|
requests==2.3.0
|
||||||
|
|
||||||
[testenv:py33requests23]
|
[testenv:py33requests23]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.3.0
|
requests==2.3.0
|
||||||
|
|
||||||
[testenv:py34requests23]
|
[testenv:py34requests23]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.3.0
|
requests==2.3.0
|
||||||
|
|
||||||
[testenv:pypyrequests23]
|
[testenv:pypyrequests23]
|
||||||
basepython = pypy
|
basepython = pypy
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.3.0
|
requests==2.3.0
|
||||||
|
|
||||||
[testenv:py26requests22]
|
[testenv:py26requests22]
|
||||||
basepython = python2.6
|
basepython = python2.6
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.2.1
|
requests==2.2.1
|
||||||
|
|
||||||
[testenv:py27requests22]
|
[testenv:py27requests22]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.2.1
|
requests==2.2.1
|
||||||
|
|
||||||
[testenv:py33requests22]
|
[testenv:py33requests22]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.2.1
|
requests==2.2.1
|
||||||
|
|
||||||
[testenv:py34requests22]
|
[testenv:py34requests22]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.2.1
|
requests==2.2.1
|
||||||
|
|
||||||
|
|
||||||
[testenv:pypyrequests22]
|
[testenv:pypyrequests22]
|
||||||
basepython = pypy
|
basepython = pypy
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
requests==2.2.1
|
requests==2.2.1
|
||||||
|
|
||||||
[testenv:py26httplib2]
|
[testenv:py26httplib2]
|
||||||
basepython = python2.6
|
basepython = python2.6
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
httplib2
|
httplib2
|
||||||
|
|
||||||
[testenv:py27httplib2]
|
[testenv:py27httplib2]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
httplib2
|
httplib2
|
||||||
|
|
||||||
[testenv:py33httplib2]
|
[testenv:py33httplib2]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
httplib2
|
httplib2
|
||||||
|
|
||||||
[testenv:py34httplib2]
|
[testenv:py34httplib2]
|
||||||
basepython = python3.4
|
basepython = python3.4
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
httplib2
|
httplib2
|
||||||
|
|
||||||
[testenv:pypyhttplib2]
|
[testenv:pypyhttplib2]
|
||||||
basepython = pypy
|
basepython = pypy
|
||||||
deps =
|
deps =
|
||||||
mock
|
{[testenv]deps}
|
||||||
pytest
|
|
||||||
pytest-localserver
|
|
||||||
PyYAML
|
|
||||||
httplib2
|
httplib2
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ class VCRHTTPResponse(HTTPResponse):
|
|||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
class VCRConnection:
|
class VCRConnection(object):
|
||||||
# A reference to the cassette that's currently being patched in
|
# A reference to the cassette that's currently being patched in
|
||||||
cassette = None
|
cassette = None
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ class VCRConnection:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def getresponse(self, _=False):
|
def getresponse(self, _=False):
|
||||||
'''Retrieve a the response'''
|
'''Retrieve the response'''
|
||||||
# Check to see if the cassette has a response for this request. If so,
|
# Check to see if the cassette has a response for this request. If so,
|
||||||
# then return it
|
# then return it
|
||||||
if self.cassette.can_play_response_for(self._vcr_request):
|
if self.cassette.can_play_response_for(self._vcr_request):
|
||||||
|
|||||||
Reference in New Issue
Block a user