test_websocket.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:django-redis-pubsub 作者: andrewyoung1991 项目源码 文件源码
def test_websocket_pubsub_wrapper_authentication_error():
    loop = asyncio.get_event_loop()

    @websocket_pubsub("/", authenticate=True)
    def handler(ws, params, **kwargs):
        ws.send_str("hello, world!")

    @asyncio.coroutine
    def start_server(loop):
        app = Application()
        app.router.add_route(*handler.route)
        srv = yield from loop.create_server(app.make_handler(), "localhost", 9000)
        return srv

    @asyncio.coroutine
    def go(loop):
        srv = yield from start_server(loop)
        with pytest.raises(WSServerHandshakeError):
            client = yield from ws_connect("http://localhost:9000")
            yield from client.close()

        srv.close()
        yield from srv.wait_closed()

    loop.run_until_complete(go(loop))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号