File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,12 @@ async def _on_request(
78
78
str (url ) + "?" + urlencode ([(x , y ) for x , y in kw ["params" ].items ()])
79
79
)
80
80
81
+ # If a json payload is provided, serialize it for JSONMatcher support
82
+ if json_body := kw .get ("json" ):
83
+ req .json = json_body
84
+ if "Content-Type" not in req .headers :
85
+ req .headers ["Content-Type" ] = "application/json"
86
+
81
87
# Match the request against the registered mocks in pook
82
88
mock = self .engine .match (req )
83
89
Original file line number Diff line number Diff line change 1
1
import pytest
2
2
import aiohttp
3
+ import json
3
4
4
5
import pook
5
6
@@ -55,3 +56,21 @@ async def test_binary_body(URL):
55
56
async with aiohttp .ClientSession () as session :
56
57
req = await session .get (URL )
57
58
assert await req .read () == BINARY_FILE
59
+
60
+
61
+ @pytest .mark .asyncio
62
+ async def test_json_matcher_data_payload (URL ):
63
+ payload = {"foo" : "bar" }
64
+ pook .post (URL ).json (payload ).reply (200 ).body (BINARY_FILE )
65
+ async with aiohttp .ClientSession () as session :
66
+ req = await session .post (URL , data = json .dumps (payload ))
67
+ assert await req .read () == BINARY_FILE
68
+
69
+
70
+ @pytest .mark .asyncio
71
+ async def test_json_matcher_json_payload (URL ):
72
+ payload = {"foo" : "bar" }
73
+ pook .post (URL ).json (payload ).reply (200 ).body (BINARY_FILE )
74
+ async with aiohttp .ClientSession () as session :
75
+ req = await session .post (URL , json = payload )
76
+ assert await req .read () == BINARY_FILE
You can’t perform that action at this time.
0 commit comments