[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZMI/tests - __init__.py:1.2 sampleInterfaces.py:1.2 testProvideClass.py:1.2 testServiceProvideClass.py:1.2 testTabsDirective.py:1.2 testZMIViewService.py:1.2 testZMIViewUtility.py:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:29:50 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/ZMI/tests
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/App/ZMI/tests

Added Files:
	__init__.py sampleInterfaces.py testProvideClass.py 
	testServiceProvideClass.py testTabsDirective.py 
	testZMIViewService.py testZMIViewUtility.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.

=== Zope3/lib/python/Zope/App/ZMI/tests/__init__.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+""" ZMI unit tests """


=== Zope3/lib/python/Zope/App/ZMI/tests/sampleInterfaces.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+from Interface import Interface
+
+from Zope.App.Traversing.ITraverser import ITraverser
+
+class FakeTraverser:
+
+    __implements__ = ITraverser
+
+    def __init__(self, *args, **kw): pass
+
+    def traverse(self, *args, **kw):
+        return None
+
+
+class I1(Interface): pass
+class I2(I1): pass
+
+class O1:
+    __implements__ = I1
+    
+class O2:
+    __implements__ = I2    


=== Zope3/lib/python/Zope/App/ZMI/tests/testProvideClass.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+""" ZMI unit tests
+
+$Id$
+"""
+
+
+import unittest, sys, Interface
+from Zope.App.OFS.Services.AddableService.tests.AddableSetup import AddableSetup
+import Zope.Configuration.name
+
+class MyAddableObject:
+    pass
+
+class ProvideClassTest(AddableSetup, unittest.TestCase):
+
+    def testProvideClass(self):
+        from Zope.ComponentArchitecture import getService
+        from Zope.App.ZMI import provideClass
+
+        provideClass(registry="AddableContent", 
+                     qualified_name="My.Test.Addable",
+                     _class=MyAddableObject,
+                     permission=None,
+                     title='Testing')
+
+        obj = getService(None, "Factories").createObject('My.Test.Addable')
+        self.assert_(isinstance(obj, MyAddableObject))
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase(ProvideClassTest)
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/lib/python/Zope/App/ZMI/tests/testServiceProvideClass.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+""" ZMI unit tests
+
+$Id$
+"""
+
+
+import unittest, sys, Interface, os
+from Zope.App.ZMI import provideClass
+
+from StringIO import StringIO
+from Zope.Configuration.xmlconfig import xmlconfig
+from Zope.App.OFS.Services.AddableService.tests.AddableSetup \
+     import AddableSetup
+from Zope.Configuration.xmlconfig import ZopeXMLConfigurationError
+from Zope.ComponentArchitecture import getService
+
+import Zope.App.ZMI
+defs_path = os.path.join(
+    os.path.split(Zope.App.ZMI.__file__)[0],
+    'zmi-meta.zcml')
+
+
+class MyAddableService:
+    pass
+
+class ServiceProvideClassTest(AddableSetup, unittest.TestCase):
+
+    def setUp(self):
+        AddableSetup.setUp(self)
+        xmlconfig(open(defs_path))
+
+    def testServiceProvideClassDirective(self):
+        serviceName = (
+            'Zope.App.ZMI.tests.testServiceProvideClass.MyAddableService')
+        
+        xmlconfig( StringIO('''
+        <zopeConfigure
+        xmlns="http://namespaces.zope.org/zope"
+        xmlns:service="http://namespaces.zope.org/service">
+
+        <service:factoryFromClass
+                 id="%s"
+                 class="%s"
+                 permission="Zope.AddService"
+                 title="Stupid Service"
+                 description="This is a sample Service" />
+      
+        </zopeConfigure>
+        ''' %(serviceName, serviceName)))
+
+        addables = getService(None,"AddableServices").getAddables(None)
+        self.assertEqual(addables[0].id, serviceName)
+      
+        
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase(ServiceProvideClassTest)
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/lib/python/Zope/App/ZMI/tests/testTabsDirective.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest, sys
+
+
+from StringIO import StringIO
+
+from Zope.App.ZMI.ZMIViewService import ZMIViews
+from Zope.Configuration.xmlconfig import xmlconfig
+from Zope.Configuration.xmlconfig import ZopeXMLConfigurationError
+
+from Interface import Interface
+
+from Zope.App.ZMI.tests.sampleInterfaces import *
+
+from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup\
+           import PlacefulSetup
+from Zope.ComponentArchitecture import getService
+
+class Test(PlacefulSetup, unittest.TestCase):
+
+    #XXX we should have a test for multiple inheritance interface
+    # hierarchies.
+
+    def testZMITabDirective(self):
+        xmlconfig( StringIO("""
+        <zopeConfigure
+          xmlns='http://namespaces.zope.org/zope'
+          xmlns:zmi='http://namespaces.zope.org/zmi'>
+
+          <directive name="tabs" attributes="for" 
+             namespace="http://namespaces.zope.org/zmi"
+             handler="Zope.App.ZMI.TabsDirective.">
+            <subdirective name="tab" attributes="label action filter" />
+          </directive>
+          <zmi:tabs for="Zope.App.ZMI.tests.sampleInterfaces.I1">
+            <zmi:tab label="Edit" action="edit" />
+            <zmi:tab label="History" action="history" />
+          </zmi:tabs>
+          <zmi:tabs for="Zope.App.ZMI.tests.sampleInterfaces.I2">
+            <zmi:tab label="Update" action="update_magic" />
+            <zmi:tab label="Organize" action="organize_magic" />
+          </zmi:tabs>
+
+        </zopeConfigure>        
+        """))
+
+        getService(None,"Adapters").provideAdapter(
+            I1, ITraverser, FakeTraverser)
+        
+        self.assertEqual(list(ZMIViews.getViews(O2())),
+                         [
+                          ('Update', 'update_magic'),
+                          ('Organize', 'organize_magic'),
+                          ('Edit', 'edit'),
+                          ('History', 'history')
+                          ]
+                         )
+
+
+    def testZMITabDirectiveWithFilters(self):
+        
+        xmlconfig( StringIO("""
+        <zopeConfigure
+        xmlns='http://namespaces.zope.org/zope'
+        xmlns:zmi='http://namespaces.zope.org/zmi'>
+          <directive name="tabs" attributes="for" 
+            namespace="http://namespaces.zope.org/zmi"
+            handler="Zope.App.ZMI.TabsDirective.">
+            <subdirective name="tab" attributes="label action filter" />
+          </directive>
+          <zmi:tabs for="Zope.App.ZMI.tests.sampleInterfaces.I1">
+            <zmi:tab label="Edit" action="edit" />
+            <zmi:tab label="History" action="history" filter="python: 1==2" />
+          </zmi:tabs>
+          <zmi:tabs for="Zope.App.ZMI.tests.sampleInterfaces.I2">
+            <zmi:tab label="Update" action="update_magic" />
+            <zmi:tab label="Organize" action="organize_magic" />
+          </zmi:tabs>
+        </zopeConfigure>        
+        """))
+
+        getService(None,"Adapters").provideAdapter(
+            I1, ITraverser, FakeTraverser)
+
+        self.assertEqual(list(ZMIViews.getViews(O2())),
+                         [
+                          ('Update', 'update_magic'),
+                          ('Organize', 'organize_magic'),
+                          ('Edit', 'edit'),
+                          ]
+                         )
+        
+def test_suite():
+    loader=unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())
+


=== Zope3/lib/python/Zope/App/ZMI/tests/testZMIViewService.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+import unittest, sys
+from Interface import Interface
+
+from Zope.ComponentArchitecture import getService
+from Zope.App.ZMI.ZMIViewService import ZMIViewService
+from Zope.App.ZMI.tests.sampleInterfaces import *
+from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup\
+           import PlacefulSetup
+
+
+
+class Test(PlacefulSetup, unittest.TestCase):
+    #XXX we should have a test for multiple inheritance interface
+    # hierarchies.
+
+    def testAddView(self):
+
+        getService(None,"Adapters").provideAdapter(
+            I1, ITraverser, FakeTraverser)
+        getService(None,"Adapters").provideAdapter(
+            I2, ITraverser, FakeTraverser)
+
+        service = ZMIViewService()
+        service.registerView(I1, 'Edit', 'edit')
+        service.registerView(I1, 'History', 'history')
+        service.registerView(I2, 'Update', 'update_magic')
+        service.registerView(I2, 'Organize', 'organize_magic')
+
+        self.assertEqual(list(service.getViews(O1())),
+                         [('Edit', 'edit'), ('History', 'history')])
+
+        self.assertEqual(list(service.getViews(O2())),
+                         [
+                          ('Update', 'update_magic'),
+                          ('Organize', 'organize_magic'),
+                          ('Edit', 'edit'),
+                          ('History', 'history')
+                          ]
+                         )
+
+    def testZMIFilter(self):
+
+        getService(None,"Adapters").provideAdapter(
+            I1, ITraverser, FakeTraverser)
+        getService(None,"Adapters").provideAdapter(
+            I2, ITraverser, FakeTraverser)
+
+        service = ZMIViewService()
+        service.registerView(I1, 'Edit', 'edit', 'python: 2==2')
+        service.registerView(I1, 'History', 'history', 'python: 1==2')
+        service.registerView(I2, 'Update', 'update_magic', 'python: 2==2')
+        service.registerView(I2, 'Organize', 'organize_magic', 'python: 1==2')
+
+        self.assertEqual(list(service.getViews(O1())),
+                         [('Edit', 'edit'),])
+
+        self.assertEqual(list(service.getViews(O2())),
+                         [('Update', 'update_magic'), ('Edit', 'edit')]
+                         )
+
+
+def test_suite():
+    loader=unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())
+


=== Zope3/lib/python/Zope/App/ZMI/tests/testZMIViewUtility.py 1.1 => 1.2 ===
+#
+# 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.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest, sys
+from Interface import Interface
+
+from Zope.App.ZMI.IZMIViewService import IZMIViewService
+from Zope.ComponentArchitecture import getService, getServiceManager
+from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup\
+           import PlacefulSetup
+from Zope.App.ZMI.ZMIViewUtility import ZMIViewUtility
+from Zope.Publisher.Browser.IBrowserView import IBrowserView
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+from Zope.App.ZopePublication.Traversers import TestTraverser
+from Zope.Security.SecurityManagement import setSecurityPolicy
+from Zope.Security.SecurityManagement import newSecurityManager
+from Zope.Exceptions import Unauthorized
+from Zope.Security.Checker import defineChecker, NamesChecker, CheckerPublic
+from Zope.Security.Proxy import ProxyFactory
+
+class Service:
+    __implements__ = IZMIViewService
+
+    def getViews(self, ob):
+        return [('l1', 'a1'),
+                ('l2', 'a2/a3'),
+                ('lbad', 'abad'),
+                ('l3', '@@a3'),]
+
+class I(Interface): pass
+class C:
+    __implements__ = I
+
+    def __call__(self):
+        pass
+
+ob = C()
+ob.a1 = C()
+ob.a2 = C()
+ob.a2.a3 = C()
+ob.abad = C()
+ob.abad.bad=1
+
+class V:
+    __implements__ = IBrowserView
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+        
+    def __call__(self):
+        pass
+
+
+class Test(PlacefulSetup, unittest.TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        defineService=getServiceManager(None).defineService
+        provideService=getServiceManager(None).provideService
+        defineService('ZMIViewService', IZMIViewService)
+        provideService('ZMIViewService', Service())
+        getService(None,"Views").provideView(
+            I, 'a3', IBrowserPresentation, [V])
+        getService(None, "Views").provideView(None, '_traverse',
+                            IBrowserPresentation, [TestTraverser])
+        defineChecker(C, NamesChecker(['a1', 'a2', 'a3', '__call__'],
+                                      CheckerPublic,
+                                      abad='waaa'))
+
+    def test(self):
+        newSecurityManager('who')
+        v = ZMIViewUtility(ProxyFactory(ob), Request())
+        self.assertEqual(v.getZMIViews(),
+                         [{'label':'l1', 'action':'a1'},
+                          {'label':'l2', 'action':'a2/a3'},
+                          {'label':'l3', 'action':'@@a3'}
+                          ])
+
+
+class Request:
+    def getPresentationType(self):
+        return IBrowserPresentation
+    def getPresentationSkin(self):
+        return ''
+        
+def test_suite():
+    loader=unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())
+