• OpenCore Dev

component lookup in zopectl tests considered harmful

from Rob Miller on Apr 28, 2009 07:11 PM
hi all,

some of you, i know, are familiar with the "sputnik" package.  for those who 
aren't, sputnik is the name of an opencore extension package that TOPP has 
developed.  when you have sputnik installed into an opencore zope instance, 
then instead of a plain vanilla openplans.org-like site, you'll get a 
customized site that has the look, feel, and features of the 
livablestreets.com groups area.

i'm currently working on getting sputnik to work with the opencore trunk. 
it's coming along nicely, but i'm hitting a lot of road blocks because there's 
a lot of code in the opencore tests that explicitly uses traversal to retrieve 
various view classes, like this:

 >>> view = self.portal.people.unrestrictedTraverse('@@view')

this is an anti-pattern.  these tests often break when you have sputnik 
installed, b/c sputnik registers its own views, often overriding the defaults 
that are registered in the opencore package.  thus, when sputnik is installed, 
the 'view' variable above is not the class that the testing code expects.

we don't need to be testing the component architecture framework in our 
zopectl tests... functional tests are the place where we can ensure that the 
pages are responding to the correct URLs.  when testing components in the 
zopectl tests, please just instantiate the class directly:

 >>> view = path.to.view.class.ViewClass(self.portal.people, request)
 >>> view = view.__of__(self.portal.people)

it's a bit more verbose, but it maintains better separation of testing 
concerns and, more importantly, it means that you're testing what you think 
you're testing.


Return to date view: threaded or flat