40
40
from aiohttp .connector import Connection
41
41
from aiohttp .hdrs import METH_DELETE
42
42
from aiohttp .helpers import TimerNoop
43
- from aiohttp .http import HttpVersion10 , HttpVersion11 , StreamWriter
43
+ from aiohttp .http import HttpVersion , HttpVersion10 , HttpVersion11 , StreamWriter
44
44
from aiohttp .multipart import MultipartWriter
45
45
from aiohttp .typedefs import LooseCookies
46
46
@@ -1205,8 +1205,6 @@ async def test_body_payload_with_size_no_content_length(
1205
1205
loop = loop ,
1206
1206
)
1207
1207
1208
- # Initially no body should be set
1209
- assert req ._body is None
1210
1208
# POST method with None body should have Content-Length: 0
1211
1209
assert req .headers [hdrs .CONTENT_LENGTH ] == "0"
1212
1210
@@ -1217,7 +1215,6 @@ async def test_body_payload_with_size_no_content_length(
1217
1215
assert req .headers [hdrs .CONTENT_LENGTH ] == str (len (data ))
1218
1216
assert req .body is bytes_payload
1219
1217
assert req ._body is bytes_payload # Access _body which is the Payload
1220
- assert req ._body is not None # type: ignore[unreachable]
1221
1218
assert req ._body .size == len (data )
1222
1219
1223
1220
# Set body back to None
@@ -1968,7 +1965,7 @@ async def test_warn_if_unclosed_payload_via_body_setter(
1968
1965
io .BufferedReader (io .BytesIO (b"test data" )),
1969
1966
encoding = "utf-8" ,
1970
1967
)
1971
- req .body = file_payload
1968
+ req .update_body ( file_payload )
1972
1969
1973
1970
# Setting body again should trigger the warning for the previous payload
1974
1971
with pytest .warns (
@@ -1988,7 +1985,7 @@ async def test_no_warn_for_autoclose_payload_via_body_setter(
1988
1985
1989
1986
# First set BytesIOPayload which has autoclose=True
1990
1987
bytes_payload = payload .BytesIOPayload (io .BytesIO (b"test data" ))
1991
- req .body = bytes_payload
1988
+ req .update_body ( bytes_payload )
1992
1989
1993
1990
# Setting body again should not trigger warning since previous payload has autoclose=True
1994
1991
with warnings .catch_warnings (record = True ) as warning_list :
@@ -2015,7 +2012,7 @@ async def test_no_warn_for_consumed_payload_via_body_setter(
2015
2012
io .BufferedReader (io .BytesIO (b"test data" )),
2016
2013
encoding = "utf-8" ,
2017
2014
)
2018
- req .body = file_payload
2015
+ req .update_body ( file_payload )
2019
2016
2020
2017
# Properly close the payload to mark it as consumed
2021
2018
await file_payload .close ()
@@ -2265,7 +2262,7 @@ async def test_warn_stacklevel_points_to_user_code(
2265
2262
io .BufferedReader (io .BytesIO (b"test data" )),
2266
2263
encoding = "utf-8" ,
2267
2264
)
2268
- req .body = file_payload
2265
+ req .update_body ( file_payload )
2269
2266
2270
2267
# Capture warnings with their details
2271
2268
with warnings .catch_warnings (record = True ) as warning_list :
@@ -2326,10 +2323,10 @@ async def test_warn_stacklevel_update_body_from_data(
2326
2323
await req ._close ()
2327
2324
2328
2325
2329
- async def test_expect100_with_body_becomes_none (
2326
+ async def test_expect100_with_body_becomes_empty (
2330
2327
make_client_request : _RequestMaker ,
2331
2328
) -> None :
2332
- """Test that write_bytes handles body becoming None after expect100 handling."""
2329
+ """Test that write_bytes handles body becoming empty after expect100 handling."""
2333
2330
# Create a mock writer and connection
2334
2331
mock_writer = mock .AsyncMock ()
2335
2332
mock_conn = mock .Mock ()
@@ -2340,9 +2337,9 @@ async def test_expect100_with_body_becomes_none(
2340
2337
)
2341
2338
req ._body = mock .Mock () # Start with a body
2342
2339
2343
- # Now set body to None to simulate a race condition
2340
+ # Now set body to empty payload to simulate a race condition
2344
2341
# where req._body is set to None after expect100 handling
2345
- req ._body = None
2342
+ req ._body = payload . PAYLOAD_REGISTRY . get ( b"" , disposition = None )
2346
2343
2347
2344
await req ._write_bytes (mock_writer , mock_conn , None )
2348
2345
@@ -2493,7 +2490,6 @@ async def test_update_body_none_sets_content_length_zero(
2493
2490
# Update body to None
2494
2491
await req .update_body (None )
2495
2492
assert req .headers [hdrs .CONTENT_LENGTH ] == "0"
2496
- assert req ._body is None
2497
2493
await req ._close ()
2498
2494
2499
2495
@@ -2513,5 +2509,4 @@ async def test_update_body_none_no_content_length_for_get_methods(
2513
2509
# Update body to None
2514
2510
await req .update_body (None )
2515
2511
assert hdrs .CONTENT_LENGTH not in req .headers
2516
- assert req ._body is None
2517
2512
await req ._close ()
0 commit comments