diff --git a/litecord/embed/sanitizer.py b/litecord/embed/sanitizer.py index 4bfe783..027e4ea 100644 --- a/litecord/embed/sanitizer.py +++ b/litecord/embed/sanitizer.py @@ -22,7 +22,6 @@ litecord.embed.sanitizer sanitize embeds by giving common values such as type: rich """ -import urllib.parse from typing import Dict, Any, Optional, Union, List, Tuple from logbook import Logger diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 50216b5..65bd51f 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -17,12 +17,14 @@ along with this program. If not, see . """ +import json + import pytest import websockets -import json from tests.common import login from litecord.gateway.opcodes import OP +from litecord.gateway.websocket import decode_etf async def _json(conn): @@ -30,6 +32,11 @@ async def _json(conn): return json.loads(frame) +async def _etf(conn): + frame = await conn.recv() + return decode_etf(frame) + + async def _json_send(conn, data): frame = json.dumps(data) await conn.send(frame) @@ -53,9 +60,13 @@ async def get_gw(test_cli) -> str: return gw_json['url'] -async def gw_start(test_cli): +async def gw_start(test_cli, *, etf=False): """Start a websocket connection""" gw_url = await get_gw(test_cli) + + if etf: + gw_url = f'{gw_url}?encoding=etf' + return await websockets.connect(gw_url) @@ -164,3 +175,15 @@ async def test_heartbeat(test_cli): assert recv['op'] == OP.HEARTBEAT_ACK await _close(conn) + + +@pytest.mark.asyncio +async def test_etf(test_cli): + """Test if the websocket can send a HELLO message over ETF.""" + conn = await gw_start(test_cli, etf=True) + + try: + hello = await _etf(conn) + assert hello['op'] == OP.HELLO + finally: + await _close(conn)