[Zope3-checkins] SVN: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/ Add tests for load_app_factory, which unfortunately was committed in the previous commit.

Brian Sutherland jinty at web.de
Mon Apr 9 17:10:33 EDT 2007


Log message for revision 74061:
  Add tests for load_app_factory, which unfortunately was committed in the previous commit.

Changed:
  A   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/minimal_zope.conf
  U   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/schema.txt
  U   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/test_doctest.py
  A   Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/zodb_zope.conf

-=-
Added: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/minimal_zope.conf
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/minimal_zope.conf	2007-04-09 19:58:57 UTC (rev 74060)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/minimal_zope.conf	2007-04-09 21:10:32 UTC (rev 74061)
@@ -0,0 +1,5 @@
+<eventlog>
+    <logfile>
+        path event.log
+    </logfile>
+</eventlog>

Modified: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/schema.txt
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/schema.txt	2007-04-09 19:58:57 UTC (rev 74060)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/schema.txt	2007-04-09 21:10:32 UTC (rev 74061)
@@ -9,28 +9,78 @@
     >>> 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()
+    >>> conf = os.path.join(here, "minimal_zope.conf")
 
 Load it up:
 
-    >>> configroot, _ = ZConfig.loadConfig(schema, conf)
+    >>> options, _ = ZConfig.loadConfig(schema, conf)
 
-Cleanup:
 
-    >>> os.remove(conf)
+Application Factory Setup as a Utility
+======================================
+
+For zope to start traversal, it needs an object to start from. The application
+factory provides that. We can provide a very simple one.
+
+    >>> from zope.app.appsetup.interfaces import IApplicationFactory
+    >>> class ApplicationFactoryStub:
+    ...     def prepare(self):
+    ...         print "prepare called"
+    ...     def __call__(self, request):
+    ...         print "__call__ called"
+
+We need to register it as an IApplicationFactory utility so that the zope
+configuration will pick it up:
+
+    >>> from zope.app.testing import ztapi
+    >>> ztapi.provideUtility(IApplicationFactory, ApplicationFactoryStub())
+
+Note that the databases attribute is an empty list:
+
+    >>> options.databases
+    []
+
+Now we can setup the application factory:
+
+    >>> from zope.app.appsetup.appsetup import setup_app_factory
+    >>> setup_app_factory(options.databases)
+    prepare called
+    <...ApplicationFactoryStub...>
+
+Unregister the utility:
+
+    >>> ztapi.unprovideUtility(IApplicationFactory)
+
+
+Application Factory Setup in zope.conf (ZODB)
+=============================================
+
+Another way of configuring an IApplicationFactory is to place a <zodb> section
+in the config file:
+
+    >>> conf = os.path.join(here, "zodb_zope.conf")
+    >>> options, _ = ZConfig.loadConfig(schema, conf)
+
+Note that the databases attribute is not an empty list:
+
+    >>> options.databases
+    [<...ZODBDatabase...>]
+
+Now we can setup the application factory:
+
+    >>> setup_app_factory(options.databases)
+    <...ZODBApplicationFactory...>
+
+When we try to use both methods to setup, we get an error:
+
+    >>> ztapi.provideUtility(IApplicationFactory, ApplicationFactoryStub())
+    >>> setup_app_factory(options.databases)
+    Traceback (most recent call last):
+        ...
+    AssertionError: ...
+
+Unregister the utility:
+
+    >>> ztapi.unprovideUtility(IApplicationFactory)

Modified: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/test_doctest.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/test_doctest.py	2007-04-09 19:58:57 UTC (rev 74060)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/test_doctest.py	2007-04-09 21:10:32 UTC (rev 74061)
@@ -19,6 +19,7 @@
 import transaction
 
 from ZODB.tests.util import DB
+from zope.interface import implements
 from zope.testing import doctest
 from zope.traversing.api import traverse
 
@@ -32,6 +33,7 @@
 from zope.app.publication.zopepublication import ZopePublication
 from zope.app.component.site import LocalSiteManager
 
+from zope.app.appsetup.interfaces import IApplicationFactory
 from zope.app.appsetup.bootstrap import bootStrapSubscriber
 from zope.app.appsetup.bootstrap import getInformationFromEvent, \
      ensureObject, ensureUtility
@@ -157,13 +159,24 @@
 def bootstraptearDown(test):
     test.globs['db'].close()
 
+class ApplicationFactoryStub:
+
+    implements(IApplicationFactory)
+
+    def prepare(self):
+        print "Prepare called"
+
+    def __call__(self, request):
+        print "__call__ called"
+
 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('schema.txt',
+        optionflags=doctest.ELLIPSIS))
     suite.addTest(doctest.DocFileSuite(
         'bootstrap.txt',
         setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown,

Added: Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/zodb_zope.conf
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/zodb_zope.conf	2007-04-09 19:58:57 UTC (rev 74060)
+++ Zope3/branches/jinty-zodbless/src/zope/app/appsetup/tests/zodb_zope.conf	2007-04-09 21:10:32 UTC (rev 74061)
@@ -0,0 +1,8 @@
+<eventlog>
+    <logfile>
+        path event.log
+    </logfile>
+</eventlog>
+<zodb>
+    <demostorage/>
+</zodb>



More information about the Zope3-Checkins mailing list