[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/StartUp/tests - __init__.py:1.2 testRegisterRequestFactory.py:1.2 testRegisterServerType.py:1.2 testRequestFactoryRegistry.py:1.2 testServerTypeRegistry.py:1.2 testSimpleRegistry.py:1.2 testStartupDirectives.py:1.2
Jim Fulton
jim@zope.com
Tue, 19 Nov 2002 18:25:45 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/StartUp/tests
In directory cvs.zope.org:/tmp/cvs-serv11465/lib/python/Zope/App/StartUp/tests
Added Files:
__init__.py testRegisterRequestFactory.py
testRegisterServerType.py testRequestFactoryRegistry.py
testServerTypeRegistry.py testSimpleRegistry.py
testStartupDirectives.py
Log Message:
Two changes that were far reaching and interdependent.
- Changed existing directives that mention interfaces to register
those interfaces with the global interface service.
- Moved all configuration support (except that in Zope.Configuration)
into Zope.App. This was necessary to get the order of execution such
that the interface service was defined before directives that used
interfaces were used. This is a change that has been needed for
some time.
=== Zope3/lib/python/Zope/App/StartUp/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:25:45 2002
+++ Zope3/lib/python/Zope/App/StartUp/tests/__init__.py Tue Nov 19 18:25:14 2002
@@ -0,0 +1,18 @@
+##############################################################################
+#
+# 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/App/StartUp/tests/testRegisterRequestFactory.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:25:45 2002
+++ Zope3/lib/python/Zope/App/StartUp/tests/testRegisterRequestFactory.py Tue Nov 19 18:25:14 2002
@@ -0,0 +1,64 @@
+##############################################################################
+#
+# 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 cStringIO import StringIO
+from Zope.Configuration.xmlconfig import xmlconfig
+from Zope.Configuration.tests.BaseTestDirectivesXML import makeconfig
+from Zope.App.StartUp.RequestFactoryRegistry import getRequestFactory
+
+
+class Test( unittest.TestCase ):
+
+ def testRegisterRequestFactory(self):
+
+ xmlconfig(makeconfig(
+ '''<directive
+ name="registerRequestFactory"
+ attributes="name publication request"
+ handler=
+ "Zope.App.StartUp.metaConfigure.registerRequestFactory"
+ />''',
+ '''<test: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/App/StartUp/tests/testRegisterServerType.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:25:45 2002
+++ Zope3/lib/python/Zope/App/StartUp/tests/testRegisterServerType.py Tue Nov 19 18:25:14 2002
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# 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 cStringIO import StringIO
+from Zope.Configuration.xmlconfig import xmlconfig
+from Zope.Configuration.tests.BaseTestDirectivesXML import makeconfig
+from Zope.App.StartUp.ServerTypeRegistry import getServerType
+
+
+class Test( unittest.TestCase ):
+
+ def testRegisterServerType(self):
+ xmlconfig(makeconfig(
+ '''<directive
+ name="registerServerType"
+ attributes="name publication request"
+ handler="Zope.App.StartUp.metaConfigure.registerServerType"
+ />''',
+ '''<test: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/App/StartUp/tests/testRequestFactoryRegistry.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:25:45 2002
+++ Zope3/lib/python/Zope/App/StartUp/tests/testRequestFactoryRegistry.py Tue Nov 19 18:25:14 2002
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# 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.App.StartUp.RequestFactoryRegistry import \
+ registerRequestFactory, getRequestFactory
+from Zope.App.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/App/StartUp/tests/testServerTypeRegistry.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:25:45 2002
+++ Zope3/lib/python/Zope/App/StartUp/tests/testServerTypeRegistry.py Tue Nov 19 18:25:14 2002
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# 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.App.StartUp.ServerTypeRegistry import \
+ registerServerType, getServerType
+from Zope.App.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/App/StartUp/tests/testSimpleRegistry.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:25:45 2002
+++ Zope3/lib/python/Zope/App/StartUp/tests/testSimpleRegistry.py Tue Nov 19 18:25:14 2002
@@ -0,0 +1,99 @@
+##############################################################################
+#
+# 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 Interface import Interface
+from Zope.App.StartUp.SimpleRegistry import SimpleRegistry, \
+ ZopeDuplicateRegistryEntryError, ZopeIllegalInterfaceError
+
+
+class I1(Interface):
+ pass
+
+
+class I2(Interface):
+ pass
+
+
+class Object1:
+ __implements__ = I1
+
+
+class Object2:
+ __implements__ = I2
+
+
+class Test( unittest.TestCase ):
+
+
+ def testRegister(self):
+
+ registry = SimpleRegistry(I1)
+ obj1 = Object1()
+
+ self.assertEqual(registry.objects, {})
+
+ registry.register('obj1', obj1)
+ self.assertEqual(registry.objects, {'obj1': obj1})
+
+ registry.register('obj2', obj1)
+ self.assertEqual(registry.objects, {'obj1': obj1, 'obj2': obj1})
+
+
+ def testIllegalInterfaceError(self):
+
+ registry = SimpleRegistry(I1)
+ obj2 = Object2()
+
+ self.failUnlessRaises(ZopeIllegalInterfaceError,
+ registry.register, 'obj2', obj2)
+
+
+ def testDuplicateEntry(self):
+
+ registry = SimpleRegistry(I1)
+ obj1 = Object1()
+ registry.register('obj1', obj1)
+
+ self.failUnlessRaises(ZopeDuplicateRegistryEntryError,
+ registry.register, 'obj1', obj1)
+
+
+ def testGet(self):
+
+ registry = SimpleRegistry(I1)
+ obj1 = Object1()
+ obj2 = Object1()
+ registry.objects = {'obj1': obj1, 'obj2': obj2}
+
+ self.assertEqual(registry.get('obj1'), obj1)
+ self.assertEqual(registry.get('obj2'), obj2)
+
+ # Requesting an object that does not exist
+ self.assertEqual(registry.get('obj3'), None)
+
+
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase( Test )
+
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )
+
=== Zope3/lib/python/Zope/App/StartUp/tests/testStartupDirectives.py 1.1 => 1.2 ===
--- /dev/null Tue Nov 19 18:25:45 2002
+++ Zope3/lib/python/Zope/App/StartUp/tests/testStartupDirectives.py Tue Nov 19 18:25:14 2002
@@ -0,0 +1,126 @@
+##############################################################################
+#
+# 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, os
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.App.StartUp.metaConfigure import SiteDefinition
+from Zope.Configuration.name import resolve
+
+_fsname = tempfile.mktemp()+'.fs'
+
+class ContextStub:
+
+ def resolve(self, dottedname):
+ return resolve(dottedname)
+
+
+class Test(CleanUp, unittest.TestCase):
+
+ def tearDown(self):
+
+ CleanUp.tearDown(self)
+
+ for ext in '', '.lock', '.index', '.tmp':
+ try: os.remove(_fsname + ext)
+ except: pass
+
+
+ def _createBlankSiteDefinition(self):
+ """ """
+ return SiteDefinition('', 'Example Site', 4)
+
+
+ def testStorageMethods(self):
+ """ """
+ sd = self._createBlankSiteDefinition()
+
+ self.assertEqual(sd.useFileStorage(ContextStub(), file=_fsname), [])
+ self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
+ self.assertEqual(sd._zodb._storage._file_name, _fsname)
+ 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)
+
+ self.assertEqual(sd.useLog(ContextStub(), _fsname), [])
+ from zLOG.MinimalLogger import _log_dest
+ self.assertEqual(_log_dest.name, open(_fsname, '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
+
+ sd.useFileStorage(ContextStub(), file=_fsname)
+
+ 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())