[Zope3-checkins] CVS: Zope3/src/zope/app/browser/security/tests - test_permissionwidget.py:1.8
Jim Fulton
jim@zope.com
Fri, 7 Mar 2003 16:14:49 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/security/tests
In directory cvs.zope.org:/tmp/cvs-serv8587/tests
Modified Files:
test_permissionwidget.py
Log Message:
Updated permission widgets to properly handle CheckerPublic/zope.Public.
=== Zope3/src/zope/app/browser/security/tests/test_permissionwidget.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/browser/security/tests/test_permissionwidget.py:1.7 Tue Feb 11 21:17:11 2003
+++ Zope3/src/zope/app/browser/security/tests/test_permissionwidget.py Fri Mar 7 16:14:41 2003
@@ -20,6 +20,7 @@
from unittest import TestCase, TestSuite, main, makeSuite
from zope.testing.cleanup import CleanUp
+from zope.security.checker import CheckerPublic
from zope.app.security.permission import PermissionField
from zope.app.browser.security.permissionwidget import SinglePermissionWidget
from zope.publisher.browser import TestRequest
@@ -144,6 +145,61 @@
'</select>'
)
+ self.assertEqual(widget(), out)
+
+ def testPermissionWidget_w_public(self):
+ defineService(Permissions, IPermissionService)
+ serviceManager.provideService(Permissions, permissionRegistry)
+
+ permissionRegistry.definePermission('read', 'Read', 'Read something')
+ read_permission = permissionRegistry.getPermission('read')
+ permissionRegistry.definePermission('reread', 'ReRead',
+ 'ReRead something')
+ reread_permission = permissionRegistry.getPermission('reread')
+ request = TestRequest()
+
+ permissionField = PermissionField(__name__ = 'TestName',
+ title = u"This is a test",
+ required=False)
+
+ widget = SinglePermissionWidget(permissionField, request)
+
+ out = (
+ '<input type="text" name="field.TestName.search" value="">'
+ '<select name="field.TestName">'
+ '<option value="">---select permission---</option>'
+
+ '<option value="'
+ 'read'
+ '">'
+ 'read'
+ '</option>'
+
+ '<option value="'
+ 'reread'
+ '">'
+ 'reread'
+ '</option>'
+
+ '<option value="'
+ 'zope.Public'
+ '" selected>'
+ 'zope.Public'
+ '</option>'
+
+ '</select>'
+ )
+
+ self.assertEqual(widget.render(CheckerPublic), out)
+
+ self.assertEqual(widget.getData(), None)
+
+ widget = SinglePermissionWidget(permissionField, request)
+
+ request.form["field.TestName"] = 'zope.Public'
+
+ self.assertEqual(widget.getData(), CheckerPublic)
+
self.assertEqual(widget(), out)