[Zope-Checkins] CVS: Zope3/lib/python/Zope/RestrictedPython/tests - testRestrictedExpressionEngine.py:1.1.2.1

Shane Hathaway shane@cvs.zope.org
Wed, 13 Mar 2002 23:17:02 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/RestrictedPython/tests
In directory cvs.zope.org:/tmp/cvs-serv17502/tests

Added Files:
      Tag: Zope-3x-branch
	testRestrictedExpressionEngine.py 
Log Message:
Added RestrictedExpressionEngine, which is derived from several pieces
of the Zope.PageTemplate package.


=== Added File Zope3/lib/python/Zope/RestrictedPython/tests/testRestrictedExpressionEngine.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.RestrictedPython.RestrictedExpressionEngine.

$Id: testRestrictedExpressionEngine.py,v 1.1.2.1 2002/03/14 04:17:02 shane Exp $
"""

import unittest
from Zope.RestrictedPython import RestrictedExpressionEngine
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.PageTemplate import EngineConfig


class Test(CleanUp, unittest.TestCase):

    def testExpressionTypes(self):
        e = EngineConfig.getEngine('restricted')
        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 testDefaultEngine(self):
        # When the RestrictedExpressionEngine module exists, the
        # restricted engine should be created automatically and
        # registered as the overrideable, implicit default.
        e1 = EngineConfig.getEngine('restricted')
        e2 = EngineConfig.getEngine()
        self.assert_(e1 is e2)

    def testExplicitDefault(self):
        EngineConfig.setDefaultEngine('restricted')
        # Now not overrideable.
        self.assertRaises(EngineConfig.RegistrationError,
                          EngineConfig.setDefaultEngine,
                          'unrestricted')


def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())