Skip to content

Commit

Permalink
test: fetch with None in json payload (#1830)
Browse files Browse the repository at this point in the history
test: fetch with none json payload
  • Loading branch information
mxschmitt committed Mar 27, 2023
1 parent f791b88 commit 481ade1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/async/test_fetch_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,14 @@ async def test_should_throw_an_error_when_max_redirects_is_less_than_0(
server.PREFIX + "/a/redirect1", method=method, max_redirects=-1
)
assert "'max_redirects' must be greater than or equal to '0'" in str(exc_info)


async def test_should_serialize_null_values_in_json(
playwright: Playwright, server: Server
) -> None:
request = await playwright.request.new_context()
server.set_route("/echo", lambda req: (req.write(req.post_body), req.finish()))
response = await request.post(server.PREFIX + "/echo", data={"foo": None})
assert response.status == 200
assert await response.text() == '{"foo":null}'
await request.dispose()
4 changes: 3 additions & 1 deletion tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def reset(self) -> None:
self.gzip_routes.clear()
self.routes.clear()

def set_route(self, path: str, callback: Callable[[http.Request], Any]) -> None:
def set_route(
self, path: str, callback: Callable[[HttpRequestWithPostBody], Any]
) -> None:
self.routes[path] = callback

def enable_gzip(self, path: str) -> None:
Expand Down
11 changes: 11 additions & 0 deletions tests/sync/test_fetch_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,14 @@ def test_should_throw_an_error_when_max_redirects_is_less_than_0(
server.PREFIX + "/a/redirect1", method=method, max_redirects=-1
)
assert "'max_redirects' must be greater than or equal to '0'" in str(exc_info)


def test_should_serialize_null_values_in_json(
playwright: Playwright, server: Server
) -> None:
request = playwright.request.new_context()
server.set_route("/echo", lambda req: (req.write(req.post_body), req.finish()))
response = request.post(server.PREFIX + "/echo", data={"foo": None})
assert response.status == 200
assert response.text() == '{"foo":null}'
request.dispose()

0 comments on commit 481ade1

Please sign in to comment.