[Zope3-Users] testing: provideInterface and vocabulary named 'Interfaces'

Christian Lück christian.lueck at ruhr-uni-bochum.de
Fri Feb 20 12:12:10 EST 2009


I answered the question myself.

Christian Lück wrote:
> Hi,
> 
> I'm stuck with testing (= developing) my components.
> I have an interface with a zope.schema.Choice field where the vocabulary
> is zope3's vocabulary named 'Interfaces' from the zope.app.component
> package.
> 
> The problem with testing occures when I try to assign a value to the
> field, inspite of providing the interface in the test and having
> registered the InterfaceVocabulary from zope.app.component.vocabulary
> for the test. The traceback says that an adapter is missing - but which
> one?  A part of the registry seems to be missing.

The test needs a placeful setup instead of a placeless setup. There is a
method in zope.app.testing.setup that does everything needed.

> Here is what is brought up for the test:
> 
> ...
> 
> from quotationtool.categorization.weighteditemscontainer import
> updateWeightedItemsContainerOrder
> from quotationtool.categorization.categorizableitemdescription import
> categorizableItemDescriptionVocabulary
> from quotationtool.categorization.mode import modeVocabulary
> 
> def setUp(test):
>     zope.component.testing.setUp(test)
>     zope.component.eventtesting.setUp(test)
>     zope.component.provideHandler(updateWeightedItemsContainerOrder)
>     vocabulary.setVocabularyRegistry(vocabulary.VocabularyRegistry())
>     vr = vocabulary.getVocabularyRegistry()
>     vr.register('quotationtool.categorization.categorizableitemdescription',
>                 categorizableItemDescriptionVocabulary)
>     vr.register('quotationtool.categorization.mode',
>                 modeVocabulary)
>     vr.register('Interfaces',
>                 InterfacesVocabulary)
> 

Change to:

...
from zope.app.testing.setup import placefulSetUp

def setUp(test):
    test.globs = {'root': placefulSetUp(True)} # placeful setup
    zope.component.eventtesting.setUp(test)
    zope.component.provideHandler(updateWeightedItemsContainerOrder)
    vocabulary.setVocabularyRegistry(vocabulary.VocabularyRegistry())
    vr = vocabulary.getVocabularyRegistry()
    vr.register('quotationtool.categorization.categorizableitemdescription',
                categorizableItemDescriptionVocabulary)
    vr.register('quotationtool.categorization.mode',
                modeVocabulary)
    vr.register('Interfaces',
                InterfacesVocabulary)



Regards,
Christian


More information about the Zope3-users mailing list