~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/zope/app/securitypolicy/browser/tests/test_functional.py

  • Committer: Sidnei da Silva
  • Date: 2010-07-05 21:07:01 UTC
  • Revision ID: sidnei.da.silva@canonical.com-20100705210701-zmqhqrbzad1mhzsl
- Reduce deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
4
 
# All Rights Reserved.
5
 
#
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.
12
 
#
13
 
##############################################################################
14
 
"""Functional tests for Security Policy's Grant screens.
15
 
 
16
 
$Id: test_functional.py 81329 2007-10-31 19:53:46Z srichter $
17
 
"""
18
 
 
19
 
import re
20
 
import unittest
21
 
 
22
 
import zope.component
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
28
 
 
29
 
from zope.app.testing import functional
30
 
from zope.app.securitypolicy.testing import SecurityPolicyLayer
31
 
 
32
 
 
33
 
class RolePermissionsTest(functional.BrowserTestCase):
34
 
 
35
 
    def testAllRolePermissionsForm(self):
36
 
        response = self.publish(
37
 
            '/++etc++site/@@AllRolePermissions.html',
38
 
            basic='mgr:mgrpw')
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',
50
 
                                 'mgr:mgrpw')
51
 
 
52
 
    def testAllRolePermissions(self):
53
 
        response = self.publish(
54
 
            '/++etc++site/@@AllRolePermissions.html',
55
 
            form={'p0r0': 'Allow',
56
 
                  'p0': 'zope.ManageContent',
57
 
                  'r0': 'zope.Manager',
58
 
                  'SUBMIT': 'Save Changes'},
59
 
            basic='mgr:mgrpw')
60
 
        self.assertEqual(response.getStatus(), 200)
61
 
        body = response.getBody()
62
 
        self.assert_('<p>Settings changed' in body)
63
 
        self.assert_(_result in body)
64
 
 
65
 
    def testRolesWithPermissionsForm(self):
66
 
        response = self.publish(
67
 
            '/++etc++site/@@RolesWithPermissions.html'
68
 
            '?permission_to_manage=zope.View',
69
 
            basic='mgr:mgrpw')
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',
77
 
                                 'mgr:mgrpw')
78
 
 
79
 
    def testRolesWithPermissionsForm(self):
80
 
        response = self.publish(
81
 
            '/++etc++site/@@RolePermissions.html?role_to_manage=zope.Manager',
82
 
            basic='mgr:mgrpw')
83
 
        self.assertEqual(response.getStatus(), 200)
84
 
        body = response.getBody()
85
 
        self.assert_(
86
 
            'This page shows the permissions allowed and denied the role'
87
 
            in body)
88
 
        self.assert_('Allow' in body)
89
 
        self.assert_('Deny' in body)
90
 
        self.checkForBrokenLinks(body, '/++etc++site/@@RolesPermissions.html',
91
 
                                 'mgr:mgrpw')
92
 
 
93
 
    def testAllRolePermissionsFormForLocalRoles(self):
94
 
        role = Role(u"id", u"Local Role")
95
 
        zope.component.provideUtility(role, IRole)
96
 
        self.testAllRolePermissions()
97
 
 
98
 
        response = self.publish(
99
 
            '/++etc++site/@@AllRolePermissions.html',
100
 
            basic='mgr:mgrpw')
101
 
        body = response.getBody()
102
 
        self.assert_('Local Role' in body)
103
 
 
104
 
    def testAllRolePermissionsFormForLocalPermissions(self):
105
 
        permission = Permission(u"id", u"Local Permission")
106
 
        zope.component.provideUtility(permission, IPermission)
107
 
        self.testAllRolePermissions()
108
 
 
109
 
        response = self.publish(
110
 
            '/++etc++site/@@AllRolePermissions.html',
111
 
            basic='mgr:mgrpw')
112
 
        body = response.getBody()
113
 
        self.assert_('Local Permission' in body)
114
 
 
115
 
    def testRolesWithPermissionsFormForLocalPermission(self):
116
 
        permission = Permission(u"id", u"Local Permission")
117
 
        zope.component.provideUtility(permission, IPermission, 'id')
118
 
 
119
 
        response = self.publish(
120
 
            '/++etc++site/@@AllRolePermissions.html',
121
 
            form={'role_id': 'zope.Manager',
122
 
                  'Allow': ['id'],
123
 
                  'Deny': ['id'],
124
 
                  'SUBMIT_ROLE': 'Save Changes'},
125
 
            basic='mgr:mgrpw',
126
 
            handle_errors=True)
127
 
        body = response.getBody()
128
 
        self.assert_('You choose both allow and deny for permission'
129
 
            ' "Local Permission". This is not allowed.' in body)
130
 
 
131
 
_result = '''\
132
 
            <option value="Unset"> </option>
133
 
            <option value="Allow" selected="selected">+</option>
134
 
            <option value="Deny">-</option>
135
 
'''
136
 
 
137
 
 
138
 
checker = renormalizing.RENormalizing([
139
 
    (re.compile(r"HTTP/1\.1 (\d\d\d) .*"), r"HTTP/1.1 \1 <MESSAGE>"),
140
 
    ])
141
 
 
142
 
 
143
 
def test_suite():
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),
150
 
        granting,
151
 
        ))
152
 
 
153
 
 
154
 
if __name__ == '__main__':
155
 
    unittest.main(defaultTest='test_suite')