[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testZope3RoleManagement.py:1.1.2.1 .testinfo:NONE testZopeSecurityPolicy.py:NONE

Tres Seaver tseaver@zope.com
Thu, 29 Nov 2001 11:45:35 -0500


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

Added Files:
      Tag: Zope-3x-branch
	testZope3RoleManagement.py 
Removed Files:
      Tag: Zope-3x-branch
	.testinfo testZopeSecurityPolicy.py 
Log Message:
 - Add initial role management.

=== Added File Zope3/lib/python/Zope/App/Security/tests/testZope3RoleManagement.py ===
# Copyright (c) 2001 Zope Coporation and Contributors.  All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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.

""" Test handler for 'Zope3RoleManager' """

import unittest, sys

from Interface import verify


class Object:
    pass

class ImportTest( unittest.TestCase ):

    def testImport( self ):
        from Zope.App.Security.IRoleManagement import IRoleManagement
        from Zope.App.Security.Zope3RoleManagement import Zope3RoleManagement

        verify( IRoleManagement, Zope3RoleManagement )

class Test( unittest.TestCase ):

    def _makeObject( self ):
        return Object()
        
    def _makeManager( self, for_ ):
        from Zope.App.Security.Zope3RoleManagement import Zope3RoleManagement
        return Zope3RoleManagement( for_ )

    def testEmpty( self ):
        obj = self._makeObject()
        manager = self._makeManager( obj )

        self.assertEquals( id( manager.getContext() ), id( obj ) )

    def testAvailableRoles( self ):
        obj = self._makeObject()
        manager = self._makeManager( obj )

        self.assertEquals( manager.listAvailableRoles(), () )

    def testAddRole( self ):
        obj = self._makeObject()
        manager = self._makeManager( obj )

        manager.addRole( 'Foo' )
        self.assertEquals( manager.listAvailableRoles(), ( 'Foo', ) )
        self.assertRaises( KeyError, manager.addRole, 'Foo' )
        manager.addRole( 'Bar' )
        roles = manager.listAvailableRoles()
        self.failUnless( 'Foo' in roles )
        self.failUnless( 'Bar' in roles )

    def testRemoveRole( self ):
        obj = self._makeObject()
        manager = self._makeManager( obj )

        self.assertRaises( KeyError, manager.removeRole, 'Foo' )
        manager.addRole( 'Foo' )
        manager.addRole( 'Bar' )
        manager.removeRole( 'Foo' )

        roles = manager.listAvailableRoles()
        self.failIf( 'Foo' in roles )
        self.failUnless( 'Bar' in roles )

def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())

=== Removed File Zope3/lib/python/Zope/App/Security/tests/.testinfo ===

=== Removed File Zope3/lib/python/Zope/App/Security/tests/testZopeSecurityPolicy.py ===