Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
91a1052f
Commit
91a1052f
authored
Jun 05, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of a ZopeTestCase dependency
parent
a656866d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
34 deletions
+42
-34
AC-vs-DTML-TODO.txt
AC-vs-DTML-TODO.txt
+0
-4
src/AccessControl/tests/testZCML.py
src/AccessControl/tests/testZCML.py
+42
-30
No files found.
AC-vs-DTML-TODO.txt
View file @
91a1052f
...
...
@@ -34,10 +34,6 @@ AccessControl
the App package, which could serve as a general dumping ground for ZMI
related stuff from "reusable" packages.
- Test only dependencies:
* Testing
DocumentTemplate
----------------
...
...
src/AccessControl/tests/testZCML.py
View file @
91a1052f
...
...
@@ -62,6 +62,9 @@ class Dummy3:
class
Dummy4
:
foo
=
None
class
Dummy5
:
pass
def
test_security_equivalence
():
"""This test demonstrates that the traditional declarative security of
Zope 2 can be replaced by ZCML statements without any loss of
...
...
@@ -220,6 +223,9 @@ def test_checkPermission():
>>> from zope.component.testing import setUp, tearDown
>>> setUp()
>>> from zope.component import eventtesting
>>> eventtesting.setUp()
zope.security has a function zope.security.checkPermission which provides
an easy way of checking whether the currently authenticated user
has the permission to access an object. The function delegates to
...
...
@@ -235,33 +241,34 @@ def test_checkPermission():
>>> XMLConfig('meta.zcml', AccessControl)()
>>> XMLConfig('permissions.zcml', AccessControl)()
>>> from AccessControl.tests.testZCML import Dummy5
>>> dummy = Dummy5()
In the following we want to test AccessControl's checkPermission function.
We do that by taking the test's folder and asserting several
standard permissions. What we want to assure is that
checkPermission translates the Zope 2 permissions correctly,
especially the edge cases:
What we want to assure is that checkPermission translates the Zope 2
permissions correctly, especially the edge cases:
a) zope2.Public (which should always be available to everyone)
>>> from AccessControl.security import checkPermission
>>> checkPermission('zope2.Public',
self.folder
)
>>> checkPermission('zope2.Public',
dummy
)
True
b) zope2.Private (which should never available to anyone)
>>> checkPermission('zope.Private',
self.folder
)
>>> checkPermission('zope.Private',
dummy
)
False
>>> checkPermission('zope2.Private',
self.folder
)
>>> checkPermission('zope2.Private',
dummy
)
False
Any other standard Zope 2 permission will also resolve correctly:
>>> checkPermission('zope2.
AccessContentsInformation', self.folder
)
Tru
e
>>> checkPermission('zope2.
ViewManagementScreens', dummy
)
Fals
e
Invalid permissions will obviously result in a negative response:
>>> checkPermission('notapermission',
self.folder
)
>>> checkPermission('notapermission',
dummy
)
False
...
...
@@ -281,24 +288,24 @@ def test_checkPermission():
a) zope2.Public (which should always be available to everyone)
>>> from zope.security import checkPermission
>>> checkPermission('zope2.Public',
self.folder
)
>>> checkPermission('zope2.Public',
dummy
)
True
b) zope2.Private (which should never available to anyone)
>>> checkPermission('zope.Private',
self.folder
)
>>> checkPermission('zope.Private',
dummy
)
False
>>> checkPermission('zope2.Private',
self.folder
)
>>> checkPermission('zope2.Private',
dummy
)
False
Any other standard Zope 2 permission will also resolve correctly:
>>> checkPermission('zope2.
AccessContentsInformation', self.folder
)
Tru
e
>>> checkPermission('zope2.
ViewManagementScreens', dummy
)
Fals
e
Invalid permissions will obviously result in a negative response:
>>> checkPermission('notapermission',
self.folder
)
>>> checkPermission('notapermission',
dummy
)
False
Clean up:
...
...
@@ -311,9 +318,12 @@ def test_register_permission():
to create a permission that does not already exist, it is created on
startup, with roles defaulting to Manager.
>>> from
Testing.ZopeTestCase.placeless
import setUp, tearDown
>>> from
zope.component.testing
import setUp, tearDown
>>> setUp()
>>> from zope.component import eventtesting
>>> eventtesting.setUp()
First, we need to configure the relevant parts of AccessControl:
>>> import AccessControl
...
...
@@ -341,18 +351,19 @@ def test_register_permission():
The permission will be made available globally, with default role set
of ('Manager',).
>>> roles = self.app.rolesOfPermission('AccessControl: Dummy permission')
>>> sorted(r['name'] for r in roles if r['selected'])
['Manager']
>>> import Products
>>> permissions = getattr(Products, '__ac_permissions__', ())
>>> [p[2] for p in permissions
... if p[0] == 'AccessControl: Dummy permission']
[('Manager',)]
Let's also ensure that permissions are not overwritten if they exist
already:
>>> from AccessControl.Permission import _registeredPermissions
>>> import Products
>>> _registeredPermissions['Dummy: Other dummy'] = 1
>>> Products.__ac_permissions__ += (
('Dummy: Other dummy', (), (),),)
>>> self.app.manage_permission('Dummy: Other dummy', roles=['Anonymous']
)
>>> Products.__ac_permissions__ += (
... ('Dummy: Other dummy', (), ('Anonymous', ),),
)
>>> from StringIO import StringIO
>>> configure_zcml = StringIO('''
...
...
@@ -369,13 +380,14 @@ def test_register_permission():
>>> from zope.configuration.xmlconfig import xmlconfig
>>> xmlconfig(configure_zcml)
>>> roles = self.app.rolesOfPermission('Dummy: Other dummy')
>>> sorted(r['name'] for r in roles if r['selected'])
['Anonymous']
>>> permissions = getattr(Products, '__ac_permissions__', ())
>>> [p[2] for p in permissions
... if p[0] == 'Dummy: Other dummy']
[('Anonymous',)]
>>> tearDown()
"""
def
test_suite
():
from
Testing.ZopeTestCase
import
ZopeDocTestSuite
return
Zope
DocTestSuite
()
import
doctest
return
doctest
.
DocTestSuite
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment