问题描述
我的应用程序中包含以下代码:
@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 (将#修改为@)