Example #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 = AsyncMock()
    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"
        })
Example #2
0
def test_encode_headers() -> None:
    assert encode_headers(Headers({"Foo": "Bar"})) == [(b"foo", b"Bar")]