单元测试werkzeug Request.application处理程序

问题描述

我的应用程序中包含以下代码:

@Request.application
def my_wsgi_app(request):
    response = JSONRPCResponseManager.handle(request.data,dispatcher)

    return Response(response.json,mimetype="application/json")


def main():
    run_simple(
        hostname=os.environ.get("HOST","0.0.0.0"),port=int(os.environ.get("PORT",8000)),application=my_wsgi_app,)


if __name__ == "__main__":
    main()

我想在单元测试中测试功能my_wsgi_app,如何调用my_wsgi_app

如果我这样做:

import types

from jsonrpc import dispatcher

from app.main import application


@dispatcher.add_method(name="onTest")
def handle_test():
    pass


def test_application():
    request = types.SimpleNamespace(data={})

    my_wsgi_app(request)

我收到此错误:

_______________________________________________________________________________________ test_application ________________________________________________________________________________________

    def test_application():
        request = types.SimpleNamespace(data={})
    
>       application(request)

tests/test_wsgi.py:23: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (namespace(data={}),)

    def application(*args):
>       request = cls(args[-2])
E       IndexError: tuple index out of range

venv/lib/python3.8/site-packages/werkzeug/wrappers/base_request.py:235: IndexError

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...