Zope2 functional testing with Twill
Zope2 is not so bad after all. I've been slowly warming up to it over the past few months. There's plenty of things it does wrong, but sometimes it leaves room for surprisingly elegant solutions.
A couple of weeks ago I started working on a new feature for our CMS and decided to start off with some tests. Unit tests were fine, but my changes could break the front-end interaction in many different ways, so what I really needed were functional tests. The ZopeTest package does provide limited support for these but, because I wanted to test as close to the browser as possible, I grabbed Twill and glued it to ZopeTestCase.
The whole thing was surprisingly easy and works like a charm. The bulk of the code is on gist, I've left out some helper functions for login and logout. Some traces of our testing setup might still be there, e.g. ZopeTestCase's self.app.REQUEST object might not have any SESSION attached to it, but you get the idea. There's probably some sneaky-globals-behind-the-scenes stuff going on there, because we're not telling ZPublisher.Test.publish_module about our application, but it works, so that's good enough for me. Oh, and you could plug any WSGI-compliant testing tool instead of Twill, because we're actually using WSGI here.
I'd love to hear from you if you find this useful, and good luck bending Zope to your will :)