[Zope3-checkins] CVS: Zope3/src/zope/app/startup/tests - __init__.py:1.2 test_registerrequestfactory.py:1.2 test_registerservertype.py:1.2 test_requestfactoryregistry.py:1.2 test_servertyperegistry.py:1.2 test_simpleregistry.py:1.2 test_startupdirectives.py:1.2
Jim Fulton
jim@zope.com
Wed, 25 Dec 2002 09:13:57 -0500
Update of /cvs-repository/Zope3/src/zope/app/startup/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/startup/tests
Added Files:
__init__.py test_registerrequestfactory.py
test_registerservertype.py test_requestfactoryregistry.py
test_servertyperegistry.py test_simpleregistry.py
test_startupdirectives.py
Log Message:
Grand renaming:
- Renamed most files (especially python modules) to lower case.
- Moved views and interfaces into separate hierarchies within each
project, where each top-level directory under the zope package
is a separate project.
- Moved everything to src from lib/python.
lib/python will eventually go away. I need access to the cvs
repository to make this happen, however.
There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.
=== Zope3/src/zope/app/startup/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/startup/tests/__init__.py Wed Dec 25 09:13:25 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
=== Zope3/src/zope/app/startup/tests/test_registerrequestfactory.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/startup/tests/test_registerrequestfactory.py Wed Dec 25 09:13:25 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.publication.browser.BrowserPublication"
+ request = "zope.publisher.browser.BrowserRequest" />
+ '''
+ ))
+
+ from zope.app.publication.browser import \
+ BrowserPublication
+ from zope.publisher.browser 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/src/zope/app/startup/tests/test_registerservertype.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/startup/tests/test_registerservertype.py Wed Dec 25 09:13:25 2002
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# 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.PublisherHTTPServer"
+ requestFactory="BrowserRequestFactory"
+ logFactory =
+ "zope.server.http.commonhitlogger.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/src/zope/app/startup/tests/test_requestfactoryregistry.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/startup/tests/test_requestfactoryregistry.py Wed Dec 25 09:13:25 2002
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# 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/src/zope/app/startup/tests/test_servertyperegistry.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/startup/tests/test_servertyperegistry.py Wed Dec 25 09:13:25 2002
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# 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/src/zope/app/startup/tests/test_simpleregistry.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/startup/tests/test_simpleregistry.py Wed Dec 25 09:13:25 2002
@@ -0,0 +1,98 @@
+##############################################################################
+#
+# 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.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/src/zope/app/startup/tests/test_startupdirectives.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/startup/tests/test_startupdirectives.py Wed Dec 25 09:13:25 2002
@@ -0,0 +1,129 @@
+##############################################################################
+#
+# 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
+import logging
+
+from zope.app.services.tests.placefulsetup import \
+ PlacefulSetup
+from zope.app.startup.metaconfigure import SiteDefinition
+from zope.configuration.name import resolve
+from zope.component.adapter import provideAdapter
+
+_fsname = tempfile.mktemp()+'.fs'
+
+class ContextStub:
+
+ def resolve(self, dottedname):
+ return resolve(dottedname)
+
+
+class Test(PlacefulSetup, unittest.TestCase):
+
+ def tearDown(self):
+
+ PlacefulSetup.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.close()
+
+ self.assertEqual(sd.useMappingStorage(ContextStub()), [])
+ self.assertEqual(sd._zodb._storage.__class__.__name__,
+ 'MappingStorage')
+ sd.close()
+
+
+ def testUseLog(self):
+ sd = self._createBlankSiteDefinition()
+
+ self.assertEqual(sd.useLog(ContextStub()), [])
+ for h in logging.root.handlers:
+ if isinstance(h, logging.StreamHandler):
+ if h.stream is sys.stderr:
+ break
+ else:
+ self.fail("Not logging to sys.stderr")
+
+ self.assertEqual(sd.useLog(ContextStub(), _fsname), [])
+ for h in logging.root.handlers:
+ if isinstance(h, logging.FileHandler):
+ if h.baseFilename == _fsname:
+ break
+ else:
+ self.fail("Not logging to _fsname")
+
+
+ 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.interfaces.content.folder import IRootFolder
+ from zope.app.publication.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()
+
+ try:
+ connection = sd._zodb.open()
+ root = connection.root()
+ app = root.get(ZopePublication.root_name, None)
+ connection.close()
+ self.failUnless(IRootFolder.isImplementedBy(app))
+ finally:
+ sd.close()
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())