mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Add .content to MockClientResponse so code which uses aiohttp request content streams directly can be tested
This commit is contained in:
@@ -5,12 +5,16 @@ import asyncio
|
|||||||
import functools
|
import functools
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from aiohttp import ClientResponse
|
from aiohttp import ClientResponse, streams
|
||||||
from yarl import URL
|
from yarl import URL
|
||||||
|
|
||||||
from vcr.request import Request
|
from vcr.request import Request
|
||||||
|
|
||||||
|
|
||||||
|
class MockStream(asyncio.StreamReader, streams.AsyncStreamReaderMixin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MockClientResponse(ClientResponse):
|
class MockClientResponse(ClientResponse):
|
||||||
def __init__(self, method, url):
|
def __init__(self, method, url):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@@ -37,6 +41,13 @@ class MockClientResponse(ClientResponse):
|
|||||||
def release(self):
|
def release(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
def content(self):
|
||||||
|
s = MockStream()
|
||||||
|
s.feed_data(self._body)
|
||||||
|
s.feed_eof()
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
def vcr_request(cassette, real_request):
|
def vcr_request(cassette, real_request):
|
||||||
@functools.wraps(real_request)
|
@functools.wraps(real_request)
|
||||||
|
|||||||
Reference in New Issue
Block a user