[Zope3-checkins] CVS: Zope3/src/zope/app/browser/security/tests - __init__.py:1.1.2.1 test_permissionwidget.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 23 Dec 2002 14:31:13 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/security/tests
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/browser/security/tests
Added Files:
Tag: NameGeddon-branch
__init__.py test_permissionwidget.py
Log Message:
Initial renaming before debugging
=== Added File Zope3/src/zope/app/browser/security/tests/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/app/browser/security/tests/test_permissionwidget.py ===
##############################################################################
#
# 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: test_permissionwidget.py,v 1.1.2.1 2002/12/23 19:31:11 jim Exp $
"""
__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="'
'Zope.Public'
'">'
'Zope.Public'
'</option>'
'<option value="'
'read'
'">'
'read'
'</option>'
'<option value="'
'reread'
'">'
'reread'
'</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="'
'Zope.Public'
'">'
'Zope.Public'
'</option>'
'<option value="'
'read'
'" selected>'
'read'
'</option>'
'<option value="'
'reread'
'">'
'reread'
'</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')