[Grok-dev] grok.local_utility is not registering anything in the app
Martijn Faassen
faassen at startifact.com
Fri Feb 20 09:50:24 EST 2009
Hi there,
Using local_utility should indeed be the right way to set up utilities
with Grok.
Vanderson Mota dos Santos wrote:
> the problem is, when i try to use component.getUtility(IIntIds), a
> componentLookUpError appear to me.
...
> I know this, but the tests are failing. And i'm running them with the
> functional layer. Every time i run the tests, a new instance is
> created(obviously), so, the local_utilities should be accessible.
It'd be interested to see your failing tests.
If you create a view like this for your application:
class Index(grok.View):
def render(self):
intids = component.getUtility(IIntIds)
print intids
return "the result"
do you still get a component lookup error when you access the view, or
do you get the intids? (assuming you re-installed your app first).
One thing to know is that in order to lookup local utilities, the
correct site needs to be set first to your application. The normal
traversal process does this for you, which is why I hope that the above
view will do the right thing for you.
In tests, setSite() may very well not have been used and therefore you
would look up only global utilities, not those for your application object.
To make it work in your tests, you might need to do something like this
before you do any getUtility lookups:
from zope.app.component.hooks import setSite
setSite(your_app)
Hopefully this will help resolve the problem. If not there might be
something deeper going on...
Regards,
Martijn
More information about the Grok-dev
mailing list