[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testProtectClass.py:1.1.2.2

Ken Manheimer klm@zope.com
Fri, 30 Nov 2001 17:09:03 -0500


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

Modified Files:
      Tag: Zope-3x-branch
	testProtectClass.py 
Log Message:
- Added previously overllooked test for simple name/permission class
  protection. 

- Refactored to put testing stuff we're going to share with
  testPublicClass in a sharable place (testmodulehookup).


=== Zope3/lib/python/Zope/App/Security/tests/testProtectClass.py 1.1.2.1 => 1.1.2.2 ===
 # FOR A PARTICULAR PURPOSE.
 
-""" Test handler for 'definePermission' directive """
-
-# TODO:
-# - Test variants on composite cases - with permission explicit in elements,
-#   and overriding in elements, etc.
+""" Test handler for 'protectClass' directive """
 
 import unittest, sys
-from Interface import Interface
 
 from Zope.App.Security import protectClass
 from Zope.App.Security.metaConfigure import metaConfigure
@@ -21,30 +16,13 @@
 # So we can use config parser to exercise protectClass stuff.
 from cStringIO import StringIO
 from Zope.Configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
-NOTSET = []
+from testmodulehookup import *
 
-PREFIX = "Zope.App.Security.tests.testmodule."
-import Zope.App.Security.tests.testmodule as testmodule
-testmodule.test_class = None
-class I(Interface):
-    def m1():
-        pass
-    def m2():
-        pass
-testmodule.I = I
+NOTSET = []
 
 P1 = "extravagant"
 P2 = "paltry"
 
-testmodule.P1 = P1
-testmodule.P2 = P2
-
-template_bracket = """<zopeConfigure
-   xmlns="http://namespaces.zope.org/zope"
-   xmlns:security='http://namespaces.zope.org/security'>
-   %s
-</zopeConfigure>"""
-
 class Test(unittest.TestCase):
 
     def setUp(self):
@@ -80,6 +58,16 @@
         apply_declaration(template_bracket % declaration)
         self.assertState(**state)
 
+    def testClass(self):
+        declaration = ("""<security:protectClass 
+                              name="%s" permission="%s" />"""
+                       % (PREFIX+"test_class", P1))
+        self.assertDeclaration(declaration,
+                               instP=P1)
+
+    # "testSimple*" exercises tags that do NOT have children.  This mode
+    # inherently sets the instances as well as the class attributes.
+
     def testSimpleNoPerm(self):
         """Establish rejection of declarations lacking a permission spec."""
         declaration = (template_bracket
@@ -87,9 +75,6 @@
         self.assertRaises(ZopeXMLConfigurationError,
                           self.assertDeclaration,
                           declaration)
-
-    # "testSimple*" exercises tags that do NOT have children.  This mode
-    # inherently sets the instances as well as the class attributes.
 
     def testSimpleMethod(self):
         declaration = ("""<security:protectClass