[Grok-dev] catalog weirdness in functional tests
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Thu May 3 08:08:43 EDT 2007
Hi,
I'm building a simple application,that uses the catalog. In grok
there's now basically two ways for setting up a catalog within an
application:
1) use a grok.local_utility directive, like so:
def setup_catalog(catalog):
catalog['first_name'] = FieldIndex('first_name', IPerson)
catalog['last_name'] = FieldIndex('last_name', IPerson)
class Application(grok.Application, grok.Container):
grok.local_utility(IntIds, provides=IIntIds)
grok.local_utility(Catalog, provides=ICatalog, setup=setup_catalog)
...
2) The "newer" way, using grok.Indexes:
class Application(grok.Application, grok.Container):
...
class PatientIndexes(grok.Indexes):
grok.context(IPerson) # that what gets indexed
grok.site(Application)
first_name = index.Text()
last_name = index.Text()
Both work fine when actually running Zope. But something weird happens
when I try to test my application in a functional test. The relevant
test code looks like this:
>>> from userforms.model import Application, Person
>>> getRootFolder()['app'] = app = Application()
>>> from zope.app.component.hooks import setSite
>>> setSite(app)
>>> from zope.app.catalog.interfaces import ICatalog
>>> from zope.component import getUtility
>>> catalog = getUtility(ICatalog)
In case the catalog is setup like in 1), this test passes. If I have a
catalog setup like in 2), the test fails with:
ComponentLookupError: (
<InterfaceClass zope.app.catalog.interfaces.ICatalog>, '')
Well, uhm, no clue here... Maybe anyone has an idea? (what I found
slightly worying, but maybe this is completely unrelated to this
issue, is that the ftests in grok that test the catalog by way of
grok.local_utility does not need any clean up, whereas the ftests for
grok.Indexes *do* need all kinds of clean up...)
kind regards,
jw
--
Jan-Wijbrand Kolman
More information about the Grok-dev
mailing list