[Zope3-checkins] CVS: Zope3/src/zope/app/browser/security/tests - __init__.py:1.2 test_permissionwidget.py:1.2
Jim Fulton
jim@zope.com
Wed, 25 Dec 2002 09:14:07 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/security/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/browser/security/tests
Added Files:
__init__.py test_permissionwidget.py
Log Message:
Grand renaming:
- Renamed most files (especially python modules) to lower case.
- Moved views and interfaces into separate hierarchies within each
project, where each top-level directory under the zope package
is a separate project.
- Moved everything to src from lib/python.
lib/python will eventually go away. I need access to the cvs
repository to make this happen, however.
There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.
=== Zope3/src/zope/app/browser/security/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:14:07 2002
+++ Zope3/src/zope/app/browser/security/tests/__init__.py Wed Dec 25 09:12:36 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
=== Zope3/src/zope/app/browser/security/tests/test_permissionwidget.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:14:07 2002
+++ Zope3/src/zope/app/browser/security/tests/test_permissionwidget.py Wed Dec 25 09:12:36 2002
@@ -0,0 +1,153 @@
+##############################################################################
+#
+# Copyright (c) 2002 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.
+#
+##############################################################################
+"""Permission field widget tests
+
+$Id$
+"""
+
+__metaclass__ = type
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.testing.cleanup import CleanUp
+from zope.app.security.permissionfield import PermissionField
+from zope.app.browser.security.permissionwidget import SinglePermissionWidget
+from zope.publisher.browser import TestRequest
+from zope.component.service \
+ import serviceManager, defineService
+
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.security.registries.permissionregistry import permissionRegistry
+from zope.component import getServiceManager
+from zope.app.interfaces.security import IPermissionService
+
+class TestPermissionWidget(PlacelessSetup, TestCase):
+
+ def testPermissionWidget(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)
+
+ self.assertEqual(widget.getData(), None)
+
+ 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'
+ '">'
+ 'zope.Public'
+ '</option>'
+
+
+ '</select>'
+ )
+
+ self.assertEqual(widget(), out)
+
+ out = (
+ '<input type="text" name="field.TestName.search" value="">'
+ '<select name="field.TestName">'
+ '<option value="">---select permission---</option>'
+
+ '<option value="'
+ 'read'
+ '" selected>'
+ 'read'
+ '</option>'
+
+ '<option value="'
+ 'reread'
+ '">'
+ 'reread'
+ '</option>'
+
+ '<option value="'
+ 'zope.Public'
+ '">'
+ 'zope.Public'
+ '</option>'
+
+ '</select>'
+ )
+
+ self.assertEqual(
+ widget.render(read_permission),
+ out)
+
+ self.assertEqual(widget.getData(), None)
+
+ widget = SinglePermissionWidget(permissionField, request)
+
+ request.form["field.TestName"] = (
+ 'read'
+ )
+ self.assertEqual(widget.getData(), read_permission)
+
+ self.assertEqual(widget(), out)
+
+ request.form["field.TestName.search"] = 'read'
+
+ out = (
+ '<input type="text" name="field.TestName.search" value="read">'
+ '<select name="field.TestName">'
+ '<option value="">---select permission---</option>'
+
+ '<option value="'
+ 'read'
+ '" selected>'
+ 'read'
+ '</option>'
+
+ '<option value="'
+ 'reread'
+ '">'
+ 'reread'
+ '</option>'
+
+ '</select>'
+ )
+ self.assertEqual(widget(), out)
+
+
+def test_suite():
+ return TestSuite((makeSuite(TestPermissionWidget),))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')