def maker(method, path, query_params=None, headers=None): nonlocal app path = URL(path) if query_params: path = path.with_query(query_params) if headers is None: headers = CIMultiDict({ "HOST": "server.example.com", "UPGRADE": "websocket", "CONNECTION": "Upgrade", "SEC-WEBSOCKET-KEY": "dGhlIHNhbXBsZSBub25jZQ==", "ORIGIN": "http://example.com", "SEC-WEBSOCKET-PROTOCOL": "chat, superchat", "SEC-WEBSOCKET-VERSION": "13", }) writer = mock.Mock() writer.write_headers = make_mocked_coro(None) writer.write = make_mocked_coro(None) writer.drain = make_mocked_coro(None) transport = mock.Mock() transport._drain_helper = make_mocked_coro() loop = asyncio.get_event_loop() ret = make_mocked_request(method, str(path).encode(), headers, writer=writer, loop=loop, app=app) return ret
async def xtest_process_release_acquire_and_remote_closed(make_transport): transp = make_transport() transp.session.interrupted = False transp.manager.acquire = make_mocked_coro() transp.manager.release = make_mocked_coro() resp = await transp.process() await transp.manager.clear() assert resp.status == 101 assert resp.headers.get("upgrade", "").lower() == "websocket" assert resp.headers.get("connection", "").lower() == "upgrade" transp.session._remote_closed.assert_called_once_with() assert transp.manager.acquire.called assert transp.manager.release.called
async def test_streaming_send(make_transport): trans = make_transport() trans.callback = "cb" resp = trans.response = mock.Mock() resp.write = make_mocked_coro(None) stop = await trans.send("text data") resp.write.assert_called_with(b'/**/cb("text data");\r\n') assert stop
async def test_streaming_send(make_transport): trans = make_transport() resp = trans.response = mock.Mock() resp.write = make_mocked_coro(None) stop = await trans.send("text data") resp.write.assert_called_with(b"data: text data\r\n\r\n") assert not stop assert trans.size == len(b"data: text data\r\n\r\n") trans.maxsize = 1 stop = trans.send("text data") assert stop