/usr/share/pyshared/zope/browsermenu/tests/test_menudirectives.py is in python-zope.browsermenu 3.9.1-0ubuntu4.
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | ##############################################################################
#
# Copyright (c) 2002 Zope Corporation 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.
#
##############################################################################
"""Browser Menu Directives Tests
$Id: test_menudirectives.py 103270 2009-08-27 13:56:02Z nadako $
"""
import unittest
from zope.configuration.xmlconfig import XMLConfig
from zope.interface import Interface, implements
from zope.publisher.browser import TestRequest
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.browsermenu.interfaces import IBrowserMenu
from zope.security.interfaces import Unauthorized, Forbidden
import zope.component
import zope.security
from zope.testing import cleanup
import zope.browsermenu
template = """<configure
xmlns='http://namespaces.zope.org/zope'
xmlns:browser='http://namespaces.zope.org/browser'
i18n_domain='zope'>
%s
</configure>"""
class I1(Interface): pass
class I11(I1): pass
class I12(I1): pass
class I111(I11): pass
class C1(object):
implements(I1)
class I2(Interface): pass
class C2(object):
implements(I2)
class TestObject(object):
implements(IBrowserPublisher, I111)
def f(self):
pass
def browserDefault(self, r):
return self, ()
def publishTraverse(self, request, name):
if name[:1] == 'f':
raise Forbidden(name)
if name[:1] == 'u':
raise Unauthorized(name)
return self.f
class IMyLayer(Interface):
pass
class IMySkin(IMyLayer, IDefaultBrowserLayer):
pass
class TestPermissions(cleanup.CleanUp, unittest.TestCase):
def setUp(self):
super(TestPermissions, self).setUp()
XMLConfig('meta.zcml', zope.browsermenu)()
XMLConfig('meta.zcml', zope.security)()
def testMenuItemsPermission(self):
XMLConfig('tests/menus-permissions.zcml', zope.browsermenu)()
menu = zope.component.getUtility(IBrowserMenu, 'test_id')
# This is a bit icky, but the menu hides too much stuff from us.
items = zope.component.getAdapters((C2(), TestRequest()),
menu.getMenuItemType())
item = list(items)[0][1]
self.assertEquals("zope.View", item.permission)
class Test(cleanup.CleanUp, unittest.TestCase):
def setUp(self):
super(Test, self).setUp()
XMLConfig('meta.zcml', zope.browsermenu)()
def testMenusAndMenuItems(self):
XMLConfig('tests/menus.zcml', zope.browsermenu)()
menu = zope.browsermenu.menu.getMenu(
'test_id', TestObject(), TestRequest())
def d(n):
return {'action': "a%s" % n,
'title': "t%s" % n,
'description': u'',
'selected': '',
'submenu': None,
'icon': None,
'extra': None}
self.assertEqual(menu[:-1], [d(5), d(6), d(3), d(2), d(1)])
self.assertEqual(
menu[-1],
{'submenu': [{'submenu': None,
'description': u'',
'extra': None,
'selected': u'',
'action': u'a10',
'title': u't10',
'icon': None}],
'description': u'',
'extra': None,
'selected': u'',
'action': u'',
'title': u's1',
'icon': None})
first = zope.browsermenu.menu.getFirstMenuItem(
'test_id', TestObject(), TestRequest())
self.assertEqual(first, d(5))
def testMenuItemWithLayer(self):
XMLConfig('tests/menus.zcml', zope.browsermenu)()
menu = zope.browsermenu.menu.getMenu(
'test_id', TestObject(), TestRequest())
self.assertEqual(len(menu), 6)
menu = zope.browsermenu.menu.getMenu(
'test_id', TestObject(), TestRequest(skin=IMyLayer))
self.assertEqual(len(menu), 2)
menu = zope.browsermenu.menu.getMenu(
'test_id', TestObject(), TestRequest(skin=IMySkin))
self.assertEqual(len(menu), 8)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test),
unittest.makeSuite(TestPermissions),
))
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
|