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
Hide 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
...
@@ -34,10 +34,6 @@ AccessControl
the App package, which could serve as a general dumping ground for ZMI
the App package, which could serve as a general dumping ground for ZMI
related stuff from "reusable" packages.
related stuff from "reusable" packages.
- Test only dependencies:
* Testing
DocumentTemplate
DocumentTemplate
----------------
----------------
...
...
src/AccessControl/tests/testZCML.py
View file @
91a1052f
...
@@ -62,6 +62,9 @@ class Dummy3:
...
@@ -62,6 +62,9 @@ class Dummy3:
class
Dummy4
:
class
Dummy4
:
foo
=
None
foo
=
None
class
Dummy5
:
pass
def
test_security_equivalence
():
def
test_security_equivalence
():
"""This test demonstrates that the traditional declarative security of
"""This test demonstrates that the traditional declarative security of
Zope 2 can be replaced by ZCML statements without any loss of
Zope 2 can be replaced by ZCML statements without any loss of
...
@@ -220,6 +223,9 @@ def test_checkPermission():
...
@@ -220,6 +223,9 @@ def test_checkPermission():
>>> from zope.component.testing import setUp, tearDown
>>> from zope.component.testing import setUp, tearDown
>>> setUp()
>>> setUp()
>>> from zope.component import eventtesting
>>> eventtesting.setUp()
zope.security has a function zope.security.checkPermission which provides
zope.security has a function zope.security.checkPermission which provides
an easy way of checking whether the currently authenticated user
an easy way of checking whether the currently authenticated user
has the permission to access an object. The function delegates to
has the permission to access an object. The function delegates to
...
@@ -235,33 +241,34 @@ def test_checkPermission():
...
@@ -235,33 +241,34 @@ def test_checkPermission():
>>> XMLConfig('meta.zcml', AccessControl)()
>>> XMLConfig('meta.zcml', AccessControl)()
>>> XMLConfig('permissions.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.
In the following we want to test AccessControl's checkPermission function.
We do that by taking the test's folder and asserting several
What we want to assure is that checkPermission translates the Zope 2
standard permissions. What we want to assure is that
permissions correctly, especially the edge cases:
checkPermission translates the Zope 2 permissions correctly,
especially the edge cases:
a) zope2.Public (which should always be available to everyone)
a) zope2.Public (which should always be available to everyone)
>>> from AccessControl.security import checkPermission
>>> from AccessControl.security import checkPermission
>>> checkPermission('zope2.Public',
self.folder
)
>>> checkPermission('zope2.Public',
dummy
)
True
True
b) zope2.Private (which should never available to anyone)
b) zope2.Private (which should never available to anyone)
>>> checkPermission('zope.Private',
self.folder
)
>>> checkPermission('zope.Private',
dummy
)
False
False
>>> checkPermission('zope2.Private',
self.folder
)
>>> checkPermission('zope2.Private',
dummy
)
False
False
Any other standard Zope 2 permission will also resolve correctly:
Any other standard Zope 2 permission will also resolve correctly:
>>> checkPermission('zope2.
AccessContentsInformation', self.folder
)
>>> checkPermission('zope2.
ViewManagementScreens', dummy
)
Tru
e
Fals
e
Invalid permissions will obviously result in a negative response:
Invalid permissions will obviously result in a negative response:
>>> checkPermission('notapermission',
self.folder
)
>>> checkPermission('notapermission',
dummy
)
False
False
...
@@ -281,24 +288,24 @@ def test_checkPermission():
...
@@ -281,24 +288,24 @@ def test_checkPermission():
a) zope2.Public (which should always be available to everyone)
a) zope2.Public (which should always be available to everyone)
>>> from zope.security import checkPermission
>>> from zope.security import checkPermission
>>> checkPermission('zope2.Public',
self.folder
)
>>> checkPermission('zope2.Public',
dummy
)
True
True
b) zope2.Private (which should never available to anyone)
b) zope2.Private (which should never available to anyone)
>>> checkPermission('zope.Private',
self.folder
)
>>> checkPermission('zope.Private',
dummy
)
False
False
>>> checkPermission('zope2.Private',
self.folder
)
>>> checkPermission('zope2.Private',
dummy
)
False
False
Any other standard Zope 2 permission will also resolve correctly:
Any other standard Zope 2 permission will also resolve correctly:
>>> checkPermission('zope2.
AccessContentsInformation', self.folder
)
>>> checkPermission('zope2.
ViewManagementScreens', dummy
)
Tru
e
Fals
e
Invalid permissions will obviously result in a negative response:
Invalid permissions will obviously result in a negative response:
>>> checkPermission('notapermission',
self.folder
)
>>> checkPermission('notapermission',
dummy
)
False
False
Clean up:
Clean up:
...
@@ -311,9 +318,12 @@ def test_register_permission():
...
@@ -311,9 +318,12 @@ def test_register_permission():
to create a permission that does not already exist, it is created on
to create a permission that does not already exist, it is created on
startup, with roles defaulting to Manager.
startup, with roles defaulting to Manager.
>>> from
Testing.ZopeTestCase.placeless
import setUp, tearDown
>>> from
zope.component.testing
import setUp, tearDown
>>> setUp()
>>> setUp()
>>> from zope.component import eventtesting
>>> eventtesting.setUp()
First, we need to configure the relevant parts of AccessControl:
First, we need to configure the relevant parts of AccessControl:
>>> import AccessControl
>>> import AccessControl
...
@@ -340,19 +350,20 @@ def test_register_permission():
...
@@ -340,19 +350,20 @@ def test_register_permission():
The permission will be made available globally, with default role set
The permission will be made available globally, with default role set
of ('Manager',).
of ('Manager',).
>>> roles = self.app.rolesOfPermission('AccessControl: Dummy permission')
>>> import Products
>>> sorted(r['name'] for r in roles if r['selected'])
>>> permissions = getattr(Products, '__ac_permissions__', ())
['Manager']
>>> [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
Let's also ensure that permissions are not overwritten if they exist
already:
already:
>>> from AccessControl.Permission import _registeredPermissions
>>> from AccessControl.Permission import _registeredPermissions
>>> import Products
>>> _registeredPermissions['Dummy: Other dummy'] = 1
>>> _registeredPermissions['Dummy: Other dummy'] = 1
>>> Products.__ac_permissions__ += (
('Dummy: Other dummy', (), (),),)
>>> Products.__ac_permissions__ += (
>>> self.app.manage_permission('Dummy: Other dummy', roles=['Anonymous']
)
... ('Dummy: Other dummy', (), ('Anonymous', ),),
)
>>> from StringIO import StringIO
>>> from StringIO import StringIO
>>> configure_zcml = StringIO('''
>>> configure_zcml = StringIO('''
...
@@ -369,13 +380,14 @@ def test_register_permission():
...
@@ -369,13 +380,14 @@ def test_register_permission():
>>> from zope.configuration.xmlconfig import xmlconfig
>>> from zope.configuration.xmlconfig import xmlconfig
>>> xmlconfig(configure_zcml)
>>> xmlconfig(configure_zcml)
>>> roles = self.app.rolesOfPermission('Dummy: Other dummy')
>>> permissions = getattr(Products, '__ac_permissions__', ())
>>> sorted(r['name'] for r in roles if r['selected'])
>>> [p[2] for p in permissions
['Anonymous']
... if p[0] == 'Dummy: Other dummy']
[('Anonymous',)]
>>> tearDown()
>>> tearDown()
"""
"""
def
test_suite
():
def
test_suite
():
from
Testing.ZopeTestCase
import
ZopeDocTestSuite
import
doctest
return
Zope
DocTestSuite
()
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