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.1According 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)
精彩评论