From 1b6f304421e6aef6a56c980ae69d5fd5b3cbe578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steinn=20Eldj=C3=A1rn=20Sigur=C3=B0arson?= Date: Tue, 4 Jun 2019 14:26:02 +0000 Subject: [PATCH] Add .content to MockClientResponse so code which uses aiohttp request content streams directly can be tested --- vcr/stubs/aiohttp_stubs/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/vcr/stubs/aiohttp_stubs/__init__.py b/vcr/stubs/aiohttp_stubs/__init__.py index f6525c7..8e03907 100644 --- a/vcr/stubs/aiohttp_stubs/__init__.py +++ b/vcr/stubs/aiohttp_stubs/__init__.py @@ -5,12 +5,16 @@ import asyncio import functools import json -from aiohttp import ClientResponse +from aiohttp import ClientResponse, streams from yarl import URL from vcr.request import Request +class MockStream(asyncio.StreamReader, streams.AsyncStreamReaderMixin): + pass + + class MockClientResponse(ClientResponse): def __init__(self, method, url): super().__init__( @@ -37,6 +41,13 @@ class MockClientResponse(ClientResponse): def release(self): pass + @property + def content(self): + s = MockStream() + s.feed_data(self._body) + s.feed_eof() + return s + def vcr_request(cassette, real_request): @functools.wraps(real_request)