1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 09:35:34 +00:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Kevin McCarthy
53c55b13e7 version bump 2017-01-11 17:54:16 -10:00
MAA
365e7cb112 Removed duplicate mock triple. 2017-01-11 17:54:15 -10:00
Charly
e5d6327de9 added a fix to httplib2 2017-01-11 17:54:15 -10:00
Luiz Menezes
d86ffe7130 Add missing requirement yarl for python >= 3.4 2017-01-06 10:43:40 -02:00
Kevin McCarthy
d9fd563812 bump version 2016-12-15 08:47:01 -10:00
Kevin McCarthy
9e548718e5 fix whitespace 2016-12-15 08:47:01 -10:00
Kevin McCarthy
83720793fb Merge pull request #280 from madninja/fix_aiohttp
Fix up to support aiohttp 1.x
2016-11-08 10:15:07 -10:00
Marc Nijdam
188326b10e Fix flake errors 2016-11-07 12:03:21 -08:00
Marc Nijdam
ff90190660 Fix up to support aiohttp 1.x 2016-11-07 10:07:08 -08:00
7 changed files with 27 additions and 30 deletions

View File

@@ -1,5 +1,9 @@
Changelog 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 - 1.10.3 Fix some issues with asyncio and params (thanks @anovikov1984 and
@lamenezes), Fix some issues with cassette serialize / deserialize and empty @lamenezes), Fix some issues with cassette serialize / deserialize and empty
response bodies (thanks @gRoussac and @dz0ny) response bodies (thanks @gRoussac and @dz0ny)

View File

@@ -31,6 +31,7 @@ extras_require = {
':python_version in "2.4, 2.5, 2.6"': ':python_version in "2.4, 2.5, 2.6"':
['contextlib2', 'backport_collections', 'mock'], ['contextlib2', 'backport_collections', 'mock'],
':python_version in "2.7, 3.1, 3.2"': ['contextlib2', '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( setup(
name='vcrpy', name='vcrpy',
version='1.10.3', version='1.10.5',
description=( description=(
"Automatically mock your HTTP interactions to simplify and " "Automatically mock your HTTP interactions to simplify and "
"speed up testing" "speed up testing"

View File

@@ -1,4 +1,6 @@
from vcr.stubs import VCRHTTPSConnection from vcr.stubs import VCRHTTPSConnection
from vcr.compat import mock
from vcr.cassette import Cassette
class TestVCRConnection(object): class TestVCRConnection(object):
@@ -7,3 +9,10 @@ class TestVCRConnection(object):
vcr_connection = VCRHTTPSConnection('www.examplehost.com') vcr_connection = VCRHTTPSConnection('www.examplehost.com')
vcr_connection.ssl_version = 'example_ssl_version' vcr_connection.ssl_version = 'example_ssl_version'
assert vcr_connection.real_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

View File

@@ -164,5 +164,6 @@ def main():
sys.stderr.write("[{0}] {1}\n".format(status, file_path)) sys.stderr.write("[{0}] {1}\n".format(status, file_path))
sys.stderr.write("Done.\n") sys.stderr.write("Done.\n")
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -301,7 +301,6 @@ class CassettePatcherBuilder(object):
self._get_cassette_subclass(stubs.VCRRequestsHTTPSConnection) self._get_cassette_subclass(stubs.VCRRequestsHTTPSConnection)
) )
mock_triples = ( mock_triples = (
(cpool, 'VerifiedHTTPSConnection', stubs.VCRRequestsHTTPSConnection),
(cpool, 'VerifiedHTTPSConnection', stubs.VCRRequestsHTTPSConnection), (cpool, 'VerifiedHTTPSConnection', stubs.VCRRequestsHTTPSConnection),
(cpool, 'HTTPConnection', stubs.VCRRequestsHTTPConnection), (cpool, 'HTTPConnection', stubs.VCRRequestsHTTPConnection),
(cpool, 'HTTPSConnection', stubs.VCRRequestsHTTPSConnection), (cpool, 'HTTPSConnection', stubs.VCRRequestsHTTPSConnection),

View File

@@ -287,7 +287,9 @@ class VCRConnection(object):
# Cassette is write-protected, don't actually connect # Cassette is write-protected, don't actually connect
return 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 @property
def sock(self): def sock(self):

View File

@@ -4,9 +4,9 @@ from __future__ import absolute_import
import asyncio import asyncio
import functools import functools
import json import json
import urllib
from aiohttp import ClientResponse, helpers from aiohttp import ClientResponse
from yarl import URL
from vcr.request import Request from vcr.request import Request
@@ -34,36 +34,17 @@ def vcr_request(cassette, real_request):
headers = self._prepare_headers(headers) headers = self._prepare_headers(headers)
data = kwargs.get('data') data = kwargs.get('data')
params = kwargs.get('params') 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 params:
if not isinstance(params, str): for k, v in params.items():
params = urllib.parse.urlencode(params) params[k] = str(v)
if query:
query = '%s&%s' % (query, params)
else:
query = params
request_path = urllib.parse.urlunsplit(('', '', helpers.requote_uri(path), request_url = URL(url).with_query(params)
query, fragment)) vcr_request = Request(method, str(request_url), data, headers)
request_url = urllib.parse.urlunsplit(
(scheme, netloc, request_path, '', ''))
vcr_request = Request(method, request_url, data, headers)
if cassette.can_play_response_for(vcr_request): if cassette.can_play_response_for(vcr_request):
vcr_response = cassette.play_response(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.status = vcr_response['status']['code']
response.content = vcr_response['body']['string'] response.content = vcr_response['body']['string']
response.reason = vcr_response['status']['message'] response.reason = vcr_response['status']['message']
@@ -73,7 +54,7 @@ def vcr_request(cassette, real_request):
return response return response
if cassette.write_protected and cassette.filter_request(vcr_request): if cassette.write_protected and cassette.filter_request(vcr_request):
response = MockClientResponse(method, url) response = MockClientResponse(method, URL(url))
response.status = 599 response.status = 599
msg = ("No match for the request {!r} was found. Can't overwrite " msg = ("No match for the request {!r} was found. Can't overwrite "
"existing cassette {!r} in your current record mode {!r}.") "existing cassette {!r} in your current record mode {!r}.")