Commit 9713f0a2 authored by Godefroid Chapelle's avatar Godefroid Chapelle

merge branch gotcha-processlifetime

notify IDatabaseOpenedWithRoot

test also for IDatabaseOpened
parents 59cedb99 aa3f3a07
......@@ -18,6 +18,8 @@ Bugs Fixed
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``.
......
......@@ -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 @@ def startup():
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 @@ class ZPublisherExceptionHook:
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 @@ class ZPublisherExceptionHook:
response.setStatus(t)
response.setBody(v)
return response
finally:
traceback = None
......
##############################################################################
#
# 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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment