[Zope-dev] testing problem with path expressions in page templates
Marius Gedminas
marius at gedmin.as
Thu Aug 26 21:31:03 EDT 2010
On Fri, Aug 27, 2010 at 12:47:11AM +0100, Chris Withers wrote:
> When trying to test a template in a unit test, I get the following
> exception:
...
> LocationError: ('No traversable adapter found', {'content': <MyObject>,
> 'args': ()})
...
> Now, the same template works just fine when used "for real", so I figure
> some standard traversal adapter hasn't been registered when the test runs.
>
> What adapter might that be and what's the "right" way to get it
> registered in a unit test?
DefaultTraversable, I think, and
from zope.app.testing import setup
setup.setUpTraversal()
Various other features need various other components, e.g. if your
template tries to use @@absolute_url, in addition to the above, you'll need
provideAdapter(zope.traversing.namespace.view,
adapts=(None, None),
provides=ITraversable,
name='view')
similarly for resources you do something like
ztapi.provideView(Interface, Interface, ITraversable, 'resource',
zope.traversing.namespace.resource)
ztapi.browserResource('style.css', ResourceStub)
and let's not even start talking about forms and widgets.
I'm not sure rendering page templates in unit tests is worth the pain.
Marius Gedminas
--
http://pov.lt/ -- Zope 3/BlueBream consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20100827/cf534362/attachment.bin
More information about the Zope-Dev
mailing list