Exemplo n.º 1
0
async def test_websocket_accept_connection(
        scope: dict, headers: Headers, subprotocol: Optional[str], has_headers: bool,
) -> None:
    connection = ASGIWebsocketConnection(Quart(__name__), scope)
    mock_send = CoroutineMock()
    await connection.accept_connection(mock_send, headers, subprotocol)

    if has_headers:
        mock_send.assert_called_with({
            "subprotocol": subprotocol,
            "type": "websocket.accept",
            "headers": _encode_headers(headers),
        })
    else:
        mock_send.assert_called_with({
            "subprotocol": subprotocol,
            "type": "websocket.accept",
        })
Exemplo n.º 2
0
def test__encode_headers() -> None:
    assert _encode_headers(Headers({"Foo": "Bar"})) == [(b"foo", b"Bar")]