Commit 069c39d2 authored by Luna's avatar Luna 😻

tests: add

 - tests.conftest: alter WEBSOCKET_URL as well
parent 00c976c5
......@@ -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
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)
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')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment