[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ContentDirective/tests - TestModuleHookup.py:1.3 testDirectives.py:1.4 testFactory.py:1.4 testRequirePermissions.py:1.4

Jim Fulton jim@zope.com
Thu, 20 Jun 2002 11:55:17 -0400


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

Modified Files:
	TestModuleHookup.py testDirectives.py testFactory.py 
	testRequirePermissions.py 
Log Message:
implemented:

http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/MergeSecurityIntoZopeNamespace

While I was at it, I couldn't resist implementing a variation of:

http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/SecurityPackageReorg

which was a lot more work. 



=== Zope3/lib/python/Zope/App/ContentDirective/tests/TestModuleHookup.py 1.2 => 1.3 ===
 
 template_bracket = """<zopeConfigure
-   xmlns="http://namespaces.zope.org/zope"
-   xmlns:security='http://namespaces.zope.org/security'>
+   xmlns="http://namespaces.zope.org/zope">
    %s
 </zopeConfigure>"""


=== Zope3/lib/python/Zope/App/ContentDirective/tests/testDirectives.py 1.3 => 1.4 ===
 """
 
-import unittest, sys, os
-
-from Zope.Configuration.xmlconfig import xmlconfig
+import unittest
+import sys
+import os
 from StringIO import StringIO
+
 from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.Configuration.xmlconfig import xmlconfig, XMLConfig
 from Zope.Configuration.xmlconfig import ZopeXMLConfigurationError
 
-# explicitly import ExampleClass and IExample using full paths
-# so that they are the same objects as resolve will get.
-from Zope.App.ContentDirective.tests.ExampleClass import ExampleClass, IExample
+import Zope.App.Security
 
 import Zope.App.ContentDirective
-defs_path = os.path.join(
-    os.path.split(Zope.App.ContentDirective.__file__)[0],
-    'meta.zcml')
 
-import Zope.App.Security
-security_defs_path = os.path.join(
-    os.path.split(Zope.App.Security.__file__)[0],
-    'meta.zcml')
+# explicitly import ExampleClass and IExample using full paths
+# so that they are the same objects as resolve will get.
+from Zope.App.ContentDirective.tests.ExampleClass import ExampleClass, IExample
 
 
 def configfile(s):
     return StringIO("""<zopeConfigure
       xmlns='http://namespaces.zope.org/zope'
-      xmlns:security='http://namespaces.zope.org/security'
       xmlns:zmi='http://namespaces.zope.org/zmi'>
       %s
       </zopeConfigure>
@@ -49,8 +44,8 @@
 
 class TestContentDirective(CleanUp, unittest.TestCase):
     def setUp(self):
-        xmlconfig(open(defs_path))
-        xmlconfig(open(security_defs_path))
+        XMLConfig('meta.zcml', Zope.App.ContentDirective)()
+        XMLConfig('meta.zcml', Zope.App.Security)()
         
         try:
             del ExampleClass.__implements__
@@ -77,9 +72,9 @@
         
     def testRequire(self):
         f = configfile("""
-<security:permission id="Zope.View" title="Zope view permission" />
+<permission id="Zope.View" title="Zope view permission" />
 <content class="Zope.App.ContentDirective.tests.ExampleClass.">
-    <security:require permission="Zope.View"
+    <require permission="Zope.View"
                       attributes="anAttribute anotherAttribute" />
 </content>
                        """)
@@ -88,7 +83,7 @@
     def testAllow(self):
         f = configfile("""
 <content class="Zope.App.ContentDirective.tests.ExampleClass.">
-    <security:allow attributes="anAttribute anotherAttribute" />
+    <allow attributes="anAttribute anotherAttribute" />
 </content>
                        """)
         xmlconfig(f)
@@ -96,7 +91,7 @@
     def testMimic(self):
         f = configfile("""
 <content class="Zope.App.ContentDirective.tests.ExampleClass.">
-    <security:mimic class="Zope.App.ContentDirective.tests.ExampleClass." />
+    <require like_class="Zope.App.ContentDirective.tests.ExampleClass." />
 </content>
                        """)
         xmlconfig(f)
@@ -108,12 +103,12 @@
 class TestFactorySubdirective(AddableSetup, CleanUp, unittest.TestCase):
     def setUp(self):
         AddableSetup.setUp(self)
-        xmlconfig(open(defs_path))
-        xmlconfig(open(security_defs_path))
+        XMLConfig('meta.zcml', Zope.App.ContentDirective)()
+        XMLConfig('meta.zcml', Zope.App.Security)()
 
     def testFactory(self):
         f = configfile("""
-<security:permission id="Zope.Foo" title="Zope Foo Permission" />
+<permission id="Zope.Foo" title="Zope Foo Permission" />
 
 <content class="Zope.App.ContentDirective.tests.ExampleClass.">
     <zmi:factory 


=== Zope3/lib/python/Zope/App/ContentDirective/tests/testFactory.py 1.3 => 1.4 ===
 """ Test handler for 'factory' subdirective of 'content' directive """
 
-import unittest, sys, os
-
+import unittest
+import sys
+import os
 from cStringIO import StringIO
+
 from Zope.Configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
+from Zope.Configuration.xmlconfig import XMLConfig
+
 from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+
+import Zope.App.Security
 from Zope.App.Security.Exceptions import UndefinedPermissionError
+
 from Zope.App.OFS.Services.AddableService.tests.AddableSetup \
     import AddableSetup
 
+import Zope.App.ContentDirective
 from Zope.App.ContentDirective.tests.ExampleClass \
     import ExampleClass, IExample, IExampleContainer
 
-import Zope.App.ContentDirective
-defs_path = os.path.join(
-    os.path.split(Zope.App.ContentDirective.__file__)[0],
-    'meta.zcml')
-
-import Zope.App.Security
-security_defs_path = os.path.join(
-    os.path.split(Zope.App.Security.__file__)[0],
-    'meta.zcml')
-
-
 def configfile(s):
     return StringIO("""<zopeConfigure
       xmlns='http://namespaces.zope.org/zope'
-      xmlns:security='http://namespaces.zope.org/security'
       xmlns:zmi='http://namespaces.zope.org/zmi'>
       %s
       </zopeConfigure>
@@ -48,15 +44,15 @@
 class Test(AddableSetup, CleanUp, unittest.TestCase):
     def setUp(self):
         AddableSetup.setUp(self)
-        xmlconfig(open(defs_path))
-        xmlconfig(open(security_defs_path))
+        XMLConfig('meta.zcml', Zope.App.ContentDirective)()
+        XMLConfig('meta.zcml', Zope.App.Security)()
 
 
     def testFactory(self):
         from Zope.ComponentArchitecture import getService
         from Zope.Proxy.ProxyIntrospection import removeAllProxies
         f = configfile("""
-<security:permission id="Zope.Foo" title="Zope Foo Permission" />
+<permission id="Zope.Foo" title="Zope Foo Permission" />
 <content class="Zope.App.ContentDirective.tests.ExampleClass.">
     <zmi:factory 
       id="Example" 
@@ -77,7 +73,7 @@
         from Zope.ComponentArchitecture import getService
         from Zope.Proxy.ProxyIntrospection import removeAllProxies
         f = configfile("""
-<security:permission id="Zope.Foo" title="Zope Foo Permission" />
+<permission id="Zope.Foo" title="Zope Foo Permission" />
 <content class="Zope.App.ContentDirective.tests.ExampleClass.">
     <zmi:factory 
       permission="Zope.Foo"


=== Zope3/lib/python/Zope/App/ContentDirective/tests/testRequirePermissions.py 1.3 => 1.4 ===
 """ Test handler for 'require' subdirective of 'content' directive """
 
-import unittest, sys, os
+import unittest
+from cStringIO import StringIO
 
+import Zope.App.Security
 from Zope.App.Security import protectClass
+from Zope.App.Security.Exceptions import UndefinedPermissionError
 
 # So we can use config parser to exercise protectClass stuff.
-from cStringIO import StringIO
 from Zope.Configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
-from TestModuleHookup import *
-from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-from Zope.App.Security.Exceptions import UndefinedPermissionError
+from Zope.Configuration.xmlconfig import XMLConfig
 
+from TestModuleHookup import * # XXX I hate this!
 
-import Zope.App.ContentDirective
-defs_path = os.path.join(
-    os.path.split(Zope.App.ContentDirective.__file__)[0],
-    'meta.zcml')
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
 
-import Zope.App.Security
-security_defs_path = os.path.join(
-    os.path.split(Zope.App.Security.__file__)[0],
-    'meta.zcml')
+import Zope.App.ContentDirective
 
 def defineDirectives():
-    xmlconfig(open(defs_path))
-    xmlconfig(open(security_defs_path))
+    XMLConfig('meta.zcml', Zope.App.ContentDirective)()
+    XMLConfig('meta.zcml', Zope.App.Security)()
     xmlconfig(StringIO("""<zopeConfigure
-        xmlns='http://namespaces.zope.org/zope' 
-        xmlns:security='http://namespaces.zope.org/security'>
-       <security:permission id="extravagant" title="extravagant" />
-       <security:permission id="paltry" title="paltry" />
+        xmlns='http://namespaces.zope.org/zope' >
+       <permission id="extravagant" title="extravagant" />
+       <permission id="paltry" title="paltry" />
     </zopeConfigure>"""))
 
 NOTSET = []
@@ -74,8 +68,7 @@
         CleanUp.tearDown(self)
         TestModule.test_class = None
 
-    def assertState(self, instP=NOTSET,
-                    m1P=NOTSET, m2P=NOTSET, m3P=NOTSET):
+    def assertState(self, m1P=NOTSET, m2P=NOTSET, m3P=NOTSET):
         "Verify that class, instance, and methods have expected permissions."
 
         from Zope.Security.Checker import selectChecker
@@ -90,37 +83,27 @@
         apply_declaration(template_bracket % declaration)
         self.assertState(**state)
 
-    def testClass(self):
-        declaration = ("""<content class="%s">
-                            <security:require permission="%s" />
-                          </content>"""
-                       % (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 testSimpleMethodsPlural(self):
         declaration = ("""<content class="%s">
-                            <security:require
+                            <require
                                 permission="%s" 
                                 attributes="m1 m3"/>
                           </content>"""
                        % (PREFIX+"test_class", P1))
-        self.assertDeclaration(declaration,
-                               instP=P1, m1P=P1, m3P=P1)
+        self.assertDeclaration(declaration, m1P=P1, m3P=P1)
 
     def testSimpleInterface(self):
         declaration = ("""<content class="%s">
-                            <security:require
+                            <require
                                 permission="%s" 
                                 interface="%s"/>
                           </content>"""
                        % (PREFIX+"test_class", P1, PREFIX+"I"))
         # m1 and m2 are in the interface, so should be set, and m3 should not:
-        self.assertDeclaration(declaration,
-                               instP=P1, m1P=P1, m2P=P1)
+        self.assertDeclaration(declaration, m1P=P1, m2P=P1)
 
     # "testComposite*" exercises tags that DO have children.
     # "testComposite*TopPerm" exercises tags with permission in containing tag.
@@ -129,7 +112,7 @@
     def testCompositeNoPerm(self):
         # Establish rejection of declarations lacking a permission spec.
         declaration = ("""<content class="%s">
-                            <security:require
+                            <require
                                 attributes="m1"/>
                           </content>"""
                        % (PREFIX+"test_class"))
@@ -141,7 +124,7 @@
 
     def testCompositeMethodsPluralElementPerm(self):
         declaration = ("""<content class="%s">
-                            <security:require
+                            <require
                                 permission="%s"
                                 attributes="m1 m3"/>
                           </content>"""
@@ -151,7 +134,7 @@
 
     def testCompositeInterfaceTopPerm(self):
         declaration = ("""<content class="%s">
-                            <security:require
+                            <require
                                 permission="%s"
                                 interface="%s"/>
                           </content>"""
@@ -162,24 +145,23 @@
 
     def testSubInterfaces(self):
         declaration = ("""<content class="%s">
-                            <security:require
+                            <require
                                 permission="%s"
                                 interface="%s"/>
                           </content>"""
                        % (PREFIX+"test_class", P1, PREFIX+"I2"))
         # m1 and m2 are in the interface, so should be set, and m3 should not:
-        self.assertDeclaration(declaration,
-                               instP=P1, m1P=P1, m2P=P1)
+        self.assertDeclaration(declaration, m1P=P1, m2P=P1)
 
 
     def testMimicOnly(self):
         declaration = ("""<content class="%s">
-                            <security:require
+                            <require
                                 permission="%s"
                                 attributes="m1 m2"/>
                           </content>
                           <content class="%s">
-                            <security:mimic class="%s" />
+                            <require like_class="%s" />
                           </content>
                           """ % (PREFIX+"test_base", P1,
                 PREFIX+"test_class", PREFIX+"test_base"))
@@ -190,13 +172,13 @@
 
     def testMimicAsDefault(self):
         declaration = ("""<content class="%s">
-                            <security:require
+                            <require
                                 permission="%s"
                                 attributes="m1 m2"/>
                           </content>
                           <content class="%s">
-                            <security:mimic class="%s" />
-                            <security:require
+                            <require like_class="%s" />
+                            <require
                                 permission="%s"
                                 attributes="m2 m3"/>
                           </content>