1
##############################################################################
3
# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
13
##############################################################################
14
"""Functional tests for Security Policy's Grant screens.
16
$Id: test_functional.py 81329 2007-10-31 19:53:46Z srichter $
23
from zope.testing import renormalizing
24
from zope.security.interfaces import IPermission
25
from zope.security.permission import Permission
26
from zope.securitypolicy.role import Role
27
from zope.securitypolicy.interfaces import IRole
29
from zope.app.testing import functional
30
from zope.app.securitypolicy.testing import SecurityPolicyLayer
33
class RolePermissionsTest(functional.BrowserTestCase):
35
def testAllRolePermissionsForm(self):
36
response = self.publish(
37
'/++etc++site/@@AllRolePermissions.html',
39
self.assertEqual(response.getStatus(), 200)
40
body = response.getBody()
41
self.assert_('Permissions' in body)
42
self.assert_('Manage Content' in body)
43
self.assert_('Manage Site' in body)
44
self.assert_('Roles' in body)
45
self.assert_('Site Manager' in body)
46
self.assert_('Site Member' in body)
47
self.failIf(_result in body)
48
self.checkForBrokenLinks(body,
49
'/++etc++site/@@AllRolePermissions.html',
52
def testAllRolePermissions(self):
53
response = self.publish(
54
'/++etc++site/@@AllRolePermissions.html',
55
form={'p0r0': 'Allow',
56
'p0': 'zope.ManageContent',
58
'SUBMIT': 'Save Changes'},
60
self.assertEqual(response.getStatus(), 200)
61
body = response.getBody()
62
self.assert_('<p>Settings changed' in body)
63
self.assert_(_result in body)
65
def testRolesWithPermissionsForm(self):
66
response = self.publish(
67
'/++etc++site/@@RolesWithPermissions.html'
68
'?permission_to_manage=zope.View',
70
self.assertEqual(response.getStatus(), 200)
71
body = response.getBody()
72
self.assert_('Roles assigned to the permission' in body)
73
self.assert_('Role' in body)
74
self.assert_('Setting' in body)
75
self.assert_('"Save Changes"' in body)
76
self.checkForBrokenLinks(body, '/@@RolesWithPermissions.html',
79
def testRolesWithPermissionsForm(self):
80
response = self.publish(
81
'/++etc++site/@@RolePermissions.html?role_to_manage=zope.Manager',
83
self.assertEqual(response.getStatus(), 200)
84
body = response.getBody()
86
'This page shows the permissions allowed and denied the role'
88
self.assert_('Allow' in body)
89
self.assert_('Deny' in body)
90
self.checkForBrokenLinks(body, '/++etc++site/@@RolesPermissions.html',
93
def testAllRolePermissionsFormForLocalRoles(self):
94
role = Role(u"id", u"Local Role")
95
zope.component.provideUtility(role, IRole)
96
self.testAllRolePermissions()
98
response = self.publish(
99
'/++etc++site/@@AllRolePermissions.html',
101
body = response.getBody()
102
self.assert_('Local Role' in body)
104
def testAllRolePermissionsFormForLocalPermissions(self):
105
permission = Permission(u"id", u"Local Permission")
106
zope.component.provideUtility(permission, IPermission)
107
self.testAllRolePermissions()
109
response = self.publish(
110
'/++etc++site/@@AllRolePermissions.html',
112
body = response.getBody()
113
self.assert_('Local Permission' in body)
115
def testRolesWithPermissionsFormForLocalPermission(self):
116
permission = Permission(u"id", u"Local Permission")
117
zope.component.provideUtility(permission, IPermission, 'id')
119
response = self.publish(
120
'/++etc++site/@@AllRolePermissions.html',
121
form={'role_id': 'zope.Manager',
124
'SUBMIT_ROLE': 'Save Changes'},
127
body = response.getBody()
128
self.assert_('You choose both allow and deny for permission'
129
' "Local Permission". This is not allowed.' in body)
132
<option value="Unset"> </option>
133
<option value="Allow" selected="selected">+</option>
134
<option value="Deny">-</option>
138
checker = renormalizing.RENormalizing([
139
(re.compile(r"HTTP/1\.1 (\d\d\d) .*"), r"HTTP/1.1 \1 <MESSAGE>"),
144
RolePermissionsTest.layer = SecurityPolicyLayer
145
granting = functional.FunctionalDocFileSuite(
146
'../granting_ftest.txt', checker=checker)
147
granting.layer = SecurityPolicyLayer
148
return unittest.TestSuite((
149
unittest.makeSuite(RolePermissionsTest),
154
if __name__ == '__main__':
155
unittest.main(defaultTest='test_suite')