Re: [Zope3-Users] IIntIds in test environment

2008-06-05 Thread Marius Gedminas
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


signature.asc
Description: Digital signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] IIntIds in test environment

2008-06-04 Thread Kai Diefenbach
Hi, 

to register a IntIds utility by startup I'm using following subscriber:

snip

def bootStrapSubscriber(event):
Subscriber to the IDataBaseOpenedEvent

Create local utilities if not yet present

db, connection, root, root_folder = getInformationFromEvent(event)

ensureUtility(root_folder, IIntIds, '', IntIds, copy_to_zlog=False)
transaction.commit()
connection.close()

/snip

and register this with 

snip

  subscriber
  for=zope.app.appsetup.IDatabaseOpenedEvent
  handler=.bootstrap.bootStrapSubscriber /

/snip

This is working when zope is running.

I wonder why it isn't within tests. the code above is executed but the
IntIds utility is not available.

With:

snip

 from zope.app.intid.interfaces import IIntIds
 from zope.component import getUtility
 intids = getUtility(IIntIds)

/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:
Traceback (most recent call last):
  File
/Users/Kai/Zope/instances/iqpp.qab/eggs/tmpDJ2x_9/zope.testing-3.5.1-py
2.4.egg/zope/testing/doctest.py, line 1356, in __run

  File doctest actions.txt[10], line 1, in ?
intids = getUtility(IIntIds)
  File
/Users/Kai/Zope/instances/iqpp.qab/eggs/zope.component-3.4.0-py2.4.egg/
zope/component/_api.py, line 207, in getUtility
raise ComponentLookupError(interface, name)
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.

Thanks
Kai

-- 
iqplusplus - http://iqpp.de
EasyShop - http://easyshop-for-plone.googlecode.com/

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users