[Zope3-Users] Adapting a builtin?

Michael Howitz mh at gocept.com
Tue Dec 13 01:57:38 EST 2005


On Mon, 2005-12-12 at 18:06 -0500, Paul Winkler wrote:
[...]
> ############# toward the end of
> # tests/testtests/test_AcceleratedHTTPCacheManager.py #############
> 
>     def test_XXXinterface(self):
>         url = 'http://www.google.com'
>         from Products.StandardCacheManagers.interfaces import IHTTPConnection
>         conn = IHTTPConnection(url)
> 
> #####################################################################
> 
> 
> This raises an error, regardless of whether I remove the registration of 
> IString or not:
[...]
> TypeError: ('Could not adapt', 'http://www.google.com', <InterfaceClass
> Products.StandardCacheManagers.interfaces.IHTTPConnection>)

In unittests the ZCML-Directives are not used so you have to do the
things from ZCML in your test-code before adaption.

from zope.interface import classImplements
from zope.app.testing import ztapi

classImplements(str, IString)
ztapi.provideAdapter(IString, IHTTPConnection, HTTPConnection)

HTH,
 mac



More information about the Zope3-users mailing list