[Zope-Checkins] CVS: Zope3/lib/python/Zope/StartUp/tests - __init__.py:1.1.2.1 testStartupDirectives.py:1.1.2.1
Stephan Richter
srichter@cbu.edu
Fri, 29 Mar 2002 14:44:21 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/StartUp/tests
In directory cvs.zope.org:/tmp/cvs-serv18519/lib/python/Zope/StartUp/tests
Added Files:
Tag: Zope-3x-branch
__init__.py testStartupDirectives.py
Log Message:
This is a first tackle of creating a Zope startup configuration file. It is
not very flexible at the moment, simply because I do not know what is ahead
of us. However, I think it is better than what we had before.
Features:
- Specify the types of servers you want to start
- Decide which type of ZODB storage to use
- Decide where the logs should be written to.
Planned (if agreed with by the community):
- Make a server type registry, where developers can register new servers,
so that the site admin has only to select them and is not challenged with
implementation details.
- Make a second registry for ZODB storage type for the same reasons as
above.
- Split the startup configuration into two sections:
1. The programmer directives, that do all the low level stuff and provide
the services for the higher level settings.
2. The Site Admin directives, which then use the objects, which were
provided by the programmers
=== Added File Zope3/lib/python/Zope/StartUp/tests/__init__.py ===
##############################################################################
#
# 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: __init__.py,v 1.1.2.1 2002/03/29 19:44:19 srichter Exp $
"""
=== Added File Zope3/lib/python/Zope/StartUp/tests/testStartupDirectives.py ===
##############################################################################
#
# 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: testStartupDirectives.py,v 1.1.2.1 2002/03/29 19:44:19 srichter Exp $
"""
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 testStorageMethod(self):
"""Note: I could not name the test testUseStorage, since another
test would throw errors."""
sd = self._createBlankSiteDefinition()
self.assertEqual(sd.useStorage(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.useStorage(ContextStub(), file=filename), [])
self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
self.assertEqual(sd._zodb._storage._file_name, filename)
sd._zodb.close()
# XXX: There should be more tests here for other Storage types. I just
# do not know enough about it.
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()),
[ Action(discriminator = 'Start Servers',
callable = sd.start,
args = (),
) ]
)
self.assertEqual(len(sd._servers), 1)
self.assertEqual(sd._servers.keys(), ['Browser'])
server_info = sd._servers['Browser']
server_type = sd._server_types['Browser']
self.assertEqual(server_info['server'], server_type[0])
self.assertEqual(server_info['publication'], server_type[1])
self.assertEqual(server_info['request'], server_type[2])
self.assertEqual(server_info['port'], 8081)
self.assertEqual(server_info['logClass'],
resolve('Zope.Server.HTTPServer.CommonHitLogger'))
self.assertEqual(server_info['verbose'], 1)
def testInitDB(self):
""" """
sd = self._createBlankSiteDefinition()
from Zope.App.OFS.Folder.RootFolder import IRootFolder
from Zope.App.ZopePublication.ZopePublication import ZopePublication
filename = tempfile.mktemp()
sd.useStorage(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())