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

Add test for MockStream on aiohttp

This commit is contained in:
Steinn Eldjárn Sigurðarson
2019-06-04 14:27:13 +00:00
parent 1b6f304421
commit cc55ef5b35

View File

@@ -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'