Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/integration/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,36 @@ def test_post(tmpdir, body, caplog, mockbin_request_url):
), "Log message not found."


@pytest.mark.online
@pytest.mark.asyncio
async def test_post_data_vs_json(tmpdir, caplog, mockbin_request_url):
caplog.set_level(logging.INFO)
data = {"key1": "value1", "key2": "value2"}
url = mockbin_request_url
with vcr.use_cassette(str(tmpdir.join("post.yaml"))):
async with aiohttp.ClientSession() as session:
async with await session.post(url, json=data) as request:
response_json = await request.json()

with vcr.use_cassette(str(tmpdir.join("post.yaml"))) as cassette:
request = cassette.requests[0]
assert request.body == data
async with aiohttp.ClientSession() as session:
async with await session.post(url, json=data) as request:
cassette_response_json = await request.json()
assert cassette_response_json == response_json
assert cassette.play_count == 1

assert next(
(
log
for log in caplog.records
if log.getMessage() == f"<Request (POST) {url}> not in cassette, sending to real server"
),
None,
), "Log message not found."


@pytest.mark.online
def test_params(tmpdir, mockbin_request_url):
url = mockbin_request_url + "?d=d"
Expand Down
2 changes: 1 addition & 1 deletion vcr/stubs/aiohttp_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ async def new_request(self, method, url, **kwargs):
headers = kwargs.get("headers")
auth = kwargs.get("auth")
headers = self._prepare_headers(headers)
data = kwargs.get("data", kwargs.get("json"))
data = kwargs.get("json", kwargs.get("data"))
params = kwargs.get("params")
cookies = kwargs.get("cookies")

Expand Down