Log message for revision 113935:
  merge branch gotcha-processlifetime
  
  notify IDatabaseOpenedWithRoot
  
  test also for IDatabaseOpened
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/Zope2/App/startup.py
  A   Zope/trunk/src/Zope2/App/tests/test_startup.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst  2010-06-27 13:52:05 UTC (rev 113934)
+++ Zope/trunk/doc/CHANGES.rst  2010-06-27 13:58:58 UTC (rev 113935)
@@ -18,6 +18,8 @@
 Features Added
 ++++++++++++++
 
+- Added notification of IDatabaseOpenedWithRoot.
+
 - Added a new API's ``get_registered_packages, set_registered_packages`` to
   ``OFS.metaconfigure`` which replace any direct access to
   ``Products._registered_packages``.

Modified: Zope/trunk/src/Zope2/App/startup.py
===================================================================
--- Zope/trunk/src/Zope2/App/startup.py 2010-06-27 13:52:05 UTC (rev 113934)
+++ Zope/trunk/src/Zope2/App/startup.py 2010-06-27 13:58:58 UTC (rev 113935)
@@ -16,6 +16,7 @@
 from zope.component import queryMultiAdapter
 from zope.event import notify
 from zope.processlifetime import DatabaseOpened
+from zope.processlifetime import DatabaseOpenedWithRoot
 
 from AccessControl.SecurityManagement import newSecurityManager
 from AccessControl.SecurityManagement import noSecurityManager
@@ -134,6 +135,8 @@
     global startup_time
     startup_time = asctime()
 
+    notify(DatabaseOpenedWithRoot(DB))
+
     Zope2.zpublisher_transactions_manager = TransactionsManager()
     Zope2.zpublisher_exception_hook = zpublisher_exception_hook
     Zope2.zpublisher_validated_hook = validated_hook
@@ -206,7 +209,7 @@
             else:
                 error_log_url = log.raising((t, v, traceback))
 
-            if (REQUEST is None or 
+            if (REQUEST is None or
                 (getattr(REQUEST.get('RESPONSE', None), '_error_format', '')
                  != 'text/html')):
                 raise t, v, traceback
@@ -277,7 +280,6 @@
                 response.setStatus(t)
                 response.setBody(v)
                 return response
-
         finally:
             traceback = None
 

Copied: Zope/trunk/src/Zope2/App/tests/test_startup.py (from rev 113934, 
Zope/branches/gotcha-processlifetime/src/Zope2/App/tests/test_startup.py)
===================================================================
--- Zope/trunk/src/Zope2/App/tests/test_startup.py                              
(rev 0)
+++ Zope/trunk/src/Zope2/App/tests/test_startup.py      2010-06-27 13:58:58 UTC 
(rev 113935)
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import logging
+
+from Testing.ZopeTestCase import ZopeTestCase
+
+from zope.testing.loggingsupport import InstalledHandler
+
+logged = """Zope2.App.test_startup INFO
+  <class 'zope.processlifetime.DatabaseOpened'>
+Zope2.App.test_startup INFO
+  <class 'ZODB.DB.DB'>
+Zope2.App.test_startup INFO
+  Root not ready.
+Zope2.App.test_startup INFO
+  <class 'zope.processlifetime.DatabaseOpenedWithRoot'>
+Zope2.App.test_startup INFO
+  <class 'ZODB.DB.DB'>
+Zope2.App.test_startup INFO
+  <class 'OFS.Application.Application'>"""
+
+
+def logevent(event):
+    logger = logging.getLogger('Zope2.App.test_startup')
+    logger.info(event.__class__)
+    db = event.database
+    logger.info(db.__class__)
+    conn = db.open()
+    try:
+        try:
+            root = conn.root()
+            app = root['Application']
+            logger.info(app.__class__)
+        except KeyError:
+            logger.info('Root not ready.')
+    finally:
+        conn.close()
+
+
+class StartupTests(ZopeTestCase):
+
+    def test_dummy(self):
+        from Zope2.App.startup import startup
+        from zope.component import provideHandler
+        from zope.processlifetime import IDatabaseOpened
+        from zope.processlifetime import IDatabaseOpenedWithRoot
+
+        handler = InstalledHandler('Zope2.App.test_startup')
+        provideHandler(logevent, [IDatabaseOpenedWithRoot])
+        provideHandler(logevent, [IDatabaseOpened])
+        startup()
+        self.assertEqual(str(handler), logged)

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to