mirror of https://gitlab.com/litecord/litecord.git
tests.test_websocket: add test_ready
This commit is contained in:
parent
069c39d29e
commit
77c52a5c28
|
|
@ -11,6 +11,11 @@ async def _json(conn):
|
||||||
return json.loads(frame)
|
return json.loads(frame)
|
||||||
|
|
||||||
|
|
||||||
|
async def _json_send(conn, data):
|
||||||
|
frame = json.dumps(data)
|
||||||
|
await conn.send(frame)
|
||||||
|
|
||||||
|
|
||||||
async def get_gw(test_cli) -> str:
|
async def get_gw(test_cli) -> str:
|
||||||
"""Get the Gateway URL."""
|
"""Get the Gateway URL."""
|
||||||
gw_resp = await test_cli.get('/api/v6/gateway')
|
gw_resp = await test_cli.get('/api/v6/gateway')
|
||||||
|
|
@ -19,8 +24,9 @@ async def get_gw(test_cli) -> str:
|
||||||
|
|
||||||
|
|
||||||
async def gw_start(test_cli):
|
async def gw_start(test_cli):
|
||||||
|
"""Start a websocket connection"""
|
||||||
gw_url = await get_gw(test_cli)
|
gw_url = await get_gw(test_cli)
|
||||||
return websockets.connect(gw_url)
|
return await websockets.connect(gw_url)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|
@ -37,3 +43,27 @@ async def test_gw(test_cli):
|
||||||
assert isinstance(hello['d']['_trace'], list)
|
assert isinstance(hello['d']['_trace'], list)
|
||||||
|
|
||||||
await conn.close(1000, 'test end')
|
await conn.close(1000, 'test end')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_ready(test_cli):
|
||||||
|
token = await login('normal', test_cli)
|
||||||
|
conn = await gw_start(test_cli)
|
||||||
|
|
||||||
|
# get the hello frame but ignore it
|
||||||
|
await _json(conn)
|
||||||
|
|
||||||
|
await _json_send(conn, {
|
||||||
|
'op': OP.IDENTIFY,
|
||||||
|
'd': {
|
||||||
|
'token': token,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
# try to get a ready
|
||||||
|
try:
|
||||||
|
await _json(conn)
|
||||||
|
assert True
|
||||||
|
await conn.close(1000, 'test end')
|
||||||
|
except (Exception, websockets.ConnectionClosed):
|
||||||
|
assert False
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue