[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZopePublication/tests - testDefaultTraverser.py:1.1.2.1
Andreas Jung
andreas@digicool.com
Thu, 10 Jan 2002 13:40:18 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/ZopePublication/tests
In directory cvs.zope.org:/tmp/cvs-serv4819
Added Files:
Tag: Zope-3x-branch
testDefaultTraverser.py
Log Message:
initial add
=== Added File Zope3/lib/python/Zope/App/ZopePublication/tests/testDefaultTraverser.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
#
##############################################################################
import unittest, sys
from Zope.ComponentArchitecture.tests.Request import Request
from Zope.ComponentArchitecture import provideView, _clear
from Zope.App.ZopePublication.Traversers import DefaultTraverser
from Interface import Interface
from Zope.Exceptions import NotFoundError
class I(Interface): pass
class Container:
def __init__(self, **kw):
for k in kw:
setattr(self, k , kw[k])
def getObject(self, name, default=None):
return getattr(self, name, default)
class Request(Request):
def getEffectiveURL(self):
return ''
class View:
def __init__(self, comp):
self._comp = comp
class Test(unittest.TestCase):
def tearDown(self):
_clear()
def testAttr(self):
""" test container traver """
foo = Container()
c = Container( foo=foo )
req = Request( I, '')
T = DefaultTraverser(c)
self.failUnless(T.browser_traverse(req,'foo') is foo)
self.assertRaises(NotFoundError , T.browser_traverse, req ,'morebar')
def testView(self):
""" test getting a view """
foo = Container()
c = Container( foo=foo )
req = Request( I, '')
T = DefaultTraverser(c)
provideView(None , 'foo', I, View)
self.failUnless(T.browser_traverse(req,'foo;view').__class__ is View )
self.failUnless(T.browser_traverse(req,'foo') is foo)
self.assertRaises(NotFoundError , T.browser_traverse, req ,'morebar')
self.assertRaises(NotFoundError , T.browser_traverse, req ,'morebar;view')
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())