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
4 changes: 3 additions & 1 deletion playwright/_impl/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ async def _inner_fetch(
if self._close_reason:
raise TargetClosedError(self._close_reason)
assert (
(1 if data else 0) + (1 if form else 0) + (1 if multipart else 0)
(1 if data is not None else 0)
+ (1 if form is not None else 0)
+ (1 if multipart is not None else 0)
) <= 1, "Only one of 'data', 'form' or 'multipart' can be specified"
assert (
maxRedirects is None or maxRedirects >= 0
Expand Down
16 changes: 16 additions & 0 deletions tests/async/test_fetch_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,22 @@ async def test_should_serialize_request_data(
await request.dispose()


async def test_should_reject_empty_data_with_form(
playwright: Playwright, server: Server
) -> None:
request = await playwright.request.new_context()
with pytest.raises(
AssertionError,
match="Only one of 'data', 'form' or 'multipart' can be specified",
):
await request.post(
server.EMPTY_PAGE,
data="",
form={"name": "value"},
)
await request.dispose()


async def test_should_retry_ECONNRESET(playwright: Playwright, server: Server) -> None:
request_count = 0

Expand Down
16 changes: 16 additions & 0 deletions tests/sync/test_fetch_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ def test_should_serialize_null_values_in_json(
request.dispose()


def test_should_reject_empty_data_with_form(
playwright: Playwright, server: Server
) -> None:
request = playwright.request.new_context()
with pytest.raises(
AssertionError,
match="Only one of 'data', 'form' or 'multipart' can be specified",
):
request.post(
server.EMPTY_PAGE,
data="",
form={"name": "value"},
)
request.dispose()


def test_should_throw_when_fail_on_status_code_is_true(
playwright: Playwright, server: Server
) -> None:
Expand Down