mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
add support for aiohttp
This commit is contained in:
22
vcr/patch.py
22
vcr/patch.py
@@ -80,6 +80,13 @@ else:
|
||||
_CurlAsyncHTTPClient_fetch_impl = \
|
||||
tornado.curl_httpclient.CurlAsyncHTTPClient.fetch_impl
|
||||
|
||||
try:
|
||||
import aiohttp.client
|
||||
except ImportError: # pragma: no cover
|
||||
pass
|
||||
else:
|
||||
_AiohttpClientSessionRequest = aiohttp.client.ClientSession._request
|
||||
|
||||
|
||||
class CassettePatcherBuilder(object):
|
||||
|
||||
@@ -98,7 +105,7 @@ class CassettePatcherBuilder(object):
|
||||
def build(self):
|
||||
return itertools.chain(
|
||||
self._httplib(), self._requests(), self._boto3(), self._urllib3(),
|
||||
self._httplib2(), self._boto(), self._tornado(),
|
||||
self._httplib2(), self._boto(), self._tornado(), self._aiohttp(),
|
||||
self._build_patchers_from_mock_triples(
|
||||
self._cassette.custom_patches
|
||||
),
|
||||
@@ -273,6 +280,19 @@ class CassettePatcherBuilder(object):
|
||||
)
|
||||
yield curl.CurlAsyncHTTPClient, 'fetch_impl', new_fetch_impl
|
||||
|
||||
@_build_patchers_from_mock_triples_decorator
|
||||
def _aiohttp(self):
|
||||
try:
|
||||
import aiohttp.client as client
|
||||
except ImportError: # pragma: no cover
|
||||
pass
|
||||
else:
|
||||
from .stubs.aiohttp_stubs import vcr_request
|
||||
new_request = vcr_request(
|
||||
self._cassette, _AiohttpClientSessionRequest
|
||||
)
|
||||
yield client.ClientSession, '_request', new_request
|
||||
|
||||
def _urllib3_patchers(self, cpool, stubs):
|
||||
http_connection_remover = ConnectionRemover(
|
||||
self._get_cassette_subclass(stubs.VCRRequestsHTTPConnection)
|
||||
|
||||
Reference in New Issue
Block a user