Skip to content

Commit f8ac564

Browse files
committed
test(sse): cover send_body fallback when ping_interval is None
1 parent 97eee5d commit f8ac564

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/unit/test_response/test_sse.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,34 @@ async def mock_receive() -> HTTPDisconnectEvent:
288288
body = b"".join(received).decode()
289289
assert "hello" in body
290290
assert "world" in body
291+
292+
293+
async def test_sse_response_send_body_without_ping() -> None:
294+
"""ASGIStreamingSSEResponse.send_body delegates to parent when ping_interval is None."""
295+
296+
async def gen() -> AsyncIterator[bytes]:
297+
yield b"data: hello\r\n\r\n"
298+
299+
response = ASGIStreamingSSEResponse(
300+
iterator=gen(),
301+
ping_interval=None,
302+
media_type="text/event-stream",
303+
status_code=200,
304+
)
305+
306+
received: list[bytes] = []
307+
308+
async def mock_send(message: Message) -> None:
309+
if message.get("type") == "http.response.body":
310+
body = message.get("body", b"")
311+
received.append(body if isinstance(body, bytes) else b"")
312+
313+
async def mock_receive() -> HTTPDisconnectEvent:
314+
await anyio.sleep(10)
315+
return {"type": "http.disconnect"}
316+
317+
await response.send_body(mock_send, mock_receive)
318+
319+
body = b"".join(received).decode()
320+
assert "hello" in body
321+
assert ": ping" not in body

0 commit comments

Comments
 (0)