[KSS-checkins] r35946 - in kukit/kss.core/trunk: . tests
reebalazs at codespeak.net
reebalazs at codespeak.net
Fri Dec 22 11:31:35 CET 2006
Author: reebalazs
Date: Fri Dec 22 11:31:16 2006
New Revision: 35946
Added:
kukit/kss.core/trunk/siteview_life.txt
Modified:
kukit/kss.core/trunk/azaxview.py
kukit/kss.core/trunk/tests/base.py
kukit/kss.core/trunk/tests/test_siteview.py
Log:
kss: fix the siteview. It needs to stopEventListening if an EndRequest event arrives. Without this the failing requests linger forever listening, and only zope restart clears the situation.
Modified: kukit/kss.core/trunk/azaxview.py
==============================================================================
--- kukit/kss.core/trunk/azaxview.py (original)
+++ kukit/kss.core/trunk/azaxview.py Fri Dec 22 11:31:16 2006
@@ -49,6 +49,7 @@
from zope.event import notify
from zope.interface import implements, Interface
from zope.publisher.browser import BrowserView
+from zope.app.publication.interfaces import IEndRequestEvent
class ViewSiteManager(BaseGlobalComponents):
@@ -93,6 +94,10 @@
@component.adapter(Interface)
def _eventRedispatcher(self, event):
+ if IEndRequestEvent.providedBy(event):
+ # If this happens, we must finish activity
+ self.stopEventListening()
+ return
if not IAzaxEvent.providedBy(event):
azaxevent = AzaxEvent(self, event)
notify(azaxevent)
Added: kukit/kss.core/trunk/siteview_life.txt
==============================================================================
--- (empty file)
+++ kukit/kss.core/trunk/siteview_life.txt Fri Dec 22 11:31:16 2006
@@ -0,0 +1,104 @@
+=====================
+Site view, life cycle
+=====================
+
+... or, making the view a site manager is a good idea after
+all, but let's see what dangers are lurking in the dark.
+
+Checking if the view finishes its lifetime
+------------------------------------------
+
+It is important that the view does not stay on after the
+request. This would cause them to continue listening to
+events. We need a few imports first.
+
+ >>> from kss.core.azaxview import SiteView
+
+ >>> from zope.interface import Interface, implements
+ >>> from zope.component import adapter
+ >>> from zope.lifecycleevent import ObjectModifiedEvent
+ >>> from zope.event import notify
+ >>> from zope.app.publication.interfaces import IEndRequestEvent
+ >>> try:
+ ... from Products.Five.testbrowser import Browser
+ ... except ImportError:
+ ... from zope.testbrowser.browser import Browser
+
+First, let's create a funky view that has two methods, one
+failing and one succeeding, and a habit to choke on any
+events.
+
+ >>> class FunkyView(SiteView):
+ ... def IAmGood(self):
+ ... 'XXX'
+ ... return self.render()
+ ... def IAmBad(self):
+ ... 'XXX'
+ ... raise Exception, 'Generic badness'
+ ... @adapter(Interface)
+ ... def _eventRedispatcher(self, event):
+ ... SiteView._eventRedispatcher(self, event)
+ ... if not IEndRequestEvent.providedBy(event):
+ ... raise Exception, 'Too late event %r' % event
+
+ >>> import kss.core.tests
+ >>> kss.core.tests.FunkyView = FunkyView
+
+We provide this view as a browser page. We care to register
+it properly, otherwise we would miss some Five acquisition
+woodoo. (XXX Note that this must be adjusted to run on Zope3.)
+
+ >>> try:
+ ... import Products.Five
+ ... except ImportError:
+ ... # probably zope 3, not supported
+ ... raise 'Zope3 not supported in this test'
+ ... else:
+ ... from Products.Five.zcml import load_string, load_config
+
+ >>> load_string('''
+ ... <configure xmlns="http://namespaces.zope.org/zope"
+ ... xmlns:browser="http://namespaces.zope.org/browser"
+ ... xmlns:five="http://namespaces.zope.org/five"
+ ... xmlns:zcml="http://namespaces.zope.org/zcml"
+ ... >
+ ...
+ ... <browser:page
+ ... for="*"
+ ... class="kss.core.tests.FunkyView"
+ ... allowed_attributes="IAmGood IAmBad"
+ ... name="funky_view"
+ ... permission="zope.Public"
+ ... />
+ ...
+ ... </configure>''')
+
+Create a test browser now, so we can finally start.
+
+ >>> browser = Browser()
+
+Let's call up the good request.
+
+ >>> browser.open(self.folder.absolute_url() + '/@@funky_view/IAmGood')
+
+Now, if we happen to send an event... nothing happens, since
+the render() method has taken care of unregistering the
+event as a SiteView.
+
+ >>> notify(ObjectModifiedEvent(None))
+
+But it is also important, that even in case the render
+method does not run (it gives an error since we raised an
+exception, this is all right). We would already get an error
+during this, thanks to the RequestEvent that arrives.
+
+ >>> browser = browser.open('http://nohost/@@funky_view/IAmBad')
+ Traceback (most recent call last):
+ ...
+ HTTPError: HTTP Error 500: Internal Server Error
+
+And even if we send a new event, it must not get to the
+redispatcher of the view.
+
+ >>> notify(ObjectModifiedEvent(None))
+
Modified: kukit/kss.core/trunk/tests/base.py
==============================================================================
--- kukit/kss.core/trunk/tests/base.py (original)
+++ kukit/kss.core/trunk/tests/base.py Fri Dec 22 11:31:16 2006
@@ -19,7 +19,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
-from Testing.ZopeTestCase import ZopeTestCase
+from Testing.ZopeTestCase import ZopeTestCase, FunctionalTestCase
import kss.core
from kss.core import AzaxBaseView
from OFS.SimpleItem import SimpleItem
@@ -49,7 +49,7 @@
class IDebugRequest(IBrowserRequest):
'The debug request'
-class AzaxViewTestCase(ZopeTestCase):
+class KssViewTestCase(ZopeTestCase):
def afterSetUp(self):
placelesssetup.setUp()
@@ -120,3 +120,10 @@
else:
import Products.Five.zcml
Products.Five.zcml._context = None
+
+class KssViewFunctionalTestCase(FunctionalTestCase, KssViewTestCase):
+ 'Functional test base'
+
+
+# backward compatibility
+AzaxViewTestCase = KssViewTestCase
Modified: kukit/kss.core/trunk/tests/test_siteview.py
==============================================================================
--- kukit/kss.core/trunk/tests/test_siteview.py (original)
+++ kukit/kss.core/trunk/tests/test_siteview.py Fri Dec 22 11:31:16 2006
@@ -1,25 +1,14 @@
-#from base import AzaxViewTestCase, FakeContent, TestRequest, DebugTestRequest
-#from kss.core import AzaxUnicodeError
-#from kss.core.events import AzaxEvent
-#from kss.core.interfaces import IAzaxCommands, IAzaxEvent
-#from kss.core.interfaces import IAzaxView
-#from kss.core.pluginregistry.action import Action
-#from kss.core.pluginregistry.commandset import CommandSet
-#from kss.core.pluginregistry.interfaces import IAction, ICommandSet
-#from kss.core.pluginregistry.plugin import registerPlugin
-#from kss.core.plugins.core.commands import KSSCoreCommands
-#from kss.core.plugins.core.interfaces import IKSSCoreCommands
-#from kss.core.tests.base import IDebugRequest
-#from kss.core.tests.commandinspector import CommandInspectorView
from Products.Five import zcml
from zope import component
from zope.component import eventtesting
from zope.testing import doctest
from zope.testing.cleanup import CleanUp as PlacelessSetup
import Products.Five
-import unittest #, os
+import unittest
+from Testing.ZopeTestCase import FunctionalDocFileSuite
+from base import KssViewFunctionalTestCase
-def setUpDoctTest(test=None):
+def setUpDocTest(test=None):
PlacelessSetup().setUp()
eventtesting.setUp()
@@ -29,11 +18,31 @@
zcml.load_config("configure.zcml", Products.Five.site)
-def tearDownDoctTest(test=None):
+def tearDownDocTest(test=None):
PlacelessSetup().tearDown()
+def setUpFDocTest(test=None):
+ #PlacelessSetup().setUp()
+ KssViewFunctionalTestCase.setUp(test)
+ eventtesting.setUp()
+
+# zcml.load_config("meta.zcml", Products.Five)
+# zcml.load_config("permissions.zcml", Products.Five)
+# zcml.load_config("configure.zcml", Products.Five.component)
+#
+# zcml.load_config("configure.zcml", Products.Five.site)
+# zcml.load_config("configure.zcml", Products.Five.site)
+
+def tearDownFDocTest(test=None):
+ #PlacelessSetup().tearDown()
+ KssViewFunctionalTestCase.tearDown(test)
+
def test_suite():
- suite = doctest.DocFileSuite('../siteview.txt',
- setUp=setUpDoctTest,
- tearDown=tearDownDoctTest)
+ suite = FunctionalDocFileSuite('../siteview.txt',
+ setUp=setUpDocTest,
+ tearDown=tearDownDocTest)
+ suite = FunctionalDocFileSuite('../siteview_life.txt',
+ test_class=KssViewFunctionalTestCase,
+ setUp=setUpFDocTest,
+ tearDown=tearDownFDocTest)
return unittest.TestSuite(suite)
More information about the Kukit-checkins
mailing list