[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/tests - testContainerTraversable.py:1.1.2.1
Steve Alexander
steve@cat-box.net
Wed, 20 Mar 2002 18:11:57 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/tests
In directory cvs.zope.org:/tmp/cvs-serv13451/lib/python/Zope/App/OFS/Container/tests
Added Files:
Tag: Zope-3x-branch
testContainerTraversable.py
Log Message:
Added a ContainerTraversable that (if enabled in zcml) traverses
containers from path expressions (and such like, not URL traversal),
and searches attributes followed by subobjects.
You can also choose explicitly whether you want attributes or subobjects
by using name;method or name;content respectively.
=== Added File Zope3/lib/python/Zope/App/OFS/Container/tests/testContainerTraversable.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
##############################################################################
"""
$Id: testContainerTraversable.py,v 1.1.2.1 2002/03/20 23:11:56 stevea Exp $
"""
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())