[Zope-Checkins] CVS: Zope3/lib/python/Zope/StartUp/tests - __init__.py:1.2 testRegisterRequestFactory.py:1.2 testRegisterServerType.py:1.2 testRequestFactoryRegistry.py:1.2 testServerTypeRegistry.py:1.2 testStartupDirectives.py:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:30:14 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/StartUp/tests
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/StartUp/tests
Added Files:
__init__.py testRegisterRequestFactory.py
testRegisterServerType.py testRequestFactoryRegistry.py
testServerTypeRegistry.py testStartupDirectives.py
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/StartUp/tests/__init__.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
=== Zope3/lib/python/Zope/StartUp/tests/testRegisterRequestFactory.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+from Zope.StartUp.RequestFactoryRegistry import getRequestFactory
+
+from Zope.Configuration.xmlconfig import xmlconfig
+from cStringIO import StringIO
+
+
+template = """<zopeConfigure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:startup='http://namespaces.zope.org/startup'>
+ %s
+ </zopeConfigure>"""
+
+
+class Test( unittest.TestCase ):
+
+
+ def testRegisterRequestFactory(self):
+
+ xmlconfig(StringIO(template % (
+ '''
+ <directive name="registerRequestFactory"
+ attributes="name publication request"
+ handler="Zope.StartUp.metaConfigure.registerRequestFactory"
+ namespace="http://namespaces.zope.org/startup" />
+
+ <startup:registerRequestFactory name="BrowserRequestFactory"
+ publication =
+ "Zope.App.ZopePublication.Browser.Publication.BrowserPublication"
+ request = "Zope.Publisher.Browser.BrowserRequest." />
+ '''
+ )))
+
+ from Zope.App.ZopePublication.Browser.Publication import \
+ BrowserPublication
+ from Zope.Publisher.Browser.BrowserRequest import BrowserRequest
+
+ self.assertEqual(
+ getRequestFactory('BrowserRequestFactory')._pubFactory,
+ BrowserPublication)
+ self.assertEqual(
+ getRequestFactory('BrowserRequestFactory')._request,
+ BrowserRequest)
+
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase( Test )
+
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )
=== Zope3/lib/python/Zope/StartUp/tests/testRegisterServerType.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""terServerType.py,v 1.1.2.2 2002/04/02 02:20:40 srichter Exp $
+"""
+
+import unittest
+from Zope.StartUp.ServerTypeRegistry import getServerType
+
+from Zope.Configuration.xmlconfig import xmlconfig
+from cStringIO import StringIO
+
+
+template = """<zopeConfigure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:startup='http://namespaces.zope.org/startup'>
+ %s
+ </zopeConfigure>"""
+
+
+class Test( unittest.TestCase ):
+
+
+ def testRegisterServerType(self):
+
+ xmlconfig(StringIO(template % (
+ '''<directive name="registerServerType"
+ attributes="name publication request"
+ handler="Zope.StartUp.metaConfigure.registerServerType"
+ namespace="http://namespaces.zope.org/startup" />
+
+ <startup:registerServerType
+ name = "Browser"
+ factory = "Zope.Server.HTTP.PublisherHTTPServer."
+ requestFactory="BrowserRequestFactory"
+ logFactory = "Zope.Server.HTTP.CommonHitLogger."
+ defaultPort="8080"
+ defaultVerbose="true" />
+ '''
+ )))
+
+ from Zope.Server.HTTP.PublisherHTTPServer import PublisherHTTPServer
+ from Zope.Server.HTTP.CommonHitLogger import CommonHitLogger
+
+ self.assertEqual(getServerType('Browser')._factory,
+ PublisherHTTPServer)
+ self.assertEqual(getServerType('Browser')._logFactory, CommonHitLogger)
+ self.assertEqual(getServerType('Browser')._requestFactory,
+ "BrowserRequestFactory")
+ self.assertEqual(getServerType('Browser')._defaultPort, 8080)
+ self.assertEqual(getServerType('Browser')._defaultVerbose, 1)
+
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase( Test )
+
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )
+
=== Zope3/lib/python/Zope/StartUp/tests/testRequestFactoryRegistry.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""
+I do not think it is necessary to do the entire SimpleRegistry tests again.
+Instead we will test whether the module in itself works.
+
+$Id$
+"""
+
+import unittest
+from Zope.StartUp.RequestFactoryRegistry import \
+ registerRequestFactory, getRequestFactory
+from Zope.StartUp.RequestFactory import IRequestFactory
+
+
+class RequestFactory:
+ """RequestFactory Stub."""
+
+ __implements__ = IRequestFactory
+
+
+
+class Test( unittest.TestCase ):
+
+
+ def testRegistry(self):
+
+ factory = RequestFactory()
+
+ registerRequestFactory('factory', factory)
+ self.assertEqual(getRequestFactory('factory'), factory)
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase( Test )
+
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )
+
=== Zope3/lib/python/Zope/StartUp/tests/testServerTypeRegistry.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""
+I do not think it is necessary to do the entire SimpleRegistry tests again.
+Instead we will test whether the module in itself works.
+
+$Id$
+"""
+
+import unittest
+from Zope.StartUp.ServerTypeRegistry import \
+ registerServerType, getServerType
+from Zope.StartUp.ServerType import IServerType
+
+
+class ServerType:
+ """ServerType Stub."""
+
+ __implements__ = IServerType
+
+
+
+class Test( unittest.TestCase ):
+
+
+ def testRegistry(self):
+
+ server = ServerType()
+
+ registerServerType('server', server)
+ self.assertEqual(getServerType('server'), server)
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase( Test )
+
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )
+
=== Zope3/lib/python/Zope/StartUp/tests/testStartupDirectives.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest, sys, tempfile
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.StartUp.metaConfigure import SiteDefinition
+from Zope.Configuration.name import resolve
+
+class ContextStub:
+
+ def resolve(self, dottedname):
+ return resolve(dottedname)
+
+
+class Test(CleanUp, unittest.TestCase):
+
+
+ def _createBlankSiteDefinition(self):
+ """ """
+ return SiteDefinition('', 'Example Site', 4)
+
+
+ def testStorageMethods(self):
+ """ """
+ sd = self._createBlankSiteDefinition()
+
+ self.assertEqual(sd.useFileStorage(ContextStub()), [])
+ self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
+ self.assertEqual(sd._zodb._storage._file_name, 'Data.fs')
+ sd._zodb.close()
+
+ filename = tempfile.mktemp()
+ self.assertEqual(sd.useFileStorage(ContextStub(), file=filename), [])
+ self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
+ self.assertEqual(sd._zodb._storage._file_name, filename)
+ sd._zodb.close()
+
+ self.assertEqual(sd.useMappingStorage(ContextStub()), [])
+ self.assertEqual(sd._zodb._storage.__class__.__name__,
+ 'MappingStorage')
+
+
+ def testUseLog(self):
+ """ """
+
+ sd = self._createBlankSiteDefinition()
+
+ from zLOG.MinimalLogger import _log_dest
+
+ self.assertEqual(sd.useLog(ContextStub()), [])
+ self.assertEqual(_log_dest, sys.stderr)
+
+ filename = tempfile.mktemp()
+ self.assertEqual(sd.useLog(ContextStub(), filename), [])
+ from zLOG.MinimalLogger import _log_dest
+ self.assertEqual(_log_dest.name, open(filename, 'w').name)
+
+
+ def testAddServer(self):
+ """ """
+
+ sd = self._createBlankSiteDefinition()
+
+ from Zope.Configuration.Action import Action
+
+ self.assertEqual(sd.addServer(ContextStub(), 'Browser',
+ '8081', 'true'), [])
+ self.assertEqual(len(sd._servers), 1)
+ self.assertEqual(sd._servers.keys(), ['Browser'])
+
+ server_info = sd._servers['Browser']
+ self.assertEqual(server_info['port'], 8081)
+ self.assertEqual(server_info['verbose'], 1)
+
+
+ def testInitDB(self):
+ """ """
+
+ sd = self._createBlankSiteDefinition()
+
+
+ from Zope.App.OFS.Content.Folder.RootFolder import IRootFolder
+ from Zope.App.ZopePublication.ZopePublication import ZopePublication
+
+ filename = tempfile.mktemp()
+ sd.useFileStorage(ContextStub(), file=filename)
+
+ connection = sd._zodb.open()
+ root = connection.root()
+ app = root.get(ZopePublication.root_name, None)
+ connection.close()
+ self.assertEqual(app, None)
+
+ sd._initDB()
+
+ connection = sd._zodb.open()
+ root = connection.root()
+ app = root.get(ZopePublication.root_name, None)
+ connection.close()
+ self.failUnless(IRootFolder.isImplementedBy(app))
+
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())