[Grok-dev] getUtility(ICatalog) fails with ComponentLookupError
Àlex Magaz Graça
rivaldi8 at gmail.com
Wed Nov 9 22:16:00 UTC 2011
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
But when called from a unit test, I get this:
Error in test testGetActiveTickets
(helpdesk.tests.test_helpdesk.TicketCatalogTest)
Traceback (most recent call last):
File "/usr/lib/python2.7/unittest/case.py", line 321, in run
testMethod()
File
"/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/tests/test_helpdesk.py",
line 29, in testGetActiveTickets
activeTickets = self._catalog.getActiveTickets()
File
"/home/alex/uni/projecte/repo/list-active-tickets/HelpDesk/src/helpdesk/app.py",
line 31, in getActiveTickets
catalog = getUtility(ICatalog)
File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/_api.py",
line 169, in getUtility
raise ComponentLookupError(interface, name)
ComponentLookupError: (<InterfaceClass
zope.catalog.interfaces.ICatalog>, '')
Also, if I try from a python console:
$ bin/python-console
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope.component
>>> from zope.catalog.interfaces import ICatalog
>>> catalog = zope.component.getUtility(ICatalog)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg/zope/component/_api.py",
line 169, in getUtility
raise ComponentLookupError(interface, name)
zope.component.interfaces.ComponentLookupError: (<InterfaceClass
zope.catalog.interfaces.ICatalog>, '')
Any idea of what I'm doing wrong?
If it helps, I'm running it from an Ubuntu 11.04 with the following
versions reported from the Grok admin interface:
Grok: 1.6 (is this right? the last announced version from the web is 1.4)
Python: 2.7.1
Zope version: Unavailable (?)
And from python path:
/home/alex/.buildout/eggs/zope.catalog-3.8.1-py2.7.egg
/home/alex/.buildout/eggs/zope.component-3.10.0-py2.7.egg
Thanks,
Àlex
More information about the Grok-dev
mailing list