[Zope3-checkins] CVS: Zope3/lib/python/Zope/Configuration/tests - Directives.py:1.4 testDirectivesXML.py:1.3

R. David Murray bitz@bitdance.com
Sun, 22 Sep 2002 12:05:19 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Configuration/tests
In directory cvs.zope.org:/tmp/cvs-serv1839/tests

Modified Files:
	Directives.py testDirectivesXML.py 
Log Message:
Renable some disabled tests in testDirectivesXML of Zope/Configuration
(they pass, so I'm not sure why they were disabled).  Enhance one
of them (SimpleComplexDirective) to actually test the calling of
the subdirective rather than just the defining of it.  Add a test
of the directive directve.

Add a test of a subdirective having subdirectives.  This test
exercises a bug:  the Subdirective returned by the subdirective
method on Subdirective didn't get passed a namespace, leading to
an InvalidDirectiveDefinition error when you tried to define the
sub-subdirective.

Fixed the bug.


=== Zope3/lib/python/Zope/Configuration/tests/Directives.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/Configuration/tests/Directives.py:1.3	Sun Sep  1 14:29:58 2002
+++ Zope3/lib/python/Zope/Configuration/tests/Directives.py	Sun Sep 22 12:05:18 2002
@@ -48,6 +48,14 @@
         self._children.append(p)
         return [(d, protections.append, (p,))]
 
+    def subsub(self, _context):
+        #Dummy subdirective-with-subdirectives.  Define this and you
+        #can define 'protect' subdirectives within it.  This lets
+        #us excercise the subdirectives-of-subdirectives code.
+        #If you put a protect inside a subsub, that'll set children,
+        #so when the parser calls us, __call__ will return ().
+        return self
+
 done = []
 
 def doit(_context, name):


=== Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py:1.2	Mon Jun 10 19:29:24 2002
+++ Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py	Sun Sep 22 12:05:18 2002
@@ -31,7 +31,7 @@
 
 class Test(CleanUp, unittest.TestCase):
         
-    def xtestDirective(self):
+    def testDirective(self):
         xmlconfig(StringIO(
             template % (
             '''<directives  namespace="%s">
@@ -43,7 +43,7 @@
 
         self.assertEqual(done, ['splat'])
         
-    def xtestSimpleComplexDirective(self):
+    def testSimpleComplexDirective(self):
         xmlconfig(StringIO(
             template % (
             '''<directives  namespace="%s">
@@ -54,11 +54,30 @@
                </directives>
                           ''' % ns,
             '''<test:protectClass
-              name=".Contact" permission="splat" names="update"
-              />'''
+                   name=".Contact" permission="splat" names="update"
+               >
+                 <test:protect permission="beep" names="update" />
+               </test:protectClass>'''
             )))
+        
+        self.assertEquals(protections, [(".Contact", "beep", 'update')])
 
-        self.assertEquals(protections, [(".Contact", "splat", 'update')])
+    def testDirectiveDirective(self):
+        xmlconfig(StringIO(
+            template % (
+            '''<directive name="protectClass" namespace="%s"
+                    handler="Zope.Configuration.tests.Directives.protectClass">
+                       <subdirective name="protect"/>
+               </directive>
+                          ''' % ns,
+            '''<test:protectClass
+                   name=".Contact" permission="splat" names="update"
+               >
+                 <test:protect permission="beep" names="update" />
+               </test:protectClass>'''
+            )))
+
+        self.assertEquals(protections, [(".Contact", "beep", 'update')])
         
     def testComplexDirective(self):
         xmlconfig(StringIO(
@@ -79,7 +98,30 @@
             (".Contact", "edit", 'update'),
             (".Contact", "view", 'name email'),
             ])
-      
+        
+    def testSubSubdirective(self):
+        xmlconfig(StringIO(
+            template % (
+            '''<directives  namespace="%s">
+                 <directive name="protectClass"
+                    handler="Zope.Configuration.tests.Directives.protectClass">
+                       <subdirective name="subsub">
+                           <subdirective name="protect"/>
+                       </subdirective>
+                 </directive>
+               </directives>
+                          ''' % ns,
+            '''<test:protectClass
+                   name=".Contact" permission="splat" names="update"
+               >
+                 <test:subsub>
+                   <test:protect permission="beep" names="update" />
+                 </test:subsub>
+               </test:protectClass>'''
+            )))
+        
+        self.assertEquals(protections, [(".Contact", "beep", 'update')])
+
     def testHandlerMethod(self):
         xmlconfig(StringIO(
             template % (