[CMF-checkins] CVS: CMF/CMFSetup/tests - test_rolemap.py:1.2
Tres Seaver
tseaver at zope.com
Tue May 18 16:46:05 EDT 2004
Update of /cvs-repository/CMF/CMFSetup/tests
In directory cvs.zope.org:/tmp/cvs-serv5636/tests
Modified Files:
test_rolemap.py
Log Message:
- Add parseXML to the exporter, and rename to 'RolemapConfigurator' to
reflect that.
=== CMF/CMFSetup/tests/test_rolemap.py 1.1 => 1.2 ===
--- CMF/CMFSetup/tests/test_rolemap.py:1.1 Tue May 18 15:54:56 2004
+++ CMF/CMFSetup/tests/test_rolemap.py Tue May 18 16:46:03 2004
@@ -9,12 +9,12 @@
from Products.CMFSetup.tests.common import BaseRegistryTests
-class RolemapExporterTests( BaseRegistryTests ):
+class RolemapConfiguratorTests( BaseRegistryTests ):
def _getTargetClass( self ):
- from Products.CMFSetup.rolemap import RolemapExporter
- return RolemapExporter
+ from Products.CMFSetup.rolemap import RolemapConfigurator
+ return RolemapConfigurator
def test_listRoles_normal( self ):
@@ -128,6 +128,20 @@
def test_generateEXML_unacquired_perm( self ):
ACI = 'Access contents information'
+ ROLES = [ 'Manager', 'Owner', 'ZZZ' ]
+
+ site = Folder( id='site' ).__of__( self.root )
+ existing_roles = list( getattr( site, '__ac_roles__', [] ) )[:]
+ existing_roles.append( 'ZZZ' )
+ site.__ac_roles__ = existing_roles
+ site.manage_permission( ACI, ROLES )
+ exporter = self._makeOne( site ).__of__( site )
+
+ self._compareDOM( exporter.generateXML(), _COMBINED_EXPORT )
+
+ def test_generateEXML_unacquired_perm_added_role( self ):
+
+ ACI = 'Access contents information'
ROLES = [ 'Manager', 'Owner' ]
site = Folder( id='site' ).__of__( self.root )
@@ -136,6 +150,113 @@
self._compareDOM( exporter.generateXML(), _UNACQUIRED_EXPORT )
+ def test_parseXML_empty( self ):
+
+ self.root.site = Folder( id='site' )
+ site = self.root.site
+ existing_roles = list( getattr( site, '__ac_roles__', [] ) )[:]
+ exporter = self._makeOne( site )
+
+ exporter.parseXML( _EMPTY_EXPORT )
+
+ new_roles = list( getattr( site, '__ac_roles__', [] ) )[:]
+
+ existing_roles.sort()
+ new_roles.sort()
+
+ self.assertEqual( existing_roles, new_roles )
+
+ def test_parseXML_added_role( self ):
+
+ self.root.site = Folder( id='site' )
+ site = self.root.site
+ exporter = self._makeOne( site )
+
+ self.failIf( site._has_user_defined_role( 'ZZZ' ) )
+ exporter.parseXML( _ADDED_ROLE_EXPORT )
+ self.failUnless( site._has_user_defined_role( 'ZZZ' ) )
+
+ def test_parseXML_acquired_permission( self ):
+
+ ACI = 'Access contents information'
+
+ self.root.site = Folder( id='site' )
+ site = self.root.site
+ exporter = self._makeOne( site )
+
+ existing_allowed = [ x[ 'name' ]
+ for x in site.rolesOfPermission( ACI )
+ if x[ 'selected' ] ]
+
+ self.assertEqual( existing_allowed, [ 'Manager' ] )
+
+ self.failUnless( site.acquiredRolesAreUsedBy( ACI ) )
+
+ exporter.parseXML( _ACQUIRED_EXPORT )
+
+ new_allowed = [ x[ 'name' ]
+ for x in site.rolesOfPermission( ACI )
+ if x[ 'selected' ] ]
+
+ self.assertEqual( new_allowed, [ 'Manager', 'Owner' ] )
+
+ self.failUnless( site.acquiredRolesAreUsedBy( ACI ) )
+
+ def test_parseXML_unacquired_permission( self ):
+
+ ACI = 'Access contents information'
+
+ self.root.site = Folder( id='site' )
+ site = self.root.site
+ exporter = self._makeOne( site )
+
+ existing_allowed = [ x[ 'name' ]
+ for x in site.rolesOfPermission( ACI )
+ if x[ 'selected' ] ]
+
+ self.assertEqual( existing_allowed, [ 'Manager' ] )
+
+ self.failUnless( site.acquiredRolesAreUsedBy( ACI ) )
+
+ exporter.parseXML( _UNACQUIRED_EXPORT )
+
+ new_allowed = [ x[ 'name' ]
+ for x in site.rolesOfPermission( ACI )
+ if x[ 'selected' ] ]
+
+ self.assertEqual( new_allowed, [ 'Manager', 'Owner' ] )
+
+ self.failIf( site.acquiredRolesAreUsedBy( ACI ) )
+
+ def test_parseXML_unacquired_permission_added_role( self ):
+
+ ACI = 'Access contents information'
+
+ self.root.site = Folder( id='site' )
+ site = self.root.site
+ exporter = self._makeOne( site )
+
+ existing_allowed = [ x[ 'name' ]
+ for x in site.rolesOfPermission( ACI )
+ if x[ 'selected' ] ]
+
+ self.assertEqual( existing_allowed, [ 'Manager' ] )
+
+ self.failUnless( site.acquiredRolesAreUsedBy( ACI ) )
+
+ self.failIf( site._has_user_defined_role( 'ZZZ' ) )
+ exporter.parseXML( _COMBINED_EXPORT )
+ self.failUnless( site._has_user_defined_role( 'ZZZ' ) )
+
+ new_allowed = [ x[ 'name' ]
+ for x in site.rolesOfPermission( ACI )
+ if x[ 'selected' ] ]
+
+ self.assertEqual( new_allowed, [ 'Manager', 'Owner', 'ZZZ' ] )
+
+ self.failIf( site.acquiredRolesAreUsedBy( ACI ) )
+
+
_EMPTY_EXPORT = """\
<?xml version="1.0"?>
<rolemap>
@@ -199,9 +320,27 @@
</rolemap>
"""
+_COMBINED_EXPORT = """\
+<?xml version="1.0"?>
+<rolemap>
+ <roles>
+ <role name="Anonymous"/>
+ <role name="Authenticated"/>
+ <role name="Manager"/>
+ <role name="Owner"/>
+ <role name="ZZZ"/>
+ </roles>
+ <permissions>
+ <permission name="Access contents information"
+ roles="Manager Owner ZZZ"
+ acquire="False" />
+ </permissions>
+</rolemap>
+"""
+
def test_suite():
return unittest.TestSuite((
- unittest.makeSuite( RolemapExporterTests ),
+ unittest.makeSuite( RolemapConfiguratorTests ),
))
if __name__ == '__main__':
More information about the CMF-checkins
mailing list