[Zope-CMF] View classes / testing

Chris McDonough chrism at plope.com
Tue Oct 18 01:28:30 EDT 2005


On Mon, 2005-10-17 at 20:37 +0100, pete wrote:
> Hi,
> 
> I've been looking at making a view class for the RSS syndication in 
> CMFDefault, and I've got all the forms and templates working fine.  So 
> now it's on to testing!
> 
> Has anyone written many tests for a view class?  I'm not quite sure how 
> to set the tests up, i.e. put the request and context in the right 
> place.  If there is an example floating round, please point me in the 
> right direction!

All the tests I've written in this vein have been for a non-OSS customer
project and thus are not shareable, but usually it's enough to make a
"dummy" context (any instance) and pass it in to the view class as the
first argument.  If your view relies on attributes or methods of the
context instance, give those to your dummy class.  Pass an empty
dictionary in as the request object.  If your view uses the RESPONSE
object of the REQUEST, create a dummy one of those too and put it in the
dictionary.  If your view uses adapters, have your test case subclass
the PlacelessSetup class (from zope.app.tests.placelesssetup import
PlacelessSetup) along with unittest.TestCase; you should be able to use
ztapi.provideAdapter then to set up "dummy" adapters.





More information about the Zope-CMF mailing list