Add test for MockStream on aiohttp
@@ -93,6 +93,24 @@ def test_binary(tmpdir, scheme):
assert cassette.play_count == 1
+@pytest.mark.asyncio
+async def test_stream(tmpdir, scheme):
+ url = scheme + '://httpbin.org/get'
+ headers = {'Content-Type': 'application/json'}
+
+ with vcr.use_cassette(str(tmpdir.join('stream.yaml'))):
+ async with aiohttp.ClientSession() as session:
+ resp = await session.get(url, headers=headers)
+ body = await resp.read() # do not use stream interface here, the stream seems exhausted by vcr
+
+ with vcr.use_cassette(str(tmpdir.join('stream.yaml'))) as cassette:
+ async with aiohttp.ClientSession() as session:
+ cassette_resp = await session.get(url, headers=headers)
+ cassette_body = await cassette_resp.content.read()
+ assert cassette_body == body
+ assert cassette.play_count == 1
+
+
def test_post(tmpdir, scheme):
data = {'key1': 'value1', 'key2': 'value2'}
url = scheme + '://httpbin.org/post'
