[Zope-CVS] CVS: Products/CompositePage/tests -
test_composite.py:1.1 test_macro.py:NONE
Shane Hathaway
shane at zope.com
Fri Mar 5 16:41:07 EST 2004
Update of /cvs-repository/Products/CompositePage/tests
In directory cvs.zope.org:/tmp/cvs-serv9514/tests
Added Files:
test_composite.py
Removed Files:
test_macro.py
Log Message:
Added a new page template expression type, "slot:".
"slot:" provides a concise way to declare composite slots in page templates.
It is designed to replace metal:define-slot.
Also augmented interfaces and fixed a race condition in the slot
generator. If two people used the _v_used_names mechanism
simultaneously, the results would be unpredictable. Now, the tracking
is done on the Composite instead.
=== Added File Products/CompositePage/tests/test_composite.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""Composite tests.
$Id: test_composite.py,v 1.1 2004/03/05 21:41:06 shane Exp $
"""
import unittest
import ZODB
from OFS.Folder import Folder
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
from Products.CompositePage.slot import Slot
from Products.CompositePage.composite import Composite
from Products.CompositePage.element import CompositeElement
from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
import AccessControl.User # Get the "nobody" user defined
from Products.CompositePage.tests.test_tool import PermissiveSecurityPolicy
template_text = '''\
<html>
<body>
<div tal:replace="structure slot: slot_a (top) 'Top News Stories'">slot_a</div>
<span tal:replace="structure slot: slot_b 'Other News'">slot_b</span>
<div tal:replace="structure here/slots/slot_c">slot_c</div>
</body>
</html>
'''
metal_template_text = '''\
<html metal:define-macro="page">
<body>
<div metal:define-slot="slot_a">slot_a</div>
</body>
</html>
'''
class CompositeTests(unittest.TestCase):
def setUp(self):
f = Folder()
f.getPhysicalPath = lambda: ()
f.getPhysicalRoot = lambda: f
f.composite = Composite()
f.composite._setId("composite")
t = ZopePageTemplate(
id="template", text=template_text, content_type="text/html")
if t.pt_errors():
raise SyntaxError(t.pt_errors())
f.composite.template = t
f.composite.filled_slots.slot_a = slot_a = Slot("slot_a")
a1 = ZopePageTemplate(id="a1", text="<b>Slot A</b>")
f._setObject(a1.id, a1)
e1 = CompositeElement('e1', f.a1)
slot_a._setObject(e1.id, e1)
self.composite = f.composite
self.old_policy = setSecurityPolicy(PermissiveSecurityPolicy())
noSecurityManager()
def tearDown(self):
setSecurityPolicy(self.old_policy)
noSecurityManager()
def assertTextEqual(self, a, b):
a = a.strip().replace("\n", "")
b = b.strip().replace("\n", "")
self.assertEqual(a, b)
def testRender(self):
rendered = self.composite()
expected = ('<html><body>'
'<div class="slot_header"></div><div><b>Slot A</b></div>'
'<div class="slot_header"></div>'
'<div class="slot_header"></div>'
'</body></html>')
self.assertTextEqual(rendered, expected)
def testGetManifest(self):
manifest = self.composite.getManifest()
self.assertEqual(len(manifest), 3)
self.assertEqual(manifest[0]['name'], 'slot_a')
self.assertEqual(manifest[0]['title'], 'Top News Stories')
self.assertEqual(manifest[0]['class_name'], 'top')
self.assertEqual(
manifest[0]['target_path'], 'composite/filled_slots/slot_a')
self.assertEqual(len(manifest[0]['elements']), 1)
self.assertEqual(manifest[1]['name'], 'slot_b')
self.assertEqual(manifest[1]['title'], 'Other News')
self.assertEqual(manifest[1]['class_name'], None)
self.assertEqual(
manifest[1]['target_path'], 'composite/filled_slots/slot_b')
self.assertEqual(len(manifest[1]['elements']), 0)
self.assertEqual(manifest[2]['name'], 'slot_c')
self.assertEqual(manifest[2]['title'], 'slot_c')
self.assertEqual(manifest[2]['class_name'], None)
self.assertEqual(
manifest[2]['target_path'], 'composite/filled_slots/slot_c')
self.assertEqual(len(manifest[2]['elements']), 0)
def testMetal(self):
t = ZopePageTemplate(
id="template", text=metal_template_text, content_type="text/html")
self.composite.template = t
rendered = self.composite()
expected = ('<html><body>'
'<div class="slot_header"></div><div><b>Slot A</b></div>'
'</body></html>')
self.assertTextEqual(rendered, expected)
if __name__ == "__main__":
unittest.main()
=== Removed File Products/CompositePage/tests/test_macro.py ===
More information about the Zope-CVS
mailing list