[Grok-dev] getUtility(ICatalog) fails with ComponentLookupError

Sylvain Viollon sylvain at infrae.com
Thu Nov 10 08:24:14 UTC 2011


Op 9 nov 2011, om 23:16 heeft Àlex Magaz Graça het volgende geschreven:

> Hello,
> 

   Hello,

> I have an application with code like this:
> 
> from zope.component import getUtility
> from zope.catalog.interfaces import ICatalog
> ...
> 
> class TicketCatalog(grok.Container):
>     ...
>     def getActiveTickets(self):
>         catalog = getUtility(ICatalog)
>         ...
> 
> after following the code at the end of the example here:
> 
> http://grok.zope.org/doc/current/reference/components.html#grok.index.Value
> 


    I you call a method of your content that rely on your Grok site directly from a unittest, you need to setup your Grok as a local site for the Zope component architecture. This is automatically done by publisher when your Grok site is traversed in a request.

    In your unittest you need to do before:

    from zope.component.hooks import setSite, getSite

    setSite(self.yourgroksite)

    If you after call getSite(), your Grok must be returned. The setup of your testcase is a good place to do that I think.

    Regards,

    Sylvain


-- 
Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands





More information about the Grok-dev mailing list