开发者

Is there a way to set the value of wsgi.input when testing?

When using wsgiref.util.setup_testing_defaults() to set up a WSGI environ is it possible to set the wsgi.input value so that one can test HTTP POST requests?

Investigating the wsgi.input value created by setup_testing_defaults() shows that it's a wsgi.validate.InputWrapper object with read, readline, readlines, input, close, and __iter__ methods, but no write开发者_JS百科 methods.

Edit:

I'm working on Python 2.6.1


According to the WSGI spec, the wsgi.input is just a file-like object. So even if your helper library assigns some weird object to the environ['wsgi.input'], you may replace it with any file-like object you want. In particular, with a StringIO object:

e = {}
setup_testing_defaults(e)
s = urlencode({'q': 'is there a way to set the value of wsgi input'})
e['wsgi.input'] = StringIO(s)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜