[Zope-dev] Re: ZopeTestCase.doctest is not aware of local sites

Hanno Schlichting plone at hannosch.info
Wed Mar 7 20:03:38 EST 2007


Hi again,

I just noticed that the publish method from the Functional base class
from ZopeTestCase has the same problem. You can find the adjusted test
attached.

Hanno

Hanno Schlichting wrote:
> Hi all,
> 
> while pushing local site support in CMF/Plone I came across some weird
> test failures. After a while of debbuging I could track this down to the
> http method in ZopeTestCase's doctest support.
> 
> The method in its Zope2 incarnation is not aware of local sites, while
> the one in zope.app.testing is.
> 
> I have attached a patch that mirrors the Zope3 behavior and saves the
> site information before publishing a module and restores it back, just
> like the security manager is saved/restored.
> 
> As this is causing some test failures in Plone 3 now, I would be happy
> if somebody could take a look at this.
> 
> Thank you,
> Hanno

-------------- next part --------------
Index: /opt/plone30/parts/zope2/lib/python/Testing/ZopeTestCase/functional.py
===================================================================
--- /opt/plone30/parts/zope2/lib/python/Testing/ZopeTestCase/functional.py	(revision 73024)
+++ /opt/plone30/parts/zope2/lib/python/Testing/ZopeTestCase/functional.py	(working copy)
@@ -37,6 +37,7 @@
                 request_method='GET', stdin=None, handle_errors=True):
         '''Publishes the object at 'path' returning a response object.'''
 
+        from zope.app.component.hooks import setSite, getSite
         from StringIO import StringIO
         from ZPublisher.Response import Response
         from ZPublisher.Test import publish_module
@@ -47,6 +48,10 @@
         # Save current security manager
         sm = getSecurityManager()
 
+        # And we need to store the old site
+        old_site = getSite()
+        setSite(None)
+
         # Commit the sandbox for good measure
         transaction.commit()
 
@@ -89,6 +94,9 @@
         # Restore security manager
         setSecurityManager(sm)
 
+        # And we need to restore the site again
+        setSite(old_site)
+
         return ResponseWrapper(response, outstream, path)
 
 


More information about the Zope-Dev mailing list