[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Publisher/Browser/tests - testDirectives.py:1.13 testFileResource.py:1.6 testIconDirective.py:1.6

Steve Alexander steve@cat-box.net
Mon, 28 Oct 2002 13:41:19 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv10546/python/Zope/App/Publisher/Browser/tests

Modified Files:
	testDirectives.py testFileResource.py testIconDirective.py 
Log Message:
Fixed collector issue http://collector.zope.org/Zope3-dev/78

Resources and pages of named views are now wrapped with security
proxies at the factory.

Updated tests to remove proxies from views etc. when the test is not
concerned with security.


=== Zope3/lib/python/Zope/App/Publisher/Browser/tests/testDirectives.py 1.12 => 1.13 ===
--- Zope3/lib/python/Zope/App/Publisher/Browser/tests/testDirectives.py:1.12	Fri Oct  4 14:37:23 2002
+++ Zope3/lib/python/Zope/App/Publisher/Browser/tests/testDirectives.py	Mon Oct 28 13:41:18 2002
@@ -22,6 +22,7 @@
 from Zope.ComponentArchitecture import getDefaultViewName, getResource
 from Zope.App.tests.PlacelessSetup import PlacelessSetup
 from Zope.Security.Proxy import ProxyFactory
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
 from cStringIO import StringIO
 
 from Zope.ComponentArchitecture.tests.Request import Request
@@ -341,12 +342,15 @@
             ))
 
         view = getView(ob, 'test', request)
+        view = removeAllProxies(view)
         self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))
 
 
         v = view.publishTraverse(request, 'index.html')
+        v = removeAllProxies(v)
         self.assertEqual(v(), 'V1 here')
         v = view.publishTraverse(request, 'action.html')
+        v = removeAllProxies(v)
         self.assertEqual(v(), 'done')
 
         v = view.publishTraverse(request, '42')
@@ -371,14 +375,18 @@
             ))
 
         view = getView(ob, 'test', request)
+        view = removeAllProxies(view)
         self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))
 
 
         v = view.publishTraverse(request, 'index.html')
+        v = removeAllProxies(v)
         self.assertEqual(v(), 'V1 here')
         v = view.publishTraverse(request, 'action.html')
+        v = removeAllProxies(v)
         self.assertEqual(v(), 'done')
         v = view.publishTraverse(request, 'test.html')
+        v = removeAllProxies(v)
         self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
 
     def testNamedViewPageViewsWithDefault(self):
@@ -401,14 +409,18 @@
             ))
 
         view = getView(ob, 'test', request)
+        view = removeAllProxies(view)
         self.assertEqual(view.browserDefault(request)[1], (u'test.html', ))
 
 
         v = view.publishTraverse(request, 'index.html')
+        v = removeAllProxies(v)
         self.assertEqual(v(), 'V1 here')
         v = view.publishTraverse(request, 'action.html')
+        v = removeAllProxies(v)
         self.assertEqual(v(), 'done')
         v = view.publishTraverse(request, 'test.html')
+        v = removeAllProxies(v)
         self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
 
     def testProtectedPageViews(self):
@@ -438,15 +450,57 @@
             """
             ))
 
+        # XXX this seems to be no longer needed
         # Need to "log someone in" to turn on checks
-        from Zope.Security.SecurityManagement import newSecurityManager
-        newSecurityManager('someuser')
+        #from Zope.Security.SecurityManagement import newSecurityManager
+        #newSecurityManager('someuser')
 
         v = getView(ob, 'index.html', request)
         self.assertRaises(Exception, v)
         v = getView(ob, 'action.html', request)
         self.assertEqual(v(), 'done')
 
+    def testProtectedNamedViewPageViews(self):
+        self.assertEqual(queryView(ob, 'test', request),
+                         None)
+
+        xmlconfig(StringIO(template %
+            """
+            <directives namespace="http://namespaces.zope.org/zope">
+              <directive name="permission"
+                 attributes="id title description"
+                 handler="
+             Zope.App.Security.Registries.metaConfigure.definePermission" />
+            </directives>
+
+            <permission id="XXX" title="xxx" />
+
+            <browser:view
+                  name="test"
+                  factory="Zope.ComponentArchitecture.tests.TestViews.V1"
+                  for="Zope.ComponentArchitecture.tests.TestViews.IC" 
+                  permission="Zope.Public">
+
+                <browser:page name="index.html" attribute="index" /> 
+                <browser:page name="action.html" attribute="action"
+                              permission="XXX" /> 
+            </browser:view>
+            """
+            ))
+
+        # XXX this seems to be no longer needed
+        # Need to "log someone in" to turn on checks
+        #from Zope.Security.SecurityManagement import newSecurityManager
+        #newSecurityManager('someuser')
+
+        view = getView(ob, 'test', request)
+        self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))
+ 
+        v = view.publishTraverse(request, 'index.html')
+        self.assertEqual(v(), 'V1 here')
+        v = view.publishTraverse(request, 'action.html')
+        self.assertRaises(Exception, v)
+    
     def testSkinnedPageView(self):
         self.assertEqual(queryView(ob, 'test', request), None)
 
@@ -505,6 +559,7 @@
             ))
 
         v = getResource(ob, 'index.html', request)
+        v = removeAllProxies(v)
         self.assertEqual(v._testData(), open(path, 'rb').read())
 
 
@@ -580,9 +635,10 @@
             """ % path
             ))
 
+        # XXX This seems to be no longer needed
         # Need to "log someone in" to turn on checks
-        from Zope.Security.SecurityManagement import newSecurityManager
-        newSecurityManager('someuser')
+        #from Zope.Security.SecurityManagement import newSecurityManager
+        #newSecurityManager('someuser')
         
         v = getView(ob, 'xxx.html', request)
         v = ProxyFactory(v)


=== Zope3/lib/python/Zope/App/Publisher/Browser/tests/testFileResource.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/Publisher/Browser/tests/testFileResource.py:1.5	Fri Oct  4 14:37:23 2002
+++ Zope3/lib/python/Zope/App/Publisher/Browser/tests/testFileResource.py	Mon Oct 28 13:41:18 2002
@@ -26,6 +26,7 @@
 from Zope.App.tests.PlacelessSetup import PlacelessSetup
 from Zope.ComponentArchitecture.GlobalResourceService import provideResource
 from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
 
 from Zope.I18n.IUserPreferredCharsets import IUserPreferredCharsets
 
@@ -39,7 +40,6 @@
 
 test_directory = os.path.split(p.__file__)[0]
 
-
 class Test(PlacelessSetup, TestCase):
 
     def setUp(self):
@@ -50,7 +50,7 @@
 
         path = os.path.join(test_directory, 'test.txt')
         resource = FileResourceFactory(path)(TestRequest())
-
+        resource = removeAllProxies(resource)
         self.assertRaises(NotFoundError,
                           resource.publishTraverse,
                           resource.request,
@@ -61,7 +61,7 @@
         path = os.path.join(test_directory, 'test.txt')
 
         resource = FileResourceFactory(path)(TestRequest())
-
+        resource = removeAllProxies(resource)
         self.assertEqual(resource.GET(), open(path, 'rb').read())
 
         response = resource.request.response
@@ -71,6 +71,7 @@
 
         path = os.path.join(test_directory, 'test.txt')
         resource = FileResourceFactory(path)(TestRequest())
+        resource = removeAllProxies(resource)
 
         self.assertEqual(resource.HEAD(), '')
 
@@ -82,6 +83,7 @@
         path = os.path.join(test_directory, 'test.gif')
 
         resource = ImageResourceFactory(path)(TestRequest())
+        resource = removeAllProxies(resource)
 
         self.assertEqual(resource.GET(), open(path, 'rb').read())
 
@@ -92,6 +94,7 @@
 
         path = os.path.join(test_directory, 'test.gif')
         resource = ImageResourceFactory(path)(TestRequest())
+        resource = removeAllProxies(resource)
 
         self.assertEqual(resource.HEAD(), '')
 


=== Zope3/lib/python/Zope/App/Publisher/Browser/tests/testIconDirective.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/Publisher/Browser/tests/testIconDirective.py:1.5	Fri Oct  4 14:37:23 2002
+++ Zope3/lib/python/Zope/App/Publisher/Browser/tests/testIconDirective.py	Mon Oct 28 13:41:18 2002
@@ -18,7 +18,7 @@
 """
 import os
 from StringIO import StringIO
-from unittest import TestCase, TestSuite, main, makeSuite
+from unittest import TestCase, main, makeSuite
 
 from Zope.Exceptions import Forbidden
 from Zope.Proxy.ProxyIntrospection import removeAllProxies
@@ -48,11 +48,19 @@
 
 ob = Ob()
 
+def defineCheckers():
+    # define the appropriate checker for a FileResource for these tests
+    from Zope.App.Security.protectClass import protectName
+    from Zope.App.Publisher.Browser.FileResource import FileResource
+    protectName(FileResource, '__call__', 'Zope.Public')
+
+
 class Test(PlacelessSetup, TestCase):
 
     def setUp(self):
         PlacelessSetup.setUp(self)
         XMLConfig('meta.zcml', Zope.App.Publisher.Browser)()
+        defineCheckers()
 
     def test(self):
         self.assertEqual(queryView(ob, 'zmi_icon', request), None)
@@ -67,7 +75,7 @@
                       for="Zope.ComponentArchitecture.tests.TestViews.IC"
                       file="%s" /> 
             """ % path
-            ))) 
+            )))
 
         view = getView(ob, 'zmi_icon', request)
         rname = 'Zope-ComponentArchitecture-tests-TestViews-IC-zmi_icon.gif'
@@ -77,7 +85,9 @@
             % rname)
 
         resource = getResource(ob, rname, request)
-        resource = ProxyFactory(resource)
+        
+        # Resources come ready-wrapped from the factory
+        #resource = ProxyFactory(resource)
 
         self.assertRaises(Forbidden, getattr, resource, '_testData')
         resource = removeAllProxies(resource)
@@ -98,8 +108,8 @@
                       for="Zope.ComponentArchitecture.tests.TestViews.IC"
                       resource="zmi_icon_res" /> 
             """ % path
-            ))) 
-
+            )))
+ 
         view = getView(ob, 'zmi_icon', request)
         rname = "zmi_icon_res"
         self.assertEqual(
@@ -108,7 +118,9 @@
             % rname)
 
         resource = getResource(ob, rname, request)
-        resource = ProxyFactory(resource)
+
+        # Resources come ready-wrapped from the factory
+        #resource = ProxyFactory(resource)
 
         self.assertRaises(Forbidden, getattr, resource, '_testData')
         resource = removeAllProxies(resource)