[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/session/ Use the new function subscriber defined within appsetup and define a function in here as well

Julien Anguenot ja at nuxeo.com
Tue Oct 12 14:11:31 EDT 2004


Log message for revision 28023:
  Use the new function subscriber defined within appsetup and define a function in here as well


Changed:
  U   Zope3/trunk/src/zope/app/session/bootstrap.py
  U   Zope3/trunk/src/zope/app/session/configure.zcml
  U   Zope3/trunk/src/zope/app/session/tests.py


-=-
Modified: Zope3/trunk/src/zope/app/session/bootstrap.py
===================================================================
--- Zope3/trunk/src/zope/app/session/bootstrap.py	2004-10-12 18:10:21 UTC (rev 28022)
+++ Zope3/trunk/src/zope/app/session/bootstrap.py	2004-10-12 18:11:29 UTC (rev 28023)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2002 Zope Corporation and Contributors.
+# Copyright (c) 2002, 2004 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -20,24 +20,31 @@
 $Id$
 """
 
-from zope.app.appsetup.bootstrap import BootstrapSubscriberBase
+from zope.app.appsetup.bootstrap import ensureUtility, getInformationFromEvent
 
-
 from zope.app.session.interfaces import \
      IClientIdManager, ISessionDataContainer
 from zope.app.session.http import CookieClientIdManager
 from zope.app.session.session import PersistentSessionDataContainer
 
-class BootstrapInstance(BootstrapSubscriberBase):
+def bootStrapSubscriber(event):
+    """Subscriber to the IDataBaseOpenedEvent
 
-    def doSetup(self):
-        self.ensureUtility(
-                IClientIdManager, 'CookieClientIdManager',
-                CookieClientIdManager,
-                )
-        self.ensureUtility(
-                ISessionDataContainer, 'PersistentSessionDataContainer',
-                PersistentSessionDataContainer,
-                )
+    Create utility at that time if not yet present
+    """
 
-bootstrapInstance = BootstrapInstance()
+    db, connection, root, root_folder = getInformationFromEvent(event)
+
+    ensureUtility(
+        root_folder,
+        IClientIdManager, 'CookieClientIdManager',
+        CookieClientIdManager,
+        )
+    ensureUtility(
+        root_folder,
+        ISessionDataContainer, 'PersistentSessionDataContainer',
+        PersistentSessionDataContainer,
+        )
+
+    get_transaction().commit()
+    connection.close()

Modified: Zope3/trunk/src/zope/app/session/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/session/configure.zcml	2004-10-12 18:10:21 UTC (rev 28022)
+++ Zope3/trunk/src/zope/app/session/configure.zcml	2004-10-12 18:11:29 UTC (rev 28023)
@@ -66,7 +66,7 @@
 
   <subscriber
       for="zope.app.appsetup.IDatabaseOpenedEvent"
-      factory=".bootstrap.bootstrapInstance"
+      factory=".bootstrap.bootStrapSubscriber"
       />
 
   <include file="browser.zcml" />

Modified: Zope3/trunk/src/zope/app/session/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/session/tests.py	2004-10-12 18:10:21 UTC (rev 28022)
+++ Zope3/trunk/src/zope/app/session/tests.py	2004-10-12 18:11:29 UTC (rev 28023)
@@ -34,6 +34,11 @@
 
 from zope.pagetemplate.pagetemplate import PageTemplate
 
+from zope.app.appsetup.tests import TestBootstrapSubscriber, EventStub
+from zope.app.appsetup.bootstrap import bootStrapSubscriber
+from zope.app.session.bootstrap import bootStrapSubscriber as \
+     sessionBootstrapSubscriber
+
 def setUp(session_data_container_class=PersistentSessionDataContainer):
     placelesssetup.setUp()
     ztapi.provideAdapter(IRequest, IClientId, ClientId)
@@ -48,19 +53,17 @@
 def tearDown():
     placelesssetup.tearDown()
 
+class TestBootstrap(TestBootstrapSubscriber):
 
-from zope.app.appsetup.tests import TestBootstrapSubscriberBase, EventStub
-class TestBootstrapInstance(TestBootstrapSubscriberBase):
+    def test_bootstrapSusbcriber(self):
+        bootStrapSubscriber(EventStub(self.db))
 
-    def test_bootstrapInstance(self):
-        from zope.app.appsetup.bootstrap import bootstrapInstance
-        bootstrapInstance(EventStub(self.db))
-        from zope.app.session.bootstrap import bootstrapInstance
-        bootstrapInstance(EventStub(self.db))
+        sessionBootstrapSubscriber(EventStub(self.db))
+
         from zope.app.publication.zopepublication import ZopePublication
         from zope.app.component.hooks import setSite
         from zope.app import zapi
-        
+
         cx = self.db.open()
         root = cx.root()
         root_folder = root[ZopePublication.root_name]
@@ -68,8 +71,8 @@
 
         zapi.getUtility(IClientIdManager)
         zapi.getUtility(ISessionDataContainer)
-        
-        
+
+
         cx.close()
 
 # Test the code in our API documentation is correct
@@ -85,15 +88,14 @@
     ''' % (open(os.path.join(os.path.dirname(__file__), 'api.txt')).read(),)
 
 def test_suite():
-    return unittest.TestSuite((
-        doctest.DocTestSuite(),
-        doctest.DocTestSuite('zope.app.session.session'),
-        doctest.DocTestSuite('zope.app.session.http'),
-        unittest.makeSuite(TestBootstrapInstance),
-        ))
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(TestBootstrap))
+    suite.addTest(doctest.DocTestSuite())
+    suite.addTest(doctest.DocTestSuite('zope.app.session.session'))
+    suite.addTest(doctest.DocTestSuite('zope.app.session.http'))
+    return suite
 
 if __name__ == '__main__':
     unittest.main()
 
 # vim: set filetype=python ts=4 sw=4 et si
-



More information about the Zope3-Checkins mailing list