async def test_send_invalid_message(stream: HTTPStream, status: Any, headers: Any, body: Any) -> None: stream.scope = {"method": "GET"} stream.state = ASGIHTTPState.REQUEST with pytest.raises((TypeError, ValueError)): await stream.app_send({ "type": "http.response.start", "headers": headers, "status": status }) await stream.app_send({"type": "http.response.body", "body": body})
async def test_send_push(stream: HTTPStream, http_scope: HTTPScope) -> None: stream.scope = http_scope stream.stream_id = 1 await stream.app_send({"type": "http.response.push", "path": "/push", "headers": []}) assert stream.send.call_args_list == [ # type: ignore call( Request( stream_id=1, headers=[(b":scheme", b"https")], http_version="2", method="GET", raw_path=b"/push", ) ) ]
async def test_send_invalid_message( stream: HTTPStream, http_scope: HTTPScope, status: Any, headers: Any, body: Any, ) -> None: stream.scope = http_scope stream.state = ASGIHTTPState.REQUEST with pytest.raises((TypeError, ValueError)): await stream.app_send( cast( HTTPResponseStartEvent, {"type": "http.response.start", "headers": headers, "status": status}, ) ) await stream.app_send( cast(HTTPResponseBodyEvent, {"type": "http.response.body", "body": body}) )
async def test_send_push(stream: HTTPStream) -> None: stream.scope = { "scheme": "https", "headers": [(b"host", b"hypercorn")], "http_version": "2" } stream.stream_id = 1 await stream.app_send({ "type": "http.response.push", "path": "/push", "headers": [] }) assert stream.send.call_args_list == [ call( Request( stream_id=1, headers=[(b":scheme", b"https"), (b":authority", b"hypercorn")], http_version="2", method="GET", raw_path=b"/push", )) ]