[Zope3-checkins] SVN: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/ Move tests to a tests directory in preparation for future work.

Brian Sutherland jinty at web.de
Mon Apr 9 13:28:17 EDT 2007


Log message for revision 74054:
  Move tests to a tests directory in preparation for future work.

Changed:
  U   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/appsetup.py
  D   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/bootstrap.txt
  D   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/schema.txt
  A   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/
  A   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/__init__.py
  A   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/bootstrap.txt
  A   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/schema.txt
  A   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/test_doctest.py
  D   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests.py

-=-
Modified: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/appsetup.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/appsetup.py	2007-04-09 16:38:09 UTC (rev 74053)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/appsetup.py	2007-04-09 17:28:16 UTC (rev 74054)
@@ -211,6 +211,24 @@
 
     return result, databases
 
+def setup_app_factory(database_factories):
+    app_factory = zope.component.queryUtility(zope.app.appsetup.interfaces.IApplicationFactory)
+    if app_factory is None:
+        # We don't have an application factory registered, so we try to make
+        # a ZODB one from the options (probably parsing the options should
+        # just register the utility in future)
+        from zope.app.zodb.app import ZODBApplicationFactory
+        db = multi_database(database_factories)[0][0]
+        app_factory = ZODBApplicationFactory(db)
+    else:
+        # Error rather than do unintuitive stuff
+        marker = object()
+        if database_factories:
+            raise AssertionError("A ZODB database has been specified in options "
+                                 "and an IApplicationFactory utility has been "
+                                 "registered. Don't know which one to use.")
+    app_factory.prepare()
+    return app_factory
 
 __config_context = None
 def getConfigContext():

Deleted: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/bootstrap.txt
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/bootstrap.txt	2007-04-09 16:38:09 UTC (rev 74053)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/bootstrap.txt	2007-04-09 17:28:16 UTC (rev 74054)
@@ -1,84 +0,0 @@
-Bootstrap helpers
-=================
-
-The bootstrap helpers provide a number of functions that help with
-bootstrapping.
-
-The bootStrapSubscriber function makes sure that there is a root
-object.  It subscribes to DatabaseOpened events:
-
-    >>> from zope.app.appsetup import bootstrap
-    >>> from zope.app.appsetup import interfaces
-
-    >>> from ZODB.tests import util
-    >>> db = util.DB()
-    >>> bootstrap.bootStrapSubscriber(interfaces.DatabaseOpened(db))
-
-The subscriber makes ure that there is a root folder:
-
-    >>> from zope.app.publication.zopepublication import ZopePublication
-    >>> conn = db.open()
-    >>> root = conn.root()[ZopePublication.root_name]
-    >>> sm = root.getSiteManager()
-    >>> conn.close()
-
-A DatabaseOpenedWithRoot is generated with the database.
-
-    >>> from zope.component.eventtesting import getEvents
-    >>> [event] = getEvents(interfaces.IDatabaseOpenedWithRootEvent)
-    >>> event.database is db
-    True
-
-Generally, startup code that expects the root object and site to have
-been created will want to subscribe to this event, not
-IDataBaseOpenedEvent.
-
-The subscriber generates the event whether or not the root had to be
-set up:
-
-    >>> bootstrap.bootStrapSubscriber(interfaces.DatabaseOpened(db))
-    >>> [e, event] = getEvents(interfaces.IDatabaseOpenedWithRootEvent)
-    >>> event.database is db
-    True
-
-
-Check the Security Policy
--------------------------
-
-When the security policy got refactored to be really pluggable, the
-inclusion of the security policy configuration was moved to the very
-top level, to site.zcml.  This happened in r24770, after ZopeX3 3.0
-was released, but before 3.1.
-
-Now the maintainers of existing 3.0 sites need to manually update
-their site.zcml to include securitypolicy.zcml while upgrading to 3.1.
-See also http://www.zope.org/Collectors/Zope3-dev/381 .
-
-    >>> from zope.testing.loggingsupport import InstalledHandler
-    >>> handler = InstalledHandler('zope.app.appsetup')
-
-If the security policy is unset from the default
-ParanoidSecurityPolicy, we get a warning:
-
-    >>> from zope.app.appsetup.bootstrap import checkSecurityPolicy
-    >>> event = object()
-    >>> checkSecurityPolicy(event)
-    >>> print handler
-    zope.app.appsetup WARNING
-      Security policy is not configured.
-    Please make sure that securitypolicy.zcml is included in site.zcml immediately
-    before principals.zcml
-
-However, if any non-default security policy is installed, no warning
-is emitted:
-
-    >>> from zope.security.management import setSecurityPolicy
-    >>> defaultPolicy = setSecurityPolicy(object())
-    >>> handler.clear()
-    >>> checkSecurityPolicy(event)
-    >>> print handler
-    <BLANKLINE>
-
-Clean up:
-
-    >>> handler.uninstall()

Deleted: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/schema.txt
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/schema.txt	2007-04-09 16:38:09 UTC (rev 74053)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/schema.txt	2007-04-09 17:28:16 UTC (rev 74054)
@@ -1,36 +0,0 @@
-Test the zope application ZConfig Schema
-========================================
-
-    >>> import os
-    >>> import doctest
-    >>> import ZConfig
-
-    >>> here = os.path.dirname(__file__)
-    >>> schemafile = os.path.join(here, "schema", "schema.xml")
-    >>> schema = ZConfig.loadSchema(schemafile)
-
-Try load a very minimal zope.conf:
-
-    >>> MINIMAL_ZOPE_CONF = """
-    ... <eventlog>
-    ...     <logfile>
-    ...         path event.log
-    ...     </logfile>
-    ... </eventlog>
-    ... """
-
-Make a temporary file to hold the zope.conf:
-
-    >>> import tempfile
-    >>> _, conf = tempfile.mkstemp()
-    >>> f = open(conf, 'w')
-    >>> f.write(MINIMAL_ZOPE_CONF)
-    >>> f.close()
-
-Load it up:
-
-    >>> configroot, _ = ZConfig.loadConfig(schema, conf)
-
-Cleanup:
-
-    >>> os.remove(conf)

Added: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/__init__.py
===================================================================


Property changes on: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/bootstrap.txt (from rev 74016, Zope3/branches/jinty-zodbless/src/zope/app/appsetup/bootstrap.txt)

Copied: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/schema.txt (from rev 74052, Zope3/branches/jinty-zodbless/src/zope/app/appsetup/schema.txt)
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/schema.txt	2007-04-09 16:31:02 UTC (rev 74052)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/schema.txt	2007-04-09 17:28:16 UTC (rev 74054)
@@ -0,0 +1,36 @@
+Test the zope application ZConfig Schema
+========================================
+
+    >>> import os
+    >>> import doctest
+    >>> import ZConfig
+
+    >>> here = os.path.dirname(__file__)
+    >>> schemafile = os.path.join(os.path.dirname(here), "schema", "schema.xml")
+    >>> schema = ZConfig.loadSchema(schemafile)
+
+Try load a very minimal zope.conf:
+
+    >>> MINIMAL_ZOPE_CONF = """
+    ... <eventlog>
+    ...     <logfile>
+    ...         path event.log
+    ...     </logfile>
+    ... </eventlog>
+    ... """
+
+Make a temporary file to hold the zope.conf:
+
+    >>> import tempfile
+    >>> _, conf = tempfile.mkstemp()
+    >>> f = open(conf, 'w')
+    >>> f.write(MINIMAL_ZOPE_CONF)
+    >>> f.close()
+
+Load it up:
+
+    >>> configroot, _ = ZConfig.loadConfig(schema, conf)
+
+Cleanup:
+
+    >>> os.remove(conf)

Copied: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/test_doctest.py (from rev 74052, Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests.py)

Deleted: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests.py	2007-04-09 16:38:09 UTC (rev 74053)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests.py	2007-04-09 17:28:16 UTC (rev 74054)
@@ -1,174 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# 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.
-#
-##############################################################################
-"""Bootstrap tests
-
-$Id$
-"""
-import unittest
-import transaction
-
-from ZODB.tests.util import DB
-from zope.testing import doctest
-from zope.traversing.api import traverse
-
-from zope.app import zapi
-from zope.app.component import hooks
-from zope.app.component.testing import PlacefulSetup
-from zope.app.error.error import ErrorReportingUtility
-from zope.app.error.interfaces import IErrorReportingUtility
-from zope.app.folder import rootFolder, Folder
-from zope.app.folder.interfaces import IRootFolder
-from zope.app.publication.zopepublication import ZopePublication
-from zope.app.component.site import LocalSiteManager
-
-from zope.app.appsetup.bootstrap import bootStrapSubscriber
-from zope.app.appsetup.bootstrap import getInformationFromEvent, \
-     ensureObject, ensureUtility
-
-from zope.app.testing import placelesssetup
-
-class EventStub(object):
-
-    def __init__(self, db):
-        self.database = db
-
-#
-# TODO: some methods from the boostap modue are not tested
-#
-
-class TestBootstrapSubscriber(PlacefulSetup, unittest.TestCase):
-
-    def setUp(self):
-        PlacefulSetup.setUp(self)
-        self.db = DB()
-
-    def tearDown(self):
-        transaction.abort()
-        PlacefulSetup.tearDown(self)
-        self.db.close()
-
-    def createRootFolder(self):
-        cx = self.db.open()
-        root = cx.root()
-        self.root_folder = rootFolder()
-        root[ZopePublication.root_name] = self.root_folder
-        transaction.commit()
-        cx.close()
-
-    def createRFAndSM(self):
-        cx = self.db.open()
-        root = cx.root()
-        self.root_folder = rootFolder()
-        root[ZopePublication.root_name] = self.root_folder
-        self.site_manager = LocalSiteManager(self.root_folder)
-        self.root_folder.setSiteManager(self.site_manager)
-
-        sub_folder = Folder()
-        self.root_folder["sub_folder"] = sub_folder
-        sub_site_manager = LocalSiteManager(sub_folder)
-        sub_folder.setSiteManager(sub_site_manager)
-
-        transaction.commit()
-        cx.close()
-
-    def test_notify(self):
-        for setup in (lambda: None), self.createRootFolder, self.createRFAndSM:
-            setup()
-        bootStrapSubscriber(EventStub(self.db))
-        cx = self.db.open()
-        root = cx.root()
-        root_folder = root.get(ZopePublication.root_name, None)
-        self.assert_(IRootFolder.providedBy(root_folder))
-        package_name = '/++etc++site/default'
-        package = traverse(root_folder, package_name)
-        cx.close()
-
-    def test_ensureUtilityForSubSite(self):
-        self.createRFAndSM()
-
-        db, connection, root, root_folder = getInformationFromEvent(
-            EventStub(self.db))
-
-        sub_folder = root_folder['sub_folder']
-        ensureUtility(sub_folder, IErrorReportingUtility,
-                     'ErrorReporting', ErrorReportingUtility,
-                     'ErrorReporting', asObject=True)
-    
-        # Make sure it was created on the sub folder, not the root folder
-        got_utility = zapi.getUtility(IErrorReportingUtility, name='ErrorReporting',
-                context=sub_folder)
-        got_path = zapi.getPath(got_utility)
-        self.assertEquals("/sub_folder/++etc++site/default/ErrorReporting", got_path)
-
-    def test_ensureUtility(self):
-        self.createRFAndSM()
-
-        db, connection, root, root_folder = getInformationFromEvent(
-            EventStub(self.db))
-
-        # TODO: check EventSub
-        root_folder = self.root_folder
-        for i in range(2):
-            cx = self.db.open()
-            utility = ensureUtility(root_folder, IErrorReportingUtility,
-                                    'ErrorReporting', ErrorReportingUtility,
-                                    'ErrorReporting', asObject=True)
-            utility2 = ensureUtility(root_folder, IErrorReportingUtility,
-                                     'ErrorReporting2', ErrorReportingUtility,
-                                     'ErrorReporting2', asObject=True)
-            if utility != None:
-                name = utility.__name__
-                name2 = utility2.__name__
-            else:
-                name = None
-                name2 = None
-            if i == 0:
-                self.assertEqual(name, 'ErrorReporting')
-                self.assertEqual(name2, 'ErrorReporting2')
-            else:
-                self.assertEqual(name, None)
-                self.assertEqual(name2, None)
-
-            root = cx.root()
-            root_folder = root[ZopePublication.root_name]
-
-            package_name = '/++etc++site/default'
-            package = traverse(self.root_folder, package_name)
-
-            self.assert_(IErrorReportingUtility.providedBy(
-                traverse(package, 'ErrorReporting')))
-            self.assert_(IErrorReportingUtility.providedBy(
-                traverse(package, 'ErrorReporting2')))
-            transaction.commit()
-
-        cx.close()
-
-def bootstraptearDown(test):
-    test.globs['db'].close()
-
-def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(TestBootstrapSubscriber))
-    suite.addTest(doctest.DocTestSuite(
-        'zope.app.appsetup.appsetup',
-        setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown))
-    suite.addTest(doctest.DocFileSuite('schema.txt'))
-    suite.addTest(doctest.DocFileSuite(
-        'bootstrap.txt',
-        setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown,
-        ))
-    return suite
-
-if __name__ == '__main__':
-    unittest.main()



More information about the Zope3-Checkins mailing list