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_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_invalid_message_given_state( stream: HTTPStream, state: ASGIHTTPState, message_type: str ) -> None: stream.state = state with pytest.raises(UnexpectedMessageError): await stream.app_send({"type": message_type}) # type: ignore