[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ZMI/tests - testStandardMacros.py:1.2
Steve Alexander
steve@cat-box.net
Mon, 28 Oct 2002 06:21:14 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/ZMI/tests
In directory cvs.zope.org:/tmp/cvs-serv24555/tests
Modified Files:
testStandardMacros.py
Log Message:
Made StandardMacros work by seeking pages with macros by name, rather
than by directly importing the PageTemplate files.
Added view_macros and dialog_macros back in as views.
=== Zope3/lib/python/Zope/App/ZMI/tests/testStandardMacros.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/ZMI/tests/testStandardMacros.py:1.1 Tue Oct 22 15:34:59 2002
+++ Zope3/lib/python/Zope/App/ZMI/tests/testStandardMacros.py Mon Oct 28 06:21:14 2002
@@ -17,40 +17,81 @@
"""
import unittest, sys
+from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup\
+ import PlacefulSetup
+from Zope.ComponentArchitecture import getService
+from Zope.Publisher.Browser.IBrowserView import IBrowserView
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
from Interface import Interface
-from Zope.PageTemplate.IMacrosAttribute import IMacrosAttribute
from Zope.App.ZMI.StandardMacros import Macros
-class DummyPageTemplate:
- __implements__ = IMacrosAttribute
+class ViewWithMacros:
+ __implements__ = IBrowserView
- def __init__(self, macros):
- '''macros is a dict for pages'''
- self.macros = macros
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def __call__(self):
+ pass
+
+ def __getitem__(self, key):
+ return self.pages[key]
-page1 = DummyPageTemplate({'foo':'page1_foo', 'bar':'page1_bar'})
-collides_with_page1 = DummyPageTemplate({'foo':'collides_with_page1_foo',
- 'baz':'collides_with_page1_baz'})
-works_with_page1 = DummyPageTemplate({'fish':'works_with_page1_fish',
- 'tree':'works_with_page1_tree'})
+ pages = {}
-class Test(unittest.TestCase):
+class I(Interface): pass
+
+class C:
+ __implements__ = I
+
+class Request:
+ def getPresentationType(self):
+ return IBrowserPresentation
+ def getPresentationSkin(self):
+ return ''
+
+class page1(ViewWithMacros):
+ pages = {'foo':'page1_foo',
+ 'bar':'page1_bar'}
+
+class collides_with_page1(ViewWithMacros):
+ pages = {'foo':'collides_with_page1_foo',
+ 'baz':'collides_with_page1_baz'}
+
+class works_with_page1(ViewWithMacros):
+ pages = {'fish':'works_with_page1_fish',
+ 'tree':'works_with_page1_tree'}
+
+def createMacrosInstance(pages):
+ from Zope.App.ZMI.StandardMacros import Macros
+ class T(Macros):
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+ macro_pages = pages
+ return T(C(), Request())
+
+class Test(PlacefulSetup, unittest.TestCase):
+
+ def setUp(self):
+ PlacefulSetup.setUp(self)
+ provideView = getService(None,"Views").provideView
+ provideView(I, 'page1', IBrowserPresentation, [page1])
+ provideView(I, 'collides_with_page1', IBrowserPresentation,
+ [collides_with_page1])
+ provideView(I, 'works_with_page1', IBrowserPresentation,
+ [works_with_page1])
def testSinglePage(self):
- from Zope.App.ZMI.StandardMacros import Macros
- class T(Macros):
- macro_pages = (page1,)
- macros = T()
+ macros = createMacrosInstance(('page1',))
self.assertEqual(macros['foo'], 'page1_foo')
self.assertEqual(macros['bar'], 'page1_bar')
self.assertRaises(KeyError, macros.__getitem__, 'fish')
def testConcordentPages(self):
- from Zope.App.ZMI.StandardMacros import Macros
- class T(Macros):
- macro_pages = (page1, works_with_page1)
- macros = T()
+ macros = createMacrosInstance(('page1', 'works_with_page1'))
self.assertEqual(macros['foo'], 'page1_foo')
self.assertEqual(macros['bar'], 'page1_bar')
self.assertEqual(macros['fish'], 'works_with_page1_fish')
@@ -58,17 +99,14 @@
self.assertRaises(KeyError, macros.__getitem__, 'pants')
def testConflictingPages(self):
- from Zope.App.ZMI.StandardMacros import Macros
- class T(Macros):
- macro_pages = (page1, collides_with_page1)
- macros = T()
+ macros = createMacrosInstance(('page1', 'collides_with_page1'))
self.assertEqual(macros['foo'], 'page1_foo')
self.assertEqual(macros['bar'], 'page1_bar')
self.assertEqual(macros['baz'], 'collides_with_page1_baz')
self.assertRaises(KeyError, macros.__getitem__, 'pants')
def test_suite():
- loader=unittest.TestLoader()
+ loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':