diff --git a/src/pook/interceptors/aiohttp.py b/src/pook/interceptors/aiohttp.py index be5a9ac..bf8e0be 100644 --- a/src/pook/interceptors/aiohttp.py +++ b/src/pook/interceptors/aiohttp.py @@ -26,7 +26,7 @@ async def __call__( req = Request( method=request.method, headers=request.headers.items(), - body=request.body, + body=request.body.decode(), url=str(request.url), ) diff --git a/tests/integration/pook_aiohttp_test.py b/tests/integration/pook_aiohttp_test.py new file mode 100644 index 0000000..5ca51b0 --- /dev/null +++ b/tests/integration/pook_aiohttp_test.py @@ -0,0 +1,15 @@ +import pytest +import aiohttp + +import pook + +pytestmark = [pytest.mark.pook] + + +async def test_aiohttp_match_body(): + body = {"foo": "bar"} + pook.post("http://example.com", body="foo=1").reply(200).json(body) + res = await aiohttp.ClientSession().post("http://example.com", data={"foo": 1}) + assert res.status == 200 + assert res.headers == {"Content-Type": "application/json"} + assert await res.json() == body