async def test_send_invalid_http_message( stream: WSStream, status: Any, headers: Any, body: Any ) -> None: stream.connection = Mock() stream.state = ASGIWebsocketState.HANDSHAKE stream.scope = {"method": "GET"} with pytest.raises((TypeError, ValueError)): await stream.app_send( {"type": "websocket.http.response.start", "headers": headers, "status": status} ) await stream.app_send({"type": "websocket.http.response.body", "body": body})
def test_stream_idle(stream: WSStream, state: ASGIWebsocketState, idle: bool) -> None: stream.state = state assert stream.idle is idle
async def test_send_invalid_message_given_state(stream: WSStream, state: ASGIWebsocketState, message_type: str) -> None: stream.state = state with pytest.raises(UnexpectedMessage): await stream.app_send({"type": message_type}) # type: ignore