installBroken(event)
Install a class factory that handled broken objects
This method installs a custom class factory when it gets a database-opened event:
>>> import ZODB.tests.util >>> from zope.app.appsetup import DatabaseOpened >>> db = ZODB.tests.util.DB() >>> installBroken(DatabaseOpened(db))
If someone tries to load an object for which there is no class, then they will get a Broken object. We can simulate that by calling the database's class factory directly with a connection (None will do for our purposes, since the class factory function we register ignores the connection argument), a non-existent module and class name:
>>> cls = db.classFactory(None, 'ZODB.not.there', 'atall')
The class that comes back is a subclass of Broken:
>>> issubclass(cls, Broken) True
It implements ILocation and IAnnotations:
>>> zope.location.interfaces.ILocation.implementedBy(cls) True >>> IAnnotations.implementedBy(cls) True
and it has a security checker that is the same as the checker that Broken has:
>>> (cls.__Security_checker__ is ... zope.security.checker.getCheckerForInstancesOf(Broken)) True
Cleanup:
>>> ZODB.broken.broken_cache.clear()