How do I use Tipfy and wsgi_intercept together for testing?
I'm creating an API using Tipfy. I have an existing suite that tests some methods I will expose via URL, but what I'd like to do is see exactly how these functions will work once they're exposed. I'd like to test the URL params directly, for example.
I think what I need is something like wsgi_intercept. It uses a function that
returns a WSGI app to run its tests so you don't have to run a web server in parallel; it bootstraps it for you in the setUp
function. There's an example at http://ivory.idyl开发者_如何学Pythonl.org/articles/twill-and-wsgi_intercept.html, but I'm not sure how to do it with Tipfy.
What call to the Tipfy library will return the WSGI application itself? Tipfy.wsgi_app
?
If there is another testing strategy or tool that you can suggest, I'd also appreciate that.
Thanks!
Use easy_install to install wsgi_intercept, then get hold of the Tipfy app via make_wsgi_app
.
import config
import tipfy
app = tipfy.make_wsgi_app(config.config)
# Enable the interception of HTTP calls.
from wsgi_intercept.urllib2_intercept import install_opener
install_opener()
wsgi_intercept.add_wsgi_intercept('localhost', 8000, lambda: app)
精彩评论