Skip to content

Commit bcc9951

Browse files
fix http tests
1 parent 88b4ca9 commit bcc9951

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/functional/event_handler/required_dependencies/test_http_resolver.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,3 +881,37 @@ async def send(message: dict[str, Any]) -> None:
881881

882882
# THEN nothing is sent (early return)
883883
assert send_called is False
884+
885+
886+
@pytest.mark.asyncio
887+
async def test_asgi_binary_response():
888+
# GIVEN an app that returns binary data (bytes body is auto base64 encoded)
889+
app = HttpResolverAlpha()
890+
binary_data = b"\x89PNG\r\n\x1a\n\x00\x00\x00" # PNG header bytes
891+
892+
@app.get("/image")
893+
def get_image():
894+
# When body is bytes, Response auto base64 encodes it
895+
return Response(
896+
status_code=200,
897+
content_type="image/png",
898+
body=binary_data,
899+
)
900+
901+
scope = {
902+
"type": "http",
903+
"method": "GET",
904+
"path": "/image",
905+
"query_string": b"",
906+
"headers": [],
907+
}
908+
909+
receive = make_asgi_receive()
910+
send, captured = make_asgi_send()
911+
912+
# WHEN called via ASGI interface
913+
await app(scope, receive, send)
914+
915+
# THEN it decodes base64 and returns binary data
916+
assert captured["status_code"] == 200
917+
assert captured["body"] == binary_data

0 commit comments

Comments
 (0)