[Zope-Checkins] CVS: Zope3/lib/python/Zope/Configuration/tests - testMeta.py:1.1.2.1
Jim Fulton
jim@zope.com
Fri, 16 Nov 2001 12:33:37 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Configuration/tests
In directory cvs.zope.org:/tmp/cvs-serv24061/Configuration/tests
Added Files:
Tag: Zope-3x-branch
testMeta.py
Log Message:
basic meta-config in place
=== Added File Zope3/lib/python/Zope/Configuration/tests/testMeta.py ===
import unittest
ns='http://www.zope.org/NS/Zope3/test'
class MetaTest(unittest.TestCase):
def testImport(self):
import Zope.Configuration.meta
def tearDown(self):
from Zope.Configuration.meta import _clear
_clear()
global protections
protections=[]
def testDirective(self):
from Zope.Configuration.meta import register, execute, InvalidDirective
x=[]
def d(name, x=x): x.append(name)
self.assertRaises(InvalidDirective, execute, ns, 'doit')
register(ns, 'test', 'doit', d)
self.failUnless(execute(ns, 'doit', name='splat') is None)
self.failUnless(x==['splat'])
def testSimpleComplexDirective(self):
from Zope.Configuration.meta import register, execute, InvalidDirective
register(ns, 'security', 'protectClass', protectClass)
o=execute(ns, 'protectClass',
name=".Contact", permission="splat", method='update')
o()
self.assertEquals(protections, [(".Contact", "splat", 'update', None)])
def testComplexDirective(self):
from Zope.Configuration.meta import register, execute, InvalidDirective
register(ns, 'security', 'protectClass', protectClass)
o=execute(ns, 'protectClass', name=".Contact")
o.protect(permission="edit", method='update')
o.protect(permission="view", methods='name, email')
o()
self.assertEquals(protections, [
(".Contact", "edit", 'update', None),
(".Contact", "view", None, 'name, email'),
])
protections=[]
class protectClass:
def __init__(self, name, permission=None, methods=None, method=None):
self._name=name
self._permission=permission
self._methods=methods
self._method=method
self._children=[]
def __call__(self):
if not self._children:
p=self._name, self._permission, self._method, self._methods
protections.append(p)
def protect(self, permission=None, method=None, methods=None):
if permission is None: permission=self._permission
if permission is None: raise 'no perm'
p=self._name, permission, method, methods
protections.append(p)
self._children.append(p)
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(MetaTest)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())