Created
May 7, 2018 20:02
-
-
Save jordic/f57039d9002b76eb61c8e78f768ba2e2 to your computer and use it in GitHub Desktop.
ws test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def test_websocket_receive_json(loop, aiohttp_client): | |
async def handler(request): | |
ws = web.WebSocketResponse() | |
await ws.prepare(request) | |
data = await ws.receive_json() | |
answer = data['test'] | |
await ws.send_str(answer) | |
await ws.close() | |
return ws | |
app = web.Application() | |
app.router.add_route('GET', '/', handler) | |
client = await aiohttp_client(app) | |
ws = await client.ws_connect('/') | |
expected_value = 'value' | |
payload = '{"test": "%s"}' % expected_value | |
await ws.send_str(payload) | |
resp = await ws.receive() | |
assert resp.data == expected_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment