[Zope-Checkins] CVS: Zope/lib/python/Zope/Startup/tests - __init__.py:1.4 test_schema.py:1.4
Fred L. Drake, Jr.
fred@zope.com
Tue, 18 Mar 2003 16:37:50 -0500
Update of /cvs-repository/Zope/lib/python/Zope/Startup/tests
In directory cvs.zope.org:/tmp/cvs-serv27358/tests
Added Files:
__init__.py test_schema.py
Log Message:
Merge startup code from the new-install-branch.
=== Zope/lib/python/Zope/Startup/tests/__init__.py 1.3 => 1.4 ===
--- /dev/null Tue Mar 18 16:37:50 2003
+++ Zope/lib/python/Zope/Startup/tests/__init__.py Tue Mar 18 16:37:50 2003
@@ -0,0 +1,15 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+
+"""Tests of the Zope.Startup package."""
=== Zope/lib/python/Zope/Startup/tests/test_schema.py 1.3 => 1.4 ===
--- /dev/null Tue Mar 18 16:37:50 2003
+++ Zope/lib/python/Zope/Startup/tests/test_schema.py Tue Mar 18 16:37:50 2003
@@ -0,0 +1,100 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+
+"""Test that the Zope schema can be loaded."""
+
+import os
+import cStringIO
+import tempfile
+import unittest
+
+import ZConfig
+import Zope.Startup
+
+from Zope.Startup import datatypes
+
+from App.config import getConfiguration
+
+
+TEMPNAME = tempfile.mktemp()
+
+
+class StartupTestCase(unittest.TestCase):
+
+ def load_config_text(self, text):
+ # We have to create a directory of our own since the existence
+ # of the directory is checked. This handles this in a
+ # platform-independent way.
+ schema = Zope.Startup.getSchema()
+ sio = cStringIO.StringIO(
+ text.replace("<<INSTANCE_HOME>>", TEMPNAME))
+ os.mkdir(TEMPNAME)
+ try:
+ conf, handler = ZConfig.loadConfigFile(schema, sio)
+ finally:
+ os.rmdir(TEMPNAME)
+ self.assertEqual(conf.instancehome, TEMPNAME)
+ return conf
+
+ def test_load_config_template(self):
+ schema = Zope.Startup.getSchema()
+ cfg = getConfiguration()
+ fn = os.path.join(cfg.zopehome, "skel", "etc", "zope.conf.in")
+ f = open(fn)
+ text = f.read()
+ f.close()
+ self.load_config_text(text)
+
+ def test_cgi_environment(self):
+ conf = self.load_config_text("""\
+ # instancehome is here since it's required
+ instancehome <<INSTANCE_HOME>>
+ <cgi-environment>
+ HEADER value
+ ANOTHER value2
+ </cgi-environment>
+ """)
+ items = conf.cgi_environment.items()
+ items.sort()
+ self.assertEqual(items, [("ANOTHER", "value2"), ("HEADER", "value")])
+
+ def test_access_and_trace_logs(self):
+ fn = tempfile.mktemp()
+ conf = self.load_config_text("""
+ instancehome <<INSTANCE_HOME>>
+ <logger access>
+ <logfile>
+ path %s
+ </logfile>
+ </logger>
+ """ % fn)
+ self.assert_(isinstance(conf.access, datatypes.LoggerFactory))
+ self.assertEqual(conf.access.name, "access")
+ self.assertEqual(conf.access.handler_factories[0].section.path, fn)
+ self.assert_(conf.trace is None)
+
+ def test_dns_resolver(self):
+ from ZServer.medusa import resolver
+ conf = self.load_config_text("""\
+ instancehome <<INSTANCE_HOME>>
+ dns-server localhost
+ """)
+ self.assert_(isinstance(conf.dns_resolver, resolver.caching_resolver))
+
+
+def test_suite():
+ return unittest.makeSuite(StartupTestCase)
+
+if __name__ == "__main__":
+ unittest.main(defaultTest="test_suite")