[Zope3-checkins] CVS: Zope3/src/zope/app/container/tests -
test_containertraverser.py:1.10
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Feb 13 22:02:19 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/container/tests
In directory cvs.zope.org:/tmp/cvs-serv27114/src/zope/app/container/tests
Modified Files:
test_containertraverser.py
Log Message:
Now I know where these aweful tests in the case-insensitive traverser came
from. They were just copied over from the default container traverser. So
I cleaned up the original tests and abstracted them a bit, so they can be
reused by other implementations. Removed unneccessary duplication of code
in the case-insensitive container traverser tests.
=== Zope3/src/zope/app/container/tests/test_containertraverser.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/container/tests/test_containertraverser.py:1.9 Fri Nov 21 12:11:31 2003
+++ Zope3/src/zope/app/container/tests/test_containertraverser.py Fri Feb 13 22:01:48 2004
@@ -11,82 +11,86 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""
+"""Container Traverser Tests
$Id$
"""
-
import unittest
-from zope.component.tests.request import Request
-from zope.component import getService
-from zope.app.services.servicenames import Presentation
from zope.app.container.traversal import ContainerTraverser
-from zope.interface import Interface, implements
-from zope.exceptions import NotFoundError
-from zope.app.interfaces.container import IContainer
+from zope.app.interfaces.container import IReadContainer
+from zope.app.tests import ztapi
from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.component.tests.request import Request
+from zope.exceptions import NotFoundError
+from zope.interface import implements
+from zope.publisher.interfaces.browser import IBrowserRequest
-class I(Interface):
- pass
-
-
-class Container:
- implements(IContainer)
+class TestContainer:
+ implements(IReadContainer)
def __init__(self, **kw):
- for k in kw:
- setattr(self, k , kw[k])
+ for name, value in kw.items():
+ setattr(self, name , value)
def get(self, name, default=None):
return getattr(self, name, default)
-
-class Request(Request):
- def getEffectiveURL(self):
- return ''
-
-
class View:
- def __init__(self, comp, request):
- self._comp = comp
-
-
-class Test(PlacelessSetup, unittest.TestCase):
- def testAttr(self):
- # test container traver
- foo = Container()
- c = Container(foo=foo)
- req = Request(I, '')
-
- T = ContainerTraverser(c, req)
- self.failUnless(T.publishTraverse(req,'foo') is foo)
-
- self.assertRaises(NotFoundError , T.publishTraverse, req ,'morebar')
-
-
- def testView(self):
- # test getting a view
- foo = Container()
- c = Container(foo=foo)
- req = Request(I, '')
-
- T = ContainerTraverser(c, req)
- getService(None, Presentation).provideView(
- IContainer, 'viewfoo', I, [View])
-
- self.failUnless(T.publishTraverse(req,'viewfoo').__class__ is View )
- self.failUnless(T.publishTraverse(req,'foo') is foo)
-
- self.assertRaises(NotFoundError , T.publishTraverse, req, 'morebar')
- self.assertRaises(NotFoundError , T.publishTraverse, req,
- '@@morebar')
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+
+class TraverserTest(PlacelessSetup, unittest.TestCase):
+
+ # The following two methods exist, so that other container traversers can
+ # use these tests as a base.
+ def _getTraverser(self, context, request):
+ return ContainerTraverser(context, request)
+
+ def _getContainer(self, **kw):
+ return TestContainer(**kw)
+
+ def setUp(self):
+ super(TraverserTest, self).setUp()
+ # Create a small object tree
+ self.foo = self._getContainer()
+ foo2 = self._getContainer(Foo=self.foo)
+ # Initiate a request
+ self.request = Request(IBrowserRequest, '')
+ # Create the traverser
+ self.traverser = self._getTraverser(foo2, self.request)
+ # Define a simple view for the container
+ ztapi.browserView(IReadContainer, 'viewfoo', [View])
+
+ def test_itemTraversal(self):
+ self.assertEqual(
+ self.traverser.publishTraverse(self.request, 'Foo'),
+ self.foo)
+ self.assertRaises(
+ NotFoundError,
+ self.traverser.publishTraverse, self.request, 'morebar')
+
+ def test_viewTraversal(self):
+ self.assertEquals(
+ self.traverser.publishTraverse(self.request, 'viewfoo').__class__,
+ View)
+ self.assertEquals(
+ self.traverser.publishTraverse(self.request, 'Foo'),
+ self.foo)
+ self.assertRaises(
+ NotFoundError,
+ self.traverser.publishTraverse, self.request, 'morebar')
+ self.assertRaises(
+ NotFoundError,
+ self.traverser.publishTraverse, self.request, '@@morebar')
def test_suite():
- loader = unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
-
+ return unittest.TestSuite((
+ unittest.makeSuite(TraverserTest),
+ ))
if __name__ == '__main__':
- unittest.TextTestRunner().run(test_suite())
+ unittest.main(defaultTest='test_suite')
More information about the Zope3-Checkins
mailing list