[Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate/tests - testBasicTemplate.py:1.1.2.6 testExpressions.py:1.1.2.8 testHTMLTests.py:1.1.2.10 SimpleTestView.py:NONE sample.py:NONE test.pt:NONE testBoundPageTemplate.py:NONE testEngineConfig.py:NONE testSimpleViewClass.pt:NONE testSimpleViewClass.py:NONE testViewZPT.py:NONE test_binding.py:NONE
Jim Fulton
jim@zope.com
Thu, 23 May 2002 14:01:51 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/PageTemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv26429/lib/python/Zope/PageTemplate/tests
Modified Files:
Tag: Zope-3x-branch
testBasicTemplate.py testExpressions.py testHTMLTests.py
Removed Files:
Tag: Zope-3x-branch
SimpleTestView.py sample.py test.pt testBoundPageTemplate.py
testEngineConfig.py testSimpleViewClass.pt
testSimpleViewClass.py testViewZPT.py test_binding.py
Log Message:
This all started with wanting to be able to use url;view in a ZPT path. :)
That lead me to:
- Massive traversal refactoring.
Namespace handling is now centralized in Zope.App.Traversing.
- ZPT refactoring, including some renaming that touches pretty much everything. :)
- The application specific ZPT support was moved into
Zope.App.PageTemplate.
- To get page template files (for use in views):
from Zope.App.PageTemplate import ViewPageTemplateFile
- Fixed up security so that ZPT expressions only have access to
safe builtins and so that modules namespace does imports safely.
- Got ZPTPage working!
- renaming url to absolute_url and got absolute_url to work in paths.
- Cleaned up the (as yet unused) RestrictedInterpreter module in
Zope.Security. In particular, changed to use a separate
RestrictedBuiltins module.
=== Zope3/lib/python/Zope/PageTemplate/tests/testBasicTemplate.py 1.1.2.5 => 1.1.2.6 ===
from Zope.PageTemplate.tests import util
-from Zope.PageTemplate.ZPT import ZPT
-from Zope.PageTemplate.EngineConfig import setDefaultEngine
-from Zope.Testing.CleanUp import CleanUp
+from Zope.PageTemplate.PageTemplate import PageTemplate
-
-class BasicTemplateTests(unittest.TestCase, CleanUp):
+class BasicTemplateTests(unittest.TestCase):
def setUp(self):
- CleanUp.setUp(self)
- setDefaultEngine('unrestricted')
- self.t = ZPT()
+ self.t = PageTemplate()
def check_if_in_var(self):
"""DTML test 1: if, in, and var:
@@ -51,13 +46,13 @@
self.t.write(tal)
aa = util.argv(('one', 'two', 'three', 'cha', 'cha', 'cha'))
- o = self.t.__get__(aa)()
+ o = self.t(content=aa)
expect = util.read_output('DTML1a.html')
util.check_xml(expect, o)
aa = util.argv(())
- o = self.t.__get__(aa)()
+ o = self.t(content=aa)
expect = util.read_output('DTML1b.html')
util.check_xml(expect, o)
@@ -99,7 +94,7 @@
'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty',
))
from Zope.PageTemplate.tests import batch
- o = self.t.__get__(aa)(batch=batch.batch(aa.args, 5))
+ o = self.t(content=aa, batch=batch.batch(aa.args, 5))
expect = util.read_output('DTML3.html')
util.check_xml(expect, o)
=== Zope3/lib/python/Zope/PageTemplate/tests/testExpressions.py 1.1.2.7 => 1.1.2.8 ===
import os, sys, unittest
-from Zope.PageTemplate.EngineConfig import getEngine
+from Zope.PageTemplate.Engine import Engine
+
+class Data:
+
+ def __init__(self, **kw):
+ self.__dict__.update(kw)
+
+ def __repr__(self): return self.name
+
+def dict(**kw): return kw
class ExpressionTests(unittest.TestCase):
def testCompile(self):
'''Test expression compilation'''
- e = getEngine('unrestricted')
- for p in ('x', 'x/y', 'x/y/z'):
- e.compile(p)
- e.compile('path:a|b|c/d/e')
- e.compile('string:Fred')
- e.compile('string:A$B')
- e.compile('string:a ${x/y} b ${y/z} c')
- e.compile('python: 2 + 2')
- e.compile('python: 2 \n+\n 2\n')
+ context = Data(
+ vars = dict(
+ x = Data(
+ name = 'xander',
+ y = Data(
+ name = 'yikes',
+ z = Data(name = 'zope')
+ )
+ ),
+ y = Data(z = 3),
+ b = 'boot',
+ B = 2,
+ )
+ )
+
+
+ engine = Engine
+
+ expr = engine.compile('x')
+ self.assertEqual(expr(context), context.vars['x'])
+
+ expr = engine.compile('x/y')
+ self.assertEqual(expr(context), context.vars['x'].y)
+
+ expr = engine.compile('x/y/z')
+ self.assertEqual(expr(context), context.vars['x'].y.z)
+
+ expr = engine.compile('path:a|b|c/d/e')
+ self.assertEqual(expr(context), 'boot')
+
+ expr = engine.compile('string:Fred')
+ self.assertEqual(expr(context), 'Fred')
+
+ expr = engine.compile('string:A$B')
+ self.assertEqual(expr(context), 'A2')
+
+ expr = engine.compile('string:a ${x/y} b ${y/z} c')
+ self.assertEqual(expr(context), 'a yikes b 3 c')
+
+ expr = engine.compile('python: 2 + 2')
+ self.assertEqual(expr(context), 4)
+
+ expr = engine.compile('python: 2 \n+\n 2\n')
+ self.assertEqual(expr(context), 4)
def test_suite():
return unittest.makeSuite(ExpressionTests)
=== Zope3/lib/python/Zope/PageTemplate/tests/testHTMLTests.py 1.1.2.9 => 1.1.2.10 ===
from Zope.PageTemplate.tests import util
-from Zope.PageTemplate.ZPT import ZPT
-from Zope.PageTemplate.EngineConfig import setDefaultEngine
-from Zope.Testing.CleanUp import CleanUp
+from Zope.PageTemplate.PageTemplate import PageTemplate
class Folder:
def getContext(self):
return self
-class HTMLTests(unittest.TestCase, CleanUp):
+class HTMLTests(unittest.TestCase):
def setUp(self):
- CleanUp.setUp(self)
- setDefaultEngine('unrestricted')
self.folder = f = Folder()
- f.laf = ZPT()
- f.t = ZPT()
+ f.laf = PageTemplate()
+ f.t = PageTemplate()
def getProducts(self):
return [
@@ -45,7 +41,7 @@
]
def check1(self):
- laf = self.folder.laf.__get__(self.folder)
+ laf = self.folder.laf
laf.write(util.read_input('TeeShopLAF.html'))
expect = util.read_output('TeeShopLAF.html')
util.check_html(expect, laf())
@@ -53,73 +49,73 @@
def check2(self):
self.folder.laf.write(util.read_input('TeeShopLAF.html'))
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('TeeShop2.html'))
expect = util.read_output('TeeShop2.html')
- out = t(getProducts=self.getProducts)
+ out = t(laf = self.folder.laf, getProducts = self.getProducts)
util.check_html(expect, out)
def check3(self):
self.folder.laf.write(util.read_input('TeeShopLAF.html'))
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('TeeShop1.html'))
expect = util.read_output('TeeShop1.html')
- out = t(getProducts=self.getProducts)
+ out = t(laf = self.folder.laf, getProducts = self.getProducts)
util.check_html(expect, out)
def checkSimpleLoop(self):
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('Loop1.html'))
expect = util.read_output('Loop1.html')
out = t()
util.check_html(expect, out)
def checkGlobalsShadowLocals(self):
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('GlobalsShadowLocals.html'))
expect = util.read_output('GlobalsShadowLocals.html')
out = t()
util.check_html(expect, out)
def checkStringExpressions(self):
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('StringExpression.html'))
expect = util.read_output('StringExpression.html')
out = t()
util.check_html(expect, out)
def checkReplaceWithNothing(self):
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('CheckNothing.html'))
expect = util.read_output('CheckNothing.html')
out = t()
util.check_html(expect, out)
def checkWithXMLHeader(self):
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('CheckWithXMLHeader.html'))
expect = util.read_output('CheckWithXMLHeader.html')
out = t()
util.check_html(expect, out)
def checkNotExpression(self):
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('CheckNotExpression.html'))
expect = util.read_output('CheckNotExpression.html')
out = t()
util.check_html(expect, out)
def checkPathNothing(self):
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('CheckPathNothing.html'))
expect = util.read_output('CheckPathNothing.html')
out = t()
util.check_html(expect, out)
def checkPathAlt(self):
- t = self.folder.t.__get__(self.folder)
+ t = self.folder.t
t.write(util.read_input('CheckPathAlt.html'))
expect = util.read_output('CheckPathAlt.html')
out = t()
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/SimpleTestView.py ===
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/sample.py ===
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/test.pt ===
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/testBoundPageTemplate.py ===
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/testEngineConfig.py ===
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/testSimpleViewClass.pt ===
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/testSimpleViewClass.py ===
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/testViewZPT.py ===
=== Removed File Zope3/lib/python/Zope/PageTemplate/tests/test_binding.py ===