mirror of https://gitlab.com/litecord/litecord.git
tests: add test_websocket.py
- tests.conftest: alter WEBSOCKET_URL as well
This commit is contained in:
parent
00c976c552
commit
069c39d29e
|
|
@ -17,6 +17,7 @@ def _test_app(unused_tcp_port, event_loop):
|
|||
# reassign an unused tcp port for websockets
|
||||
# since the config might give a used one.
|
||||
main_app.config['WS_PORT'] = unused_tcp_port
|
||||
main_app.config['WEBSOCKET_URL'] = f'localhost:{unused_tcp_port}'
|
||||
|
||||
# make sure we're calling the before_serving hooks
|
||||
event_loop.run_until_complete(main_app.startup())
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import pytest
|
||||
import websockets
|
||||
import json
|
||||
|
||||
from tests.common import login
|
||||
from litecord.gateway.opcodes import OP
|
||||
|
||||
|
||||
async def _json(conn):
|
||||
frame = await conn.recv()
|
||||
return json.loads(frame)
|
||||
|
||||
|
||||
async def get_gw(test_cli) -> str:
|
||||
"""Get the Gateway URL."""
|
||||
gw_resp = await test_cli.get('/api/v6/gateway')
|
||||
gw_json = await gw_resp.json
|
||||
return gw_json['url']
|
||||
|
||||
|
||||
async def gw_start(test_cli):
|
||||
gw_url = await get_gw(test_cli)
|
||||
return websockets.connect(gw_url)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gw(test_cli):
|
||||
"""Test if the gateway connects and sends a proper
|
||||
HELLO payload."""
|
||||
conn = await gw_start(test_cli)
|
||||
|
||||
hello = await _json(conn)
|
||||
assert hello['op'] == OP.HELLO
|
||||
|
||||
assert isinstance(hello['d'], dict)
|
||||
assert isinstance(hello['d']['heartbeat_interval'], int)
|
||||
assert isinstance(hello['d']['_trace'], list)
|
||||
|
||||
await conn.close(1000, 'test end')
|
||||
Loading…
Reference in New Issue