[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/tests - testContainerTraversable.py:1.1.2.4
Jim Fulton
jim@zope.com
Thu, 23 May 2002 14:01:41 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/tests
In directory cvs.zope.org:/tmp/cvs-serv26429/lib/python/Zope/App/OFS/Container/tests
Modified Files:
Tag: Zope-3x-branch
testContainerTraversable.py
Log Message:
This all started with wanting to be able to use url;view in a ZPT path. :)
That lead me to:
- Massive traversal refactoring.
Namespace handling is now centralized in Zope.App.Traversing.
- ZPT refactoring, including some renaming that touches pretty much everything. :)
- The application specific ZPT support was moved into
Zope.App.PageTemplate.
- To get page template files (for use in views):
from Zope.App.PageTemplate import ViewPageTemplateFile
- Fixed up security so that ZPT expressions only have access to
safe builtins and so that modules namespace does imports safely.
- Got ZPTPage working!
- renaming url to absolute_url and got absolute_url to work in paths.
- Cleaned up the (as yet unused) RestrictedInterpreter module in
Zope.Security. In particular, changed to use a separate
RestrictedBuiltins module.
=== Zope3/lib/python/Zope/App/OFS/Container/tests/testContainerTraversable.py 1.1.2.3 => 1.1.2.4 ===
#
##############################################################################
-"""
+"""
$Id$
"""
-
-import unittest, sys
-from Zope.App.OFS.Container.ContainerTraversable import ContainerTraversable
-from Zope.Exceptions import NotFoundError
-from Zope.App.OFS.Container.IContainer import IContainer
-from Zope.Testing.CleanUp import CleanUp
-
-
-class Container:
-
- __implements__ = IContainer
-
- def __init__(self, attrs={}, objs={}):
- for attr,value in attrs.iteritems():
- setattr(self, attr, value)
-
- self.__objs = {}
- for name,value in objs.iteritems():
- self.__objs[name] = value
-
-
- def getObject(self, name, default=None):
- return self.__objs.get(name, default)
-
- def hasObject(self, name):
- return self.__objs.has_key(name)
-
-class Test(CleanUp, unittest.TestCase):
-
- def testAttr(self):
- """ test container path traversal """
-
- foo = Container()
- bar = Container()
- baz = Container()
- c = Container( {'foo':foo}, {'bar':bar, 'foo':baz} )
-
- T = ContainerTraversable(c)
- self.failUnless(T.traverse('foo', '') is foo)
- self.failUnless(T.traverse('bar', '') is bar)
-
- self.assertRaises(NotFoundError , T.traverse, 'morebar', '')
-
- self.failUnless(T.traverse('foo;method', '') is foo)
- self.failUnless(T.traverse('bar;content', '') is bar)
- self.failUnless(T.traverse('foo;content', '') is baz)
-
-
-def test_suite():
- loader=unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
- unittest.TextTestRunner().run(test_suite())
+
+import unittest, sys
+from Zope.App.OFS.Container.ContainerTraversable import ContainerTraversable
+from Zope.Exceptions import NotFoundError
+from Zope.App.OFS.Container.IContainer import IContainer
+from Zope.Testing.CleanUp import CleanUp
+
+
+class Container:
+
+ __implements__ = IContainer
+
+ def __init__(self, attrs={}, objs={}):
+ for attr,value in attrs.iteritems():
+ setattr(self, attr, value)
+
+ self.__objs = {}
+ for name,value in objs.iteritems():
+ self.__objs[name] = value
+
+
+ def getObject(self, name, default=None):
+ return self.__objs.get(name, default)
+
+ def hasObject(self, name):
+ return self.__objs.has_key(name)
+
+class Test(CleanUp, unittest.TestCase):
+
+ def testAttr(self):
+ """ test container path traversal """
+
+ foo = Container()
+ bar = Container()
+ baz = Container()
+ c = Container( {'foo':foo}, {'bar':bar, 'foo':baz} )
+
+ T = ContainerTraversable(c)
+ self.failUnless(T.traverse('foo', (), 'foo', []) is baz)
+ self.failUnless(T.traverse('bar', (), 'bar', []) is bar)
+
+ self.assertRaises(NotFoundError , T.traverse,
+ 'morebar', (), 'morebar', [])
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())