Testing WSGI Application with Urltest

I found myself wanted something to make writing high level, functional tests for WSGI application easier and quicker. If I liked the term I’d call it a domain specific language for testing URLs. Basically I found myself writing a lot of tests like:

pre. def test_404_handler(self): response = self.app.get(‘/does-not-exist’, expect_errors=True) self.assertEquals(“404 Not Found”, response.status)

Testing more than a view URLs like this got boring quickly. What I wanted was a short hand syntax for defining this sort of simple test and then running them all individually. So was born Urltest. It uses the rather nifty Webtest module and hooks into unittest from the standard library. You’re test script then looks a little like:

pre. #!/usr/bin/env python from example_app import application from urltest import verify_urls if name == “main“: urls = ( {‘url’:“/”, ‘code’:200}, {‘url’:“/bob”, ‘code’:200}, {‘url’:“/jim”, ‘code’:404}, {‘url’:“/jim”, ‘method’: “POST”, ‘code’:405}, ) verify_urls(urls, application)

Let me know if you use it as at the moment this is works for me ware, although it’s reasonably well tested and commented.