[Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate/tests - testEngineConfig.py:1.1.2.1
Shane Hathaway
shane@cvs.zope.org
Wed, 13 Mar 2002 22:37:07 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/PageTemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv2925/tests
Added Files:
Tag: Zope-3x-branch
testEngineConfig.py
Log Message:
Added a new expression engine configuration module. It allows you to
assign names to expression engines and choose which one to use per page
template or expression. This helps solve some problems:
- There was a strong dependency from Zope.PageTemplates to Zope.App.Security
and Zope.App.Traversing. Now we can just plug in a restricted expression
engine.
- Some of the tests want to run with a restricted expression engine, but some
don't. Now each test can choose which one to use.
I've also made a metaConfigure module, but I can't check it in until there
are tests for it. :-)
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/testEngineConfig.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
#
##############################################################################
"""Tests of Zope.PageTemplate.EngineConfig.
$Id: testEngineConfig.py,v 1.1.2.1 2002/03/14 03:37:06 shane Exp $
"""
import unittest
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.PageTemplate import EngineConfig
from Zope.PageTemplate.TALES import ExpressionEngine, RegistrationError
class Test(CleanUp, unittest.TestCase):
def testDefaultEngine(self):
e = EngineConfig.getEngine()
minimal_types = ('standard', 'path', 'exists', 'nocall',
'defer', 'python', 'not', 'string')
types = e.getTypes()
for t in minimal_types:
self.assert_(types.has_key(t))
def testUnrestrictedEngine(self):
# There must always be an unrestricted engine available.
EngineConfig.getEngine('unrestricted')
def testNoOverrideEngine(self):
self.assertRaises(RegistrationError, EngineConfig.registerEngine,
'unrestricted', ExpressionEngine())
def testNoDefaultMishaps(self):
self.assertRaises(RegistrationError, EngineConfig.registerEngine,
'default', ExpressionEngine())
def testRegisterSpecialEngine(self):
e = ExpressionEngine()
e._i_am_the_special_engine = 1
EngineConfig.registerEngine('special', e)
self.assert_(getattr(EngineConfig.getEngine('special'),
'_i_am_the_special_engine', None))
def testRegisterNewDefault(self):
self.testRegisterSpecialEngine()
EngineConfig.setDefaultEngine('special')
self.assert_(getattr(EngineConfig.getEngine(),
'_i_am_the_special_engine', None))
def testNoTwoDefaults(self):
self.testRegisterNewDefault()
self.assertRaises(RegistrationError, EngineConfig.setDefaultEngine,
'unrestricted')
def testCleanup(self):
self.testRegisterNewDefault()
EngineConfig._cleanup()
# The next line will raise an exception if something didn't get
# cleaned up.
self.testRegisterNewDefault()
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())