Testing web resources in Twisted can be a bit of a pain, and the Twisted docs don’t describe how best go go about writing tests for twisted.web.resource.Resource objects.
Generally, usage of twisted.web resources looks something like this:
I created a small bit of code that wraps some of the testing library in Twisted. This code can be used to easily create tests by just using a DummySite instead of a twisted.web.server.Site. You can then call get and post on that site (and pass optional dictionaries of get/post arguments and headers). Here’s what a test looks like:
Here’s the testing code if you want to use it:
And with that, a few hours worth of work will save me at least a few 10 minute segments in the future.