1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Luiz Menezes
506700651d Bump version to 1.13.0 2018-07-12 20:07:30 -03:00
Luiz Menezes
d1b11da610 Merge pull request #369 from lamenezes/fix-aiohttp-url-with-query-params
Fix aiohttp url with query params
2018-07-08 23:48:20 -03:00
Luiz Menezes
306238d561 Test aiohttp usage with query strings on the URL 2018-07-08 23:06:22 -03:00
Goran Stefkovski
dbddaa0e44 Shallow copy of query as mutable MultiDict 2018-07-08 23:04:36 -03:00
Goran Stefkovski
0d4c9eccf5 simplified logic so that either params or url is used, if params are specified - they will overwrite any get params on the url 2018-07-08 23:03:42 -03:00
Luiz Menezes
1674741d9f Merge pull request #368 from lamenezes/fix-json-content-type-on-aiohttp-stub
Fix content type being passed to aiohttp response stub
2018-07-08 14:46:16 -03:00
Luiz Menezes
75cb067e29 Fix content type being passed to aiohttp response stub 2018-07-07 23:56:39 -03:00
Luiz Menezes
ab6e6b5b5d Merge pull request #359 from lamenezes/adapt-aiohttp-stub-to-3.3
Fix aiohttp stub to work with aiohttp 3.3.x
2018-06-18 10:46:36 -03:00
Luiz Menezes
9e8bd382d3 Fix aiohttp stub to work with aiohttp 3.3.x 2018-06-05 11:59:28 -03:00
5 changed files with 32 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
Changelog
---------
- 1.13.0 - Fix support to latest aiohttp version (3.3.2). Fix content-type bug in aiohttp stub. Save URL with query params properly when using aiohttp.
- 1.12.0 - Fix support to latest aiohttp version (3.2.1), Adapted setup to PEP508, Support binary responses on aiohttp, Dropped support for EOL python versions (2.6 and 3.3)
- 1.11.1 Fix compatibility with newest requests and urllib3 releases
- 1.11.0 Allow injection of persistence methods + bugfixes (thanks @j-funk and @IvanMalison),

View File

@@ -37,7 +37,7 @@ if sys.version_info[0] == 2:
setup(
name='vcrpy',
version='1.12.0',
version='1.13.0',
description=(
"Automatically mock your HTTP interactions to simplify and "
"speed up testing"

View File

@@ -5,7 +5,7 @@ import aiohttp
@asyncio.coroutine
def aiohttp_request(loop, method, url, output='text', encoding='utf-8', **kwargs):
def aiohttp_request(loop, method, url, output='text', encoding='utf-8', content_type=None, **kwargs):
session = aiohttp.ClientSession(loop=loop)
response_ctx = session.request(method, url, **kwargs)
@@ -13,7 +13,8 @@ def aiohttp_request(loop, method, url, output='text', encoding='utf-8', **kwargs
if output == 'text':
content = yield from response.text()
elif output == 'json':
content = yield from response.json(encoding=encoding)
content_type = content_type or 'application/json'
content = yield from response.json(encoding=encoding, content_type=content_type)
elif output == 'raw':
content = yield from response.read()

View File

@@ -137,3 +137,20 @@ def test_params_same_url_distinct_params(tmpdir, scheme):
response, cassette_response_text = get(url, output='text', params=other_params)
assert 'No match for the request' in cassette_response_text
assert response.status == 599
def test_params_on_url(tmpdir, scheme):
url = scheme + '://httpbin.org/get?a=1&b=foo'
headers = {'Content-Type': 'application/json'}
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
_, response_json = get(url, output='json', headers=headers)
request = cassette.requests[0]
assert request.url == url
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
_, cassette_response_json = get(url, output='json', headers=headers)
request = cassette.requests[0]
assert request.url == url
assert cassette_response_json == response_json
assert cassette.play_count == 1

View File

@@ -20,7 +20,6 @@ class MockClientResponse(ClientResponse):
continue100=None,
timer=None,
request_info=None,
auto_decompress=None,
traces=None,
loop=asyncio.get_event_loop(),
session=None,
@@ -28,16 +27,16 @@ class MockClientResponse(ClientResponse):
# TODO: get encoding from header
@asyncio.coroutine
def json(self, *, encoding='utf-8', loads=json.loads): # NOQA: E999
return loads(self.content.decode(encoding))
def json(self, *, encoding='utf-8', loads=json.loads, **kwargs): # NOQA: E999
return loads(self._body.decode(encoding))
@asyncio.coroutine
def text(self, encoding='utf-8'):
return self.content.decode(encoding)
return self._body.decode(encoding)
@asyncio.coroutine
def read(self):
return self.content
return self._body
@asyncio.coroutine
def release(self):
@@ -52,11 +51,13 @@ def vcr_request(cassette, real_request):
headers = self._prepare_headers(headers)
data = kwargs.get('data')
params = kwargs.get('params')
request_url = URL(url)
if params:
for k, v in params.items():
params[k] = str(v)
request_url = URL(url).with_query(params)
request_url = URL(url).with_query(params)
vcr_request = Request(method, str(request_url), data, headers)
if cassette.can_play_response_for(vcr_request):
@@ -64,9 +65,9 @@ def vcr_request(cassette, real_request):
response = MockClientResponse(method, URL(vcr_response.get('url')))
response.status = vcr_response['status']['code']
response.content = vcr_response['body']['string']
response._body = vcr_response['body']['string']
response.reason = vcr_response['status']['message']
response.headers = vcr_response['headers']
response._headers = vcr_response['headers']
response.close()
return response
@@ -77,7 +78,7 @@ def vcr_request(cassette, real_request):
msg = ("No match for the request {!r} was found. Can't overwrite "
"existing cassette {!r} in your current record mode {!r}.")
msg = msg.format(vcr_request, cassette._path, cassette.record_mode)
response.content = msg.encode()
response._body = msg.encode()
response.close()
return response