mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53c55b13e7 | ||
|
|
365e7cb112 | ||
|
|
e5d6327de9 | ||
|
|
d86ffe7130 | ||
|
|
d9fd563812 | ||
|
|
9e548718e5 | ||
|
|
83720793fb | ||
|
|
188326b10e | ||
|
|
ff90190660 |
@@ -1,5 +1,9 @@
|
||||
Changelog
|
||||
---------
|
||||
- 1.10.5 Added a fix to httplib2 (thanks @carlosds730), Fix an issue with
|
||||
aiohttp (thanks @madninja), Add missing requirement yarl (thanks @lamenezes),
|
||||
Remove duplicate mock triple (thanks @FooBarQuaxx)
|
||||
- 1.10.4 Fix an issue with asyncio aiohttp (thanks @madninja)
|
||||
- 1.10.3 Fix some issues with asyncio and params (thanks @anovikov1984 and
|
||||
@lamenezes), Fix some issues with cassette serialize / deserialize and empty
|
||||
response bodies (thanks @gRoussac and @dz0ny)
|
||||
|
||||
3
setup.py
3
setup.py
@@ -31,6 +31,7 @@ extras_require = {
|
||||
':python_version in "2.4, 2.5, 2.6"':
|
||||
['contextlib2', 'backport_collections', 'mock'],
|
||||
':python_version in "2.7, 3.1, 3.2"': ['contextlib2', 'mock'],
|
||||
':python_version in "3.4, 3.5, 3.6"': ['yarl'],
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +56,7 @@ if sys.version_info[0] == 2:
|
||||
|
||||
setup(
|
||||
name='vcrpy',
|
||||
version='1.10.3',
|
||||
version='1.10.5',
|
||||
description=(
|
||||
"Automatically mock your HTTP interactions to simplify and "
|
||||
"speed up testing"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from vcr.stubs import VCRHTTPSConnection
|
||||
from vcr.compat import mock
|
||||
from vcr.cassette import Cassette
|
||||
|
||||
|
||||
class TestVCRConnection(object):
|
||||
@@ -7,3 +9,10 @@ class TestVCRConnection(object):
|
||||
vcr_connection = VCRHTTPSConnection('www.examplehost.com')
|
||||
vcr_connection.ssl_version = 'example_ssl_version'
|
||||
assert vcr_connection.real_connection.ssl_version == 'example_ssl_version'
|
||||
|
||||
@mock.patch('vcr.cassette.Cassette.can_play_response_for', return_value=False)
|
||||
def testing_connect(*args):
|
||||
vcr_connection = VCRHTTPSConnection('www.google.com')
|
||||
vcr_connection.cassette = Cassette('test', record_mode='all')
|
||||
vcr_connection.real_connection.connect()
|
||||
assert vcr_connection.real_connection.sock is not None
|
||||
|
||||
@@ -164,5 +164,6 @@ def main():
|
||||
sys.stderr.write("[{0}] {1}\n".format(status, file_path))
|
||||
sys.stderr.write("Done.\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -301,7 +301,6 @@ class CassettePatcherBuilder(object):
|
||||
self._get_cassette_subclass(stubs.VCRRequestsHTTPSConnection)
|
||||
)
|
||||
mock_triples = (
|
||||
(cpool, 'VerifiedHTTPSConnection', stubs.VCRRequestsHTTPSConnection),
|
||||
(cpool, 'VerifiedHTTPSConnection', stubs.VCRRequestsHTTPSConnection),
|
||||
(cpool, 'HTTPConnection', stubs.VCRRequestsHTTPConnection),
|
||||
(cpool, 'HTTPSConnection', stubs.VCRRequestsHTTPSConnection),
|
||||
|
||||
@@ -287,7 +287,9 @@ class VCRConnection(object):
|
||||
# Cassette is write-protected, don't actually connect
|
||||
return
|
||||
|
||||
return self.real_connection.connect(*args, **kwargs)
|
||||
from vcr.patch import force_reset
|
||||
with force_reset():
|
||||
return self.real_connection.connect(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def sock(self):
|
||||
|
||||
@@ -4,9 +4,9 @@ from __future__ import absolute_import
|
||||
import asyncio
|
||||
import functools
|
||||
import json
|
||||
import urllib
|
||||
|
||||
from aiohttp import ClientResponse, helpers
|
||||
from aiohttp import ClientResponse
|
||||
from yarl import URL
|
||||
|
||||
from vcr.request import Request
|
||||
|
||||
@@ -34,36 +34,17 @@ def vcr_request(cassette, real_request):
|
||||
headers = self._prepare_headers(headers)
|
||||
data = kwargs.get('data')
|
||||
params = kwargs.get('params')
|
||||
|
||||
# INFO: Query join logic from
|
||||
# https://github.com/KeepSafe/aiohttp/blob/b3eeedbc2f515ec2aa6e87ba129524c17b6fe4e3/aiohttp/client_reqrep.py#L167-L188
|
||||
scheme, netloc, path, query, fragment = urllib.parse.urlsplit(url)
|
||||
if not path:
|
||||
path = '/'
|
||||
|
||||
# NOTICE: Not sure this is applicable here:
|
||||
# if isinstance(params, collections.Mapping):
|
||||
# params = list(params.items())
|
||||
|
||||
if params:
|
||||
if not isinstance(params, str):
|
||||
params = urllib.parse.urlencode(params)
|
||||
if query:
|
||||
query = '%s&%s' % (query, params)
|
||||
else:
|
||||
query = params
|
||||
for k, v in params.items():
|
||||
params[k] = str(v)
|
||||
|
||||
request_path = urllib.parse.urlunsplit(('', '', helpers.requote_uri(path),
|
||||
query, fragment))
|
||||
request_url = urllib.parse.urlunsplit(
|
||||
(scheme, netloc, request_path, '', ''))
|
||||
|
||||
vcr_request = Request(method, request_url, data, headers)
|
||||
request_url = URL(url).with_query(params)
|
||||
vcr_request = Request(method, str(request_url), data, headers)
|
||||
|
||||
if cassette.can_play_response_for(vcr_request):
|
||||
vcr_response = cassette.play_response(vcr_request)
|
||||
|
||||
response = MockClientResponse(method, vcr_response.get('url'))
|
||||
response = MockClientResponse(method, URL(vcr_response.get('url')))
|
||||
response.status = vcr_response['status']['code']
|
||||
response.content = vcr_response['body']['string']
|
||||
response.reason = vcr_response['status']['message']
|
||||
@@ -73,7 +54,7 @@ def vcr_request(cassette, real_request):
|
||||
return response
|
||||
|
||||
if cassette.write_protected and cassette.filter_request(vcr_request):
|
||||
response = MockClientResponse(method, url)
|
||||
response = MockClientResponse(method, URL(url))
|
||||
response.status = 599
|
||||
msg = ("No match for the request {!r} was found. Can't overwrite "
|
||||
"existing cassette {!r} in your current record mode {!r}.")
|
||||
|
||||
Reference in New Issue
Block a user