mirror of https://gitlab.com/litecord/litecord.git
test_websocket: add test for etf
- embed.sanitizer: remove unused import
This commit is contained in:
parent
9f50721243
commit
0631f007c1
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
"""
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue