[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testPermissionField.py:1.1

Steve Alexander steve@cat-box.net
Sat, 21 Dec 2002 14:56:37 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv9329/lib/python/Zope/App/Security/tests

Added Files:
	testPermissionField.py 
Log Message:
Added a PermissionField and its associated widgets.
This works like an InterfaceWidget. Use it to select a permission from
those that are available.


=== Added File Zope3/lib/python/Zope/App/Security/tests/testPermissionField.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 fields tests

$Id: testPermissionField.py,v 1.1 2002/12/21 19:56:36 stevea Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.Security.PermissionField import PermissionField
from Zope.Schema.Exceptions import ValidationError
from Zope.App.tests.PlacelessSetup import PlacelessSetup
from Zope.App.Security.Registries.PermissionRegistry import permissionRegistry
from Zope.App.Security.IPermissionService import IPermissionService
from Zope.ComponentArchitecture.GlobalServiceManager \
     import serviceManager, defineService

class TestPermissionField(PlacelessSetup, TestCase):

    def test_validate(self):
        defineService("Permissions", IPermissionService)
        serviceManager.provideService("Permissions", permissionRegistry)

        field = PermissionField()
        self.assertRaises(ValidationError, field.validate, 'read')
        permissionRegistry.definePermission('read', 'Read', 'Read something')
        field.validate('read')

def test_suite():
    return TestSuite((makeSuite(TestPermissionField),))


if __name__=='__main__':
    main(defaultTest='test_suite')