[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/security/ Added a
utility function for getting an iterator over all permission ids.
Jim Fulton
jim at zope.com
Mon May 17 06:02:09 EDT 2004
Log message for revision 24769:
Added a utility function for getting an iterator over all permission ids.
-=-
Modified: Zope3/trunk/src/zope/app/security/permission.py
===================================================================
--- Zope3/trunk/src/zope/app/security/permission.py 2004-05-17 09:54:53 UTC (rev 24768)
+++ Zope3/trunk/src/zope/app/security/permission.py 2004-05-17 10:02:08 UTC (rev 24769)
@@ -32,8 +32,44 @@
def checkPermission(context, permission_id):
- """Check whether a given permission exists in the provided context."""
+ """Check whether a given permission exists in the provided context.
+
+ >>> from zope.app.tests.placelesssetup import setUp, tearDown
+ >>> setUp()
+
+ >>> from zope.app.tests.ztapi import provideUtility
+ >>> provideUtility(IPermission, Permission('x'), 'x')
+
+ >>> checkPermission(None, 'x')
+ >>> checkPermission(None, 'y')
+ Traceback (most recent call last):
+ ...
+ ValueError: ('Undefined permission id', 'y')
+
+ >>> tearDown()
+ """
if permission_id == CheckerPublic:
return
if not zapi.queryUtility(context, IPermission, name=permission_id):
raise ValueError("Undefined permission id", permission_id)
+
+def allPermissions(context):
+ """Get the ids of all defined permissions
+
+ >>> from zope.app.tests.placelesssetup import setUp, tearDown
+ >>> setUp()
+
+ >>> from zope.app.tests.ztapi import provideUtility
+ >>> provideUtility(IPermission, Permission('x'), 'x')
+ >>> provideUtility(IPermission, Permission('y'), 'y')
+
+ >>> ids = list(allPermissions(None))
+ >>> ids.sort()
+ >>> ids
+ [u'x', u'y']
+
+ >>> tearDown()
+ """
+ for id, permission in zapi.getUtilitiesFor(context, IPermission):
+ if id != u'zope.Public':
+ yield id
Added: Zope3/trunk/src/zope/app/security/tests/test_permission.py
===================================================================
--- Zope3/trunk/src/zope/app/security/tests/test_permission.py 2004-05-17 09:54:53 UTC (rev 24768)
+++ Zope3/trunk/src/zope/app/security/tests/test_permission.py 2004-05-17 10:02:08 UTC (rev 24769)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+
+
+def test_suite():
+ return unittest.TestSuite((
+ DocTestSuite('zope.app.security.permission'),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
Property changes on: Zope3/trunk/src/zope/app/security/tests/test_permission.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Zope3-Checkins
mailing list