我很难弄清楚如何为用@Sockets.route
修饰的Flask路由编写单元测试。使用普通的Flask路由,我可以将测试客户机设置为上下文管理器,并使用它来发送请求,但我不确定web套接字的模拟是什么。你知道吗
这是我试图为其编写单元测试的代码:
from flask_sockets import Sockets
sockets = Sockets(app)
@sockets.route('/test')
def echo_socket(ws):
while not ws.closed:
message = ws.receive()
ws.send('success')
Flask Sockets的文档中说我应该使用gunicorn worker,但是我不太清楚如何从单元测试访问其中一个(仅使用unittest模块)。我有点像:
def test_echo_socket:
# this is all incorrect
with my_app.app.test_client() as context:
context.get('/test')
self.assertEqual(context.response_code, '101')
有人知道如何获得单元测试的websocket上下文吗?谢谢。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐