[CMF-checkins] CVS: CMF/CMFSetup/tests - common.py:1.1
test_rolemap.py:1.1 test_all.py:1.3 test_registry.py:1.6
Tres Seaver
tseaver at zope.com
Tue May 18 15:55:27 EDT 2004
Update of /cvs-repository/CMF/CMFSetup/tests
In directory cvs.zope.org:/tmp/cvs-serv26621/tests
Modified Files:
test_all.py test_registry.py
Added Files:
common.py test_rolemap.py
Log Message:
- Add exporter for role-permission map, and tests.
=== Added File CMF/CMFSetup/tests/common.py ===
""" CMFSetup product: unit test utilities.
"""
from Products.CMFCore.tests.base.testcase import SecurityRequestTest
class BaseRegistryTests( SecurityRequestTest ):
def _makeOne( self, *args, **kw ):
# Derived classes must implement _getTargetClass
return self._getTargetClass()( *args, **kw )
def _compareDOM( self, found_text, expected_text ):
from xml.dom.minidom import parseString
found = parseString( found_text )
expected = parseString( expected_text )
self.assertEqual( found.toxml(), expected.toxml() )
=== Added File CMF/CMFSetup/tests/test_rolemap.py ===
""" CMFSetup rolemap export / import unit tests
$Id: test_rolemap.py,v 1.1 2004/05/18 19:54:56 tseaver Exp $
"""
import unittest
from OFS.Folder import Folder
from Products.CMFSetup.tests.common import BaseRegistryTests
class RolemapExporterTests( BaseRegistryTests ):
def _getTargetClass( self ):
from Products.CMFSetup.rolemap import RolemapExporter
return RolemapExporter
def test_listRoles_normal( self ):
EXPECTED = [ 'Anonymous', 'Authenticated', 'Manager', 'Owner' ]
self.root.site = Folder( id='site' )
site = self.root.site
exporter = self._makeOne( site )
roles = list( exporter.listRoles() )
self.assertEqual( len( roles ), len( EXPECTED ) )
roles.sort()
for found, expected in zip( roles, EXPECTED ):
self.assertEqual( found, expected )
def test_listRoles_added( self ):
EXPECTED = [ 'Anonymous', 'Authenticated', 'Manager', 'Owner', 'ZZZ' ]
self.root.site = Folder( id='site' )
site = self.root.site
existing_roles = list( getattr( site, '__ac_roles__', [] ) )[:]
existing_roles.append( 'ZZZ' )
site.__ac_roles__ = existing_roles
exporter = self._makeOne( site )
roles = list( exporter.listRoles() )
self.assertEqual( len( roles ), len( EXPECTED ) )
roles.sort()
for found, expected in zip( roles, EXPECTED ):
self.assertEqual( found, expected )
def test_listPermissions_nooverrides( self ):
self.root.site = Folder( id='site' )
site = self.root.site
exporter = self._makeOne( site )
self.assertEqual( len( exporter.listPermissions() ), 0 )
def test_listPermissions_nooverrides( self ):
site = Folder( id='site' ).__of__( self.root )
exporter = self._makeOne( site )
self.assertEqual( len( exporter.listPermissions() ), 0 )
def test_listPermissions_acquire( self ):
ACI = 'Access contents information'
ROLES = [ 'Manager', 'Owner' ]
site = Folder( id='site' ).__of__( self.root )
site.manage_permission( ACI, ROLES, acquire=1 )
exporter = self._makeOne( site )
self.assertEqual( len( exporter.listPermissions() ), 1 )
info = exporter.listPermissions()[ 0 ]
self.assertEqual( info[ 'name' ], ACI )
self.assertEqual( info[ 'roles' ], ROLES )
self.failUnless( info[ 'acquire' ] )
def test_listPermissions_no_acquire( self ):
ACI = 'Access contents information'
ROLES = [ 'Manager', 'Owner' ]
site = Folder( id='site' ).__of__( self.root )
site.manage_permission( ACI, ROLES )
exporter = self._makeOne( site )
self.assertEqual( len( exporter.listPermissions() ), 1 )
info = exporter.listPermissions()[ 0 ]
self.assertEqual( info[ 'name' ], ACI )
self.assertEqual( info[ 'roles' ], ROLES )
self.failIf( info[ 'acquire' ] )
def test_generateXML_empty( self ):
self.root.site = Folder( id='site' )
site = self.root.site
exporter = self._makeOne( site ).__of__( site )
self._compareDOM( exporter.generateXML(), _EMPTY_EXPORT )
def test_generateXML_added_role( self ):
self.root.site = Folder( id='site' )
site = self.root.site
existing_roles = list( getattr( site, '__ac_roles__', [] ) )[:]
existing_roles.append( 'ZZZ' )
site.__ac_roles__ = existing_roles
exporter = self._makeOne( site ).__of__( site )
self._compareDOM( exporter.generateXML(), _ADDED_ROLE_EXPORT )
def test_generateEXML_acquired_perm( self ):
ACI = 'Access contents information'
ROLES = [ 'Manager', 'Owner' ]
site = Folder( id='site' ).__of__( self.root )
site.manage_permission( ACI, ROLES, acquire=1 )
exporter = self._makeOne( site ).__of__( site )
self._compareDOM( exporter.generateXML(), _ACQUIRED_EXPORT )
def test_generateEXML_unacquired_perm( self ):
ACI = 'Access contents information'
ROLES = [ 'Manager', 'Owner' ]
site = Folder( id='site' ).__of__( self.root )
site.manage_permission( ACI, ROLES )
exporter = self._makeOne( site ).__of__( site )
self._compareDOM( exporter.generateXML(), _UNACQUIRED_EXPORT )
_EMPTY_EXPORT = """\
<?xml version="1.0"?>
<rolemap>
<roles>
<role name="Anonymous"/>
<role name="Authenticated"/>
<role name="Manager"/>
<role name="Owner"/>
</roles>
<permissions>
</permissions>
</rolemap>
"""
_ADDED_ROLE_EXPORT = """\
<?xml version="1.0"?>
<rolemap>
<roles>
<role name="Anonymous"/>
<role name="Authenticated"/>
<role name="Manager"/>
<role name="Owner"/>
<role name="ZZZ"/>
</roles>
<permissions>
</permissions>
</rolemap>
"""
_ACQUIRED_EXPORT = """\
<?xml version="1.0"?>
<rolemap>
<roles>
<role name="Anonymous"/>
<role name="Authenticated"/>
<role name="Manager"/>
<role name="Owner"/>
</roles>
<permissions>
<permission name="Access contents information"
roles="Manager Owner"
acquire="True" />
</permissions>
</rolemap>
"""
_UNACQUIRED_EXPORT = """\
<?xml version="1.0"?>
<rolemap>
<roles>
<role name="Anonymous"/>
<role name="Authenticated"/>
<role name="Manager"/>
<role name="Owner"/>
</roles>
<permissions>
<permission name="Access contents information"
roles="Manager Owner"
acquire="False" />
</permissions>
</rolemap>
"""
def test_suite():
return unittest.TestSuite((
unittest.makeSuite( RolemapExporterTests ),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
=== CMF/CMFSetup/tests/test_all.py 1.2 => 1.3 ===
--- CMF/CMFSetup/tests/test_all.py:1.2 Fri May 14 09:22:43 2004
+++ CMF/CMFSetup/tests/test_all.py Tue May 18 15:54:56 2004
@@ -14,6 +14,7 @@
def suite():
return build_test_suite( 'Products.CMFSetup.tests'
, [ 'test_registry'
+ , 'test_rolemap'
, 'test_utils'
]
)
=== CMF/CMFSetup/tests/test_registry.py 1.5 => 1.6 ===
--- CMF/CMFSetup/tests/test_registry.py:1.5 Fri May 14 08:45:29 2004
+++ CMF/CMFSetup/tests/test_registry.py Tue May 18 15:54:56 2004
@@ -5,7 +5,7 @@
import unittest
import os
-from Products.CMFCore.tests.base.testcase import SecurityRequestTest
+from Products.CMFSetup.tests.common import BaseRegistryTests
#==============================================================================
# Dummy handlers
@@ -19,21 +19,6 @@
TWO_FUNC_NAME = '%s.%s' % ( __name__, TWO_FUNC.__name__ )
THREE_FUNC_NAME = '%s.%s' % ( __name__, THREE_FUNC.__name__ )
FOUR_FUNC_NAME = '%s.%s' % ( __name__, FOUR_FUNC.__name__ )
-
-
-class BaseRegistryTests( SecurityRequestTest ):
-
- def _makeOne( self, *args, **kw ):
-
- # Derived classes must implement _getTargetClass
- return self._getTargetClass()( *args, **kw )
-
- def _compareDOM( self, found_text, expected_text ):
-
- from xml.dom.minidom import parseString
- found = parseString( found_text )
- expected = parseString( expected_text )
- self.assertEqual( found.toxml(), expected.toxml() )
#==============================================================================
More information about the CMF-checkins
mailing list