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

R. David Murray bitz@bitdance.com
Wed, 6 Nov 2002 14:23:46 -0500


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

Modified Files:
      Tag: rdmurray-metameta-branch
	testDirectivesXML.py 
Log Message:
Refactor to use BaseTestDirectives.


=== Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py 1.4.4.1 => 1.4.4.2 ===
--- Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py:1.4.4.1	Mon Oct 14 18:38:49 2002
+++ Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py	Wed Nov  6 14:23:46 2002
@@ -12,194 +12,11 @@
 # 
 ##############################################################################
 import sys, unittest
-from cStringIO import StringIO
-from Zope.Configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
-from Zope.Configuration.xmlconfig import testxmlconfig
-from Zope.Configuration.meta import InvalidDirective
-from Zope.Configuration.tests.Directives import protections, done
-from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.Configuration.tests.BaseTestDirectivesXML import directiveTests
+from Zope.Testing.CleanUp import CleanUp
 
-template = """<zopeConfigure
-   xmlns='http://namespaces.zope.org/zope'
-   xmlns:test='http://www.zope.org/NS/Zope3/test'>
-   %s
-   %s
-   </zopeConfigure>"""
-
-
-ns='http://www.zope.org/NS/Zope3/test'
-
-class Test(CleanUp, unittest.TestCase):
-        
-    def testDirective(self):
-        xmlconfig(StringIO(
-            template % (
-            '''<directives  namespace="%s">
-                   <directive name="doit"
-                    handler="Zope.Configuration.tests.Directives.doit" />
-               </directives>''' % ns,
-            '<test:doit name="splat" />'
-            )))
-
-        self.assertEqual(done, ['splat'])
-        
-    def testSimpleComplexDirective(self):
-        xmlconfig(StringIO(
-            template % (
-            '''<directives  namespace="%s">
-                   <directive name="protectClass"
-                    handler="Zope.Configuration.tests.Directives.protectClass">
-                       <subdirective name="protect"/>
-               </directive>
-               </directives>
-                          ''' % ns,
-            '''<test:protectClass
-                   name=".Contact" permission="splat" names="update"
-               >
-                 <test:protect permission="beep" names="update" />
-               </test:protectClass>'''
-            )))
-        
-        self.assertEquals(protections, [(".Contact", "beep", '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(
-            template % (
-            '''<directives  namespace="%s">
-                   <directive name="protectClass"
-                    handler="Zope.Configuration.tests.Directives.protectClass">
-                      <subdirective name="protect" />
-                   </directive>
-               </directives>''' % ns,
-            '''<test:protectClass name=".Contact">
-                <test:protect permission="edit" names='update' />
-                <test:protect permission="view" names='name email' />
-              </test:protectClass>'''
-            )))
-
-        self.assertEquals(protections, [
-            (".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="subsub">
-                           <subdirective name="subsub">
-                             <subdirective name="subsub">
-                               <subdirective name="protect"/>
-                             </subdirective>
-                           </subdirective>
-                         </subdirective>
-                       </subdirective>
-                 </directive>
-               </directives>
-                          ''' % ns,
-            '''<test:protectClass
-                   name=".Contact" permission="splat" names="update"
-               >
-                 <test:subsub>
-                   <test:subsub>
-                     <test:subsub>
-                       <test:subsub>
-                         <test:protect permission="beep" names="update" />
-                       </test:subsub>
-                     </test:subsub>
-                   </test:subsub>
-                 </test:subsub>
-               </test:protectClass>'''
-            )))
+class Test(CleanUp, unittest.TestCase, directiveTests): pass
         
-        self.assertEquals(protections, [(".Contact", "beep", 'update')])
-
-    def testHandlerMethod(self):
-        xmlconfig(StringIO(
-            template % (
-            '''<directives  namespace="%s">
-                   <directive name="protectClass"
-                    handler="Zope.Configuration.tests.Directives.protectClass">
-                      <subdirective name="fish"
-                                    handler_method="protect" />
-                   </directive>
-               </directives>''' % ns,
-            '''<test:protectClass name=".Contact">
-                <test:fish permission="edit" names='update' />
-                <test:fish permission="view" names='name email' />
-              </test:protectClass>'''
-            )))
-
-        self.assertEquals(protections, [
-            (".Contact", "edit", 'update'),
-            (".Contact", "view", 'name email'),
-            ])
-        
-        
-    def testBadNoPrefixComplexDirective(self):
-
-        self.assertRaises(
-            InvalidDirective,
-            xmlconfig,
-            StringIO(
-            template % (
-            '''<directives  namespace="%s">
-                   <directive name="protectClass"
-                    handler="Zope.Configuration.tests.Directives.protectClass">
-                  <subdirective name="protect" />
-               </directive>
-               </directives>''' % ns,
-
-            '''<test:protectClass name=".Contact">
-              <test:protect permission="edit" names='update' />
-              <protect permission="view" names='name email' />
-              </test:protectClass>'''
-            )),
-            testing=1)
-        
-    def testBadPrefixComplexDirective(self):
-
-        try:
-            testxmlconfig(
-                StringIO(
-                template % (
-            '''<directives  namespace="%s">
-                   <directive name="protectClass"
-                    handler="Zope.Configuration.tests.Directives.protectClass">
-                  <subdirective name="protect" />
-               </directive>
-               </directives>''' % ns,
-
-                '''<test:protectClass name=".Contact">
-                <test2:protect permission="edit" names='update' />
-                </test:protectClass>'''
-                )))
-        except InvalidDirective, v:
-            self.assertEqual(str(v), "(None, u'test2:protect')")
-        else:
-            self.fail('Should have raised ZopeXMLConfigurationError')
-        
-
 def test_suite():
     loader=unittest.TestLoader()
     return loader.loadTestsFromTestCase(Test)