[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ContentDirective/tests - TestModuleHookup.py:1.4 testRequirePermissions.py:1.7

Jim Fulton jim@zope.com
Mon, 11 Nov 2002 15:13:50 -0500


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

Modified Files:
	TestModuleHookup.py testRequirePermissions.py 
Log Message:
Added a schema_set attribute for the content require directive to
allow a permission for setting attributes defined by a schema to be
set. Any interface can be provided. Only fields in the interface are
used. Methods and other attributes are ignored.


=== Zope3/lib/python/Zope/App/ContentDirective/tests/TestModuleHookup.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/ContentDirective/tests/TestModuleHookup.py:1.3	Thu Jun 20 11:54:46 2002
+++ Zope3/lib/python/Zope/App/ContentDirective/tests/TestModuleHookup.py	Mon Nov 11 15:13:49 2002
@@ -19,6 +19,7 @@
 modules, themselves."""
 
 from Interface import Interface
+from Zope.Schema import Text
 
 PREFIX = "Zope.App.Security.tests.TestModule."
 import Zope.App.Security.tests.TestModule as TestModule
@@ -34,8 +35,14 @@
         pass
     
 
+class S(Interface):
+    foo = Text()
+    bar = Text()
+    
+
 TestModule.I = I
 TestModule.I2 = I2
+TestModule.S = S
 
 template_bracket = """<zopeConfigure
    xmlns="http://namespaces.zope.org/zope">


=== Zope3/lib/python/Zope/App/ContentDirective/tests/testRequirePermissions.py 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/App/ContentDirective/tests/testRequirePermissions.py:1.6	Wed Nov  6 17:30:21 2002
+++ Zope3/lib/python/Zope/App/ContentDirective/tests/testRequirePermissions.py	Mon Nov 11 15:13:49 2002
@@ -20,6 +20,9 @@
 import Zope.App.Security
 from Zope.App.Security import protectClass
 from Zope.App.Security.Exceptions import UndefinedPermissionError
+from Zope.Security.Checker import selectChecker
+from Zope.Exceptions import Forbidden
+
 
 # So we can use config parser to exercise protectClass stuff.
 from Zope.Configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
@@ -81,6 +84,22 @@
         self.assertEqual(checker.permission_id('m2'), (m2P or None))
         self.assertEqual(checker.permission_id('m3'), (m3P or None))
 
+    def assertDeclaration(self, declaration, **state):
+        apply_declaration(template_bracket % declaration)
+        self.assertState(**state)
+
+    # "testSimple*" exercises tags that do NOT have children.  This mode
+    # inherently sets the instances as well as the class attributes.
+
+    def testSimpleMethodsPlural(self):
+        declaration = ("""<content class="%s">
+                            <require
+                                permission="%s" 
+                                attributes="m1 m3"/>
+                          </content>"""
+                       % (PREFIX+"test_class", P1))
+        self.assertDeclaration(declaration, m1P=P1, m3P=P1)
+
     def assertSetattrState(self, m1P=NOTSET, m2P=NOTSET, m3P=NOTSET):
         "Verify that class, instance, and methods have expected permissions."
 
@@ -92,34 +111,36 @@
         self.assertEqual(checker.setattr_permission_id('m2'), (m2P or None))
         self.assertEqual(checker.setattr_permission_id('m3'), (m3P or None))
 
-    def assertDeclaration(self, declaration, **state):
-        apply_declaration(template_bracket % declaration)
-        self.assertState(**state)
-
     def assertSetattrDeclaration(self, declaration, **state):
-        apply_declaration(template_bracket % declaration)
         self.assertSetattrState(**state)
 
-    # "testSimple*" exercises tags that do NOT have children.  This mode
-    # inherently sets the instances as well as the class attributes.
-
-    def testSimpleMethodsPlural(self):
+    def test_set_attributes(self):
         declaration = ("""<content class="%s">
                             <require
                                 permission="%s" 
-                                attributes="m1 m3"/>
+                                set_attributes="m1 m3"/>
                           </content>"""
                        % (PREFIX+"test_class", P1))
-        self.assertDeclaration(declaration, m1P=P1, m3P=P1)
+        apply_declaration(template_bracket % declaration)
+        checker = selectChecker(TestModule.test_instance)
+        self.assertEqual(checker.setattr_permission_id('m1'), P1)
+        self.assertEqual(checker.setattr_permission_id('m2'), None)
+        self.assertEqual(checker.setattr_permission_id('m3'), P1)
 
-    def test_set_attributes(self):
+    def test_set_schema(self):
         declaration = ("""<content class="%s">
                             <require
                                 permission="%s" 
-                                set_attributes="m1 m3"/>
+                                set_schema="%s"/>
                           </content>"""
-                       % (PREFIX+"test_class", P1))
-        self.assertSetattrDeclaration(declaration, m1P=P1, m3P=P1)
+                       % (PREFIX+"test_class", P1, PREFIX+"S"))
+        apply_declaration(template_bracket % declaration)
+        checker = selectChecker(TestModule.test_instance)
+        self.assertEqual(checker.setattr_permission_id('m1'), None)
+        self.assertEqual(checker.setattr_permission_id('m2'), None)
+        self.assertEqual(checker.setattr_permission_id('m3'), None)
+        self.assertEqual(checker.setattr_permission_id('foo'), P1)
+        self.assertEqual(checker.setattr_permission_id('bar'), P1)
 
     def testSimpleInterface(self):
         declaration = ("""<content class="%s">