[Zope-Checkins] CVS: Zope/lib/python/ZServer/tests - test_config.py:1.1.2.2
Fred L. Drake, Jr.
fred@zope.com
Thu, 27 Feb 2003 14:15:58 -0500
Update of /cvs-repository/Zope/lib/python/ZServer/tests
In directory cvs.zope.org:/tmp/cvs-serv30526
Modified Files:
Tag: new-install-branch
test_config.py
Log Message:
Add tests that check the initialization of server factory instances.
=== Zope/lib/python/ZServer/tests/test_config.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/ZServer/tests/test_config.py:1.1.2.1 Wed Feb 5 18:25:40 2003
+++ Zope/lib/python/ZServer/tests/test_config.py Thu Feb 27 14:15:56 2003
@@ -14,11 +14,14 @@
"""Test the ZServer configuration machinery."""
+import os
import StringIO
+import tempfile
import unittest
import ZConfig
import ZServer
+import ZServer.datatypes
class ZServerConfigurationTestCase(unittest.TestCase):
@@ -36,8 +39,136 @@
ZServerConfigurationTestCase.schema = schema
return self.schema
+ def load_factory(self, text):
+ conf, xxx = ZConfig.loadConfigFile(self.get_schema(),
+ StringIO.StringIO(text))
+ return conf.servers[0]
+
+ def load_unix_domain_factory(self, text):
+ fn = tempfile.mktemp()
+ f = open(fn, 'w')
+ f.close()
+ try:
+ factory = self.load_factory(text % fn)
+ finally:
+ os.unlink(fn)
+ self.assertEqual(factory.path, fn)
+ return factory
+
def test_load_schema_component(self):
self.get_schema()
+
+ def test_http_factory(self):
+ factory = self.load_factory("""\
+ <http-server>
+ address 81
+ force-connection-close true
+ webdav-source-clients cadaever
+ </http-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.HTTPServerFactory))
+ self.assertEqual(factory.host, '')
+ self.assertEqual(factory.port, 81)
+ self.check_prepare(factory)
+
+ def test_webdav_source_factory(self):
+ factory = self.load_factory("""\
+ <webdav-source-server>
+ address 82
+ force-connection-close true
+ </webdav-source-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.WebDAVSourceServerFactory))
+ self.assertEqual(factory.host, '')
+ self.assertEqual(factory.port, 82)
+ self.check_prepare(factory)
+
+ def test_pcgi_factory(self):
+ factory = self.load_unix_domain_factory("""\
+ <pcgi-server>
+ path %s
+ </pcgi-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.PCGIServerFactory))
+ self.assertEqual(factory.host, None)
+ self.assertEqual(factory.port, None)
+
+ def test_fcgi_factory(self):
+ factory = self.load_factory("""\
+ <fcgi-server>
+ address 83
+ </fcgi-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.FCGIServerFactory))
+ self.assertEqual(factory.host, '')
+ self.assertEqual(factory.port, 83)
+ self.assertEqual(factory.path, None)
+ self.check_prepare(factory)
+ factory = self.load_unix_domain_factory("""\
+ <fcgi-server>
+ address %s
+ </fcgi-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.FCGIServerFactory))
+ self.assertEqual(factory.host, None)
+ self.assertEqual(factory.port, None)
+ self.check_prepare(factory)
+
+ def test_ftp_factory(self):
+ factory = self.load_factory("""\
+ <ftp-server>
+ address 84
+ </ftp-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.FTPServerFactory))
+ self.assertEqual(factory.host, '')
+ self.assertEqual(factory.port, 84)
+ self.check_prepare(factory)
+
+ def test_monitor_factory(self):
+ factory = self.load_factory("""\
+ <monitor-server>
+ address 85
+ </monitor-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.MonitorServerFactory))
+ self.assertEqual(factory.host, '')
+ self.assertEqual(factory.port, 85)
+ self.check_prepare(factory)
+
+ def test_icp_factory(self):
+ factory = self.load_factory("""\
+ <icp-server>
+ address 86
+ </icp-server>
+ """)
+ self.assert_(isinstance(factory,
+ ZServer.datatypes.ICPServerFactory))
+ self.assertEqual(factory.host, '')
+ self.assertEqual(factory.port, 86)
+ self.check_prepare(factory)
+
+ def check_prepare(self, factory):
+ port = factory.port
+ o = object()
+ factory.prepare("127.0.0.1", o, "module",
+ {"key": "value"}, portbase=9300)
+ self.assert_(factory.dnsresolver is o)
+ self.assertEqual(factory.module, "module")
+ self.assertEqual(factory.cgienv.items(), [("key", "value")])
+ if port is None:
+ self.assert_(factory.host is None)
+ self.assert_(factory.port is None)
+ else:
+ self.assertEqual(factory.host, "127.0.0.1")
+ self.assertEqual(factory.port, 9300 + port)
def test_suite():