def test_disallowed_builtin(self): from zope.pagetemplate.engine import ZopePythonExpr expr = ZopePythonExpr('python', 'open("x", "w")', DummyEngine()) self.assertRaises(NameError, expr, DummyContext())
def test_allowed_module_name(self): from zope.pagetemplate.engine import ZopePythonExpr expr = ZopePythonExpr('python', '__import__("sys").__name__', DummyEngine()) self.assertEqual(expr(DummyContext()), 'sys')
def test_forbidden_module_name(self): from zope.pagetemplate.engine import ZopePythonExpr from zope.security.interfaces import Forbidden expr = ZopePythonExpr('python', '__import__("sys").exit', DummyEngine()) self.assertRaises(Forbidden, expr, DummyContext())
def test_simple(self): from zope.pagetemplate.engine import ZopePythonExpr expr = ZopePythonExpr('python', 'max(a,b)', DummyEngine()) self.assertEqual(expr(DummyContext(a=1, b=2)), 2)