[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser/tests - test_directives.py:1.4 test_fileresource.py:1.3

Jim Fulton jim@zope.com
Sat, 28 Dec 2002 11:14:02 -0500


Update of /cvs-repository/Zope3/src/zope/app/publisher/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv21770/browser/tests

Modified Files:
	test_directives.py test_fileresource.py 
Log Message:

Vastly simplified resource configuration be removing a bunch of unused 
features.  Also always put security proxies around resources, with 
default access of always public for needed methods or attributes.

Moved the missplaced icon configuration here.



=== Zope3/src/zope/app/publisher/browser/tests/test_directives.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_directives.py:1.3	Sat Dec 28 09:13:27 2002
+++ Zope3/src/zope/app/publisher/browser/tests/test_directives.py	Sat Dec 28 11:14:01 2002
@@ -132,22 +132,6 @@
                       Request(IBrowserPresentation, 'zmi')).__class__,
             VZMI)
 
-    def testResource(self):
-        self.assertEqual(queryResource(ob, 'test', request,
-                                       None),
-                         None)
-
-        xmlconfig(StringIO(template % (
-            """
-            <browser:resource name="test"
-                  factory="zope.component.tests.views.R1" />
-            """
-            )))
-
-        self.assertEqual(
-            queryResource(ob, 'test', request).__class__,
-            R1)
-
     def testI18nResource(self):
         self.assertEqual(queryResource(ob, 'test', request,
                                        None),
@@ -194,32 +178,6 @@
             ))
         self.assertRaises(ConfigurationError, xmlconfig, config)
 
-
-    def testSkinResource(self):
-        self.assertEqual(
-            queryResource(ob, 'test', request, None),
-            None)
-
-        xmlconfig(StringIO(template % (
-            """
-            <browser:skin name="zmi" layers="zmi default" />
-            <browser:resource name="test"
-                  factory="zope.component.tests.views.RZMI"
-                  layer="zmi" />
-            <browser:resource name="test"
-                  factory="zope.component.tests.views.R1" />
-            """
-            )))
-
-        self.assertEqual(
-            queryResource(ob, 'test', request).__class__,
-            R1)
-        self.assertEqual(
-            queryResource(ob, 'test',
-                          Request(IBrowserPresentation, 'zmi')).__class__,
-            RZMI)
-
-
     def testInterfaceProtectedView(self):
         xmlconfig(StringIO(template %
             """
@@ -525,26 +483,6 @@
                     Request(IBrowserPresentation, "skinny"))
         self.assertEqual(v(), 'done')
 
-    def testPageResource(self):
-        self.assertEqual(queryResource(ob, 'test', request), None)
-
-        xmlconfig(StringIO(template %
-            """
-            <browser:resource
-                  factory="zope.component.tests.views.R1">
-
-                <browser:page name="index.html" attribute="index" />
-                <browser:page name="action.html" attribute="action" />
-            </browser:resource>
-            """
-            ))
-
-        v = getResource(ob, 'index.html', request)
-        self.assertEqual(v(), 'R1 here')
-        v = getResource(ob, 'action.html', request)
-        self.assertEqual(v(), 'R done')
-
-
     def testFile(self):
         path = os.path.join(tests_path, 'test.pt')
 
@@ -560,10 +498,38 @@
             """ % path
             ))
 
-        v = getResource(ob, 'index.html', request)
-        v = removeAllProxies(v)
-        self.assertEqual(v._testData(), open(path, 'rb').read())
+        r = getResource(ob, 'index.html', request)
+
+        # Make sure we can access available attrs and not others
+        for n in ('GET', 'HEAD', 'publishTraverse', 'request', '__call__'):
+            getattr(r, n)
+
+        self.assertRaises(Exception, getattr, r, '_testData')
+
+        r = removeAllProxies(r)
+        self.assertEqual(r._testData(), open(path, 'rb').read())
+
+
+    def testSkinResource(self):
+        self.assertEqual(
+            queryResource(ob, 'test', request, None),
+            None)
+
+        path = os.path.join(tests_path, 'test.pt')
+
+        xmlconfig(StringIO(template % (
+            """
+            <browser:skin name="zmi" layers="zmi default" />
+            <browser:resource name="test" file="%s" 
+                  layer="zmi" />
+            """ % path
+            )))
+
+        self.assertEqual(queryResource(ob, 'test', request), None)
 
+        r = getResource(ob, 'test', Request(IBrowserPresentation, 'zmi'))
+        r = removeAllProxies(r)
+        self.assertEqual(r._testData(), open(path, 'rb').read())
 
     def testtemplate(self):
         path = os.path.join(tests_path, 'test.pt')


=== Zope3/src/zope/app/publisher/browser/tests/test_fileresource.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_fileresource.py:1.2	Wed Dec 25 09:13:10 2002
+++ Zope3/src/zope/app/publisher/browser/tests/test_fileresource.py	Sat Dec 28 11:14:01 2002
@@ -17,9 +17,11 @@
 $Id$
 """
 
+import os
+
 from unittest import TestCase, TestSuite, main, makeSuite
 
-import os
+from zope.security.checker import CheckerPublic, NamesChecker
 
 from zope.exceptions import NotFoundError
 
@@ -38,6 +40,10 @@
 from zope.app.publisher.browser.fileresource import ImageResourceFactory
 import zope.app.publisher.browser.tests as p
 
+checker = NamesChecker(
+    ('__call__', 'HEAD', 'request', 'publishTraverse', 'GET')
+    )
+
 test_directory = os.path.split(p.__file__)[0]
 
 class Test(PlacelessSetup, TestCase):
@@ -49,8 +55,7 @@
     def testNoTraversal(self):
 
         path = os.path.join(test_directory, 'test.txt')
-        resource = FileResourceFactory(path)(TestRequest())
-        resource = removeAllProxies(resource)
+        resource = FileResourceFactory(path, checker)(TestRequest())
         self.assertRaises(NotFoundError,
                           resource.publishTraverse,
                           resource.request,
@@ -60,45 +65,41 @@
 
         path = os.path.join(test_directory, 'test.txt')
 
-        resource = FileResourceFactory(path)(TestRequest())
-        resource = removeAllProxies(resource)
+        resource = FileResourceFactory(path, checker)(TestRequest())
         self.assertEqual(resource.GET(), open(path, 'rb').read())
 
-        response = resource.request.response
+        response = removeAllProxies(resource.request).response
         self.assertEqual(response.getHeader('Content-Type'), 'text/plain')
 
     def testFileHEAD(self):
 
         path = os.path.join(test_directory, 'test.txt')
-        resource = FileResourceFactory(path)(TestRequest())
-        resource = removeAllProxies(resource)
+        resource = FileResourceFactory(path, checker)(TestRequest())
 
         self.assertEqual(resource.HEAD(), '')
 
-        response = resource.request.response
+        response = removeAllProxies(resource.request).response
         self.assertEqual(response.getHeader('Content-Type'), 'text/plain')
 
     def testImageGET(self):
 
         path = os.path.join(test_directory, 'test.gif')
 
-        resource = ImageResourceFactory(path)(TestRequest())
-        resource = removeAllProxies(resource)
+        resource = ImageResourceFactory(path, checker)(TestRequest())
 
         self.assertEqual(resource.GET(), open(path, 'rb').read())
 
-        response = resource.request.response
+        response = removeAllProxies(resource.request).response
         self.assertEqual(response.getHeader('Content-Type'), 'image/gif')
 
     def testImageHEAD(self):
 
         path = os.path.join(test_directory, 'test.gif')
-        resource = ImageResourceFactory(path)(TestRequest())
-        resource = removeAllProxies(resource)
+        resource = ImageResourceFactory(path, checker)(TestRequest())
 
         self.assertEqual(resource.HEAD(), '')
 
-        response = resource.request.response
+        response = removeAllProxies(resource.request).response
         self.assertEqual(response.getHeader('Content-Type'), 'image/gif')