/usr/share/pyshared/zope/app/publication/tests/test_simplecomponenttraverser.py is in python-zope.app.publication 3.13.2-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Sample Component Traverser Test
"""
import unittest
from zope.publisher.interfaces import NotFound
from zope.interface import Interface, directlyProvides
from zope.app.publication.traversers import SimpleComponentTraverser
from zope import component
class I(Interface):
pass
class Container(object):
def __init__(self, **kw):
for k in kw:
setattr(self, k , kw[k])
def get(self, name, default=None):
return getattr(self, name, default)
class Request(object):
def __init__(self, type):
directlyProvides(self, type)
def getEffectiveURL(self):
return ''
class View(object):
def __init__(self, comp, request):
self._comp = comp
class Test(unittest.TestCase):
def testAttr(self):
# test container traver
foo = Container()
c = Container(foo=foo)
req = Request(I)
T = SimpleComponentTraverser(c, req)
self.assertRaises(NotFound , T.publishTraverse, req ,'foo')
def testView(self):
# test getting a view
foo = Container()
c = Container(foo=foo)
req = Request(I)
T = SimpleComponentTraverser(c, req)
component.provideAdapter(View, (None, I), Interface,
name='foo')
self.failUnless(T.publishTraverse(req, 'foo').__class__ is View)
self.assertRaises(NotFound, T.publishTraverse, req , 'morebar')
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
|