File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -338,7 +338,7 @@ async def _inner_fetch(
338
338
form_data : Optional [List [NameValue ]] = None
339
339
multipart_data : Optional [List [FormField ]] = None
340
340
post_data_buffer : Optional [bytes ] = None
341
- if data :
341
+ if data is not None :
342
342
if isinstance (data , str ):
343
343
if is_json_content_type (serialized_headers ):
344
344
json_data = data if is_json_parsable (data ) else json .dumps (data )
Original file line number Diff line number Diff line change @@ -448,12 +448,18 @@ async def test_should_throw_an_error_when_max_redirects_is_less_than_0(
448
448
assert "'max_redirects' must be greater than or equal to '0'" in str (exc_info )
449
449
450
450
451
- async def test_should_serialize_null_values_in_json (
451
+ async def test_should_serialize_request_data (
452
452
playwright : Playwright , server : Server
453
453
) -> None :
454
454
request = await playwright .request .new_context ()
455
455
server .set_route ("/echo" , lambda req : (req .write (req .post_body ), req .finish ()))
456
- response = await request .post (server .PREFIX + "/echo" , data = {"foo" : None })
457
- assert response .status == 200
458
- assert await response .text () == '{"foo": null}'
456
+ for data , expected in [
457
+ ({"foo" : None }, '{"foo": null}' ),
458
+ ([], "[]" ),
459
+ ({}, "{}" ),
460
+ ("" , "" ),
461
+ ]:
462
+ response = await request .post (server .PREFIX + "/echo" , data = data )
463
+ assert response .status == 200
464
+ assert await response .text () == expected
459
465
await request .dispose ()
You can’t perform that action at this time.
0 commit comments