[Zope3-Users] IIntIds in test environment

Marius Gedminas mgedmin at b4net.lt
Thu Jun 5 15:05:28 EDT 2008


On Wed, Jun 04, 2008 at 05:19:11PM +0200, Kai Diefenbach wrote:
> to register a IntIds utility by startup I'm using following subscriber:
> 
<snip>
>     ensureUtility(root_folder, IIntIds, '', IntIds, copy_to_zlog=False)
<snip>
> This is working when zope is running.
> 
> I wonder why it isn't within tests.

Are you talking about unit or functional tests?

> the code above is executed but the
> IntIds utility is not available.

This sounds like functional tests to me.

> With:
> 
> <snip>
> 
>     >>> from zope.app.intid.interfaces import IIntIds
>     >>> from zope.component import getUtility
>     >>> intids = getUtility(IIntIds)

This looks more like a unit test to me.

Are you setting the site in the test fixture?  Local utilities can only
be found when you set the site (running zope does this for you when
processing requests) or pass some context to getUtility.

> </snip>
> 
> I get: 
> 
> File
> "/Users/Kai/Zope/instances/iqpp.qab/src/iqppqab/actions/adapters/actions
> .txt", line 28, in actions.txt
> Failed example:
>     intids = getUtility(IIntIds)
> Exception raised:
...
>     ComponentLookupError: (<InterfaceClass
> zope.app.intid.interfaces.IIntIds>, '')

> I guess I don't understand the whole SiteManager thing. Is there a
> working example of how to setup a test environment with IntIds.

zope/app/catalog/README.txt could be an example.  I haven't looked
deeply, but it seems that it is registering an IIntIds utility as a
global utility, which is much simpler and therefore more suitable for
tests.

Regards,
Marius Gedminas
-- 
... there is always a well-known solution to every human problem -- neat,
plausible, and wrong.
		-- H. L. Mencken (1880-1956), "Prejudices"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20080605/e6da74c4/attachment.bin


More information about the Zope3-users mailing list