Ejemplo n.º 1
0
    def test_import_updates_registry(self):
        from Products.GenericSetup.tool import TOOLSET_XML
        from Products.GenericSetup.tool import importToolset
        from test_registry import _NORMAL_TOOLSET_XML

        site = self._initSite()
        context = DummyImportContext( site, tool=site.setup_tool )

        # Import forbidden
        context._files[ TOOLSET_XML ] = _FORBIDDEN_TOOLSET_XML
        importToolset( context )

        tool = context.getSetupTool()
        toolset = tool.getToolsetRegistry()

        self.assertEqual( len( toolset.listForbiddenTools() ), 3 )
        self.failUnless( 'doomed' in toolset.listForbiddenTools() )
        self.failUnless( 'damned' in toolset.listForbiddenTools() )
        self.failUnless( 'blasted' in toolset.listForbiddenTools() )

        # Import required
        context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML
        importToolset( context )

        self.assertEqual( len( toolset.listRequiredTools() ), 2 )
        self.failUnless( 'mandatory' in toolset.listRequiredTools() )
        info = toolset.getRequiredToolInfo( 'mandatory' )
        self.assertEqual( info[ 'class' ],
                          'Products.GenericSetup.tests.test_tool.DummyTool' )
        self.failUnless( 'obligatory' in toolset.listRequiredTools() )
        info = toolset.getRequiredToolInfo( 'obligatory' )
        self.assertEqual( info[ 'class' ],
                          'Products.GenericSetup.tests.test_tool.DummyTool' )
Ejemplo n.º 2
0
    def test_forbidden_tools( self ):

        from Products.GenericSetup.tool import TOOLSET_XML
        from Products.GenericSetup.tool import importToolset
        TOOL_IDS = ( 'doomed', 'blasted', 'saved' )

        site = self._initSite()

        for tool_id in TOOL_IDS:
            pseudo = Folder()
            pseudo._setId( tool_id )
            site._setObject( tool_id, pseudo )

        self.assertEqual( len( site.objectIds() ), len( TOOL_IDS ) + 1 )

        for tool_id in TOOL_IDS:
            self.failUnless( tool_id in site.objectIds() )

        context = DummyImportContext( site, tool=site.setup_tool )
        context._files[ TOOLSET_XML ] = _FORBIDDEN_TOOLSET_XML

        importToolset( context )

        self.assertEqual( len( site.objectIds() ), 2 )
        self.failUnless( 'setup_tool' in site.objectIds() )
        self.failUnless( 'saved' in site.objectIds() )
Ejemplo n.º 3
0
    def test_required_tools_with_replacement( self ):

        from Products.GenericSetup.tool import TOOLSET_XML
        from Products.GenericSetup.tool import importToolset

        site = self._initSite()

        mandatory = AnotherDummyTool()
        mandatory._setId( 'mandatory' )
        site._setObject( 'mandatory', mandatory )

        obligatory = AnotherDummyTool()
        obligatory._setId( 'obligatory' )
        site._setObject( 'obligatory', obligatory )

        self.assertEqual( len( site.objectIds() ), 3 )

        context = DummyImportContext( site, tool=site.setup_tool )
        context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML

        importToolset( context )

        self.assertEqual( len( site.objectIds() ), 3 )

        self.failIf( aq_base( site._getOb( 'mandatory' ) ) is mandatory )
        self.failUnless( isinstance( aq_base( site._getOb( 'mandatory' ) )
                                   , DummyTool ) )

        self.failIf( aq_base( site._getOb( 'obligatory' ) ) is obligatory )
        self.failUnless( isinstance( aq_base( site._getOb( 'obligatory' ) )
                                   , DummyTool ) )
Ejemplo n.º 4
0
    def test_required_tools_missing_acquired_nofail( self ):

        from Products.GenericSetup.tool import TOOLSET_XML
        from Products.GenericSetup.tool import importToolset

        site = self._initSite()
        parent_site = Folder()

        mandatory = AnotherDummyTool()
        mandatory._setId( 'mandatory' )
        parent_site._setObject( 'mandatory', mandatory )

        obligatory = AnotherDummyTool()
        obligatory._setId( 'obligatory' )
        parent_site._setObject( 'obligatory', obligatory )

        site = site.__of__(parent_site)

        # acquiring subobjects of a different class during import
        # should not prevent new objects from being created if they
        # don't exist in the site

        context = DummyImportContext( site, tool=site.setup_tool )
        context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML

        importToolset( context )

        self.failIf( aq_base( site._getOb( 'mandatory' ) ) is mandatory )
        self.failUnless( isinstance( aq_base( site._getOb( 'mandatory' ) )
                                   , DummyTool ) )

        self.failIf( aq_base( site._getOb( 'obligatory' ) ) is obligatory )
        self.failUnless( isinstance( aq_base( site._getOb( 'obligatory' ) )
                                   , DummyTool ) )
Ejemplo n.º 5
0
    def test_required_tools_no_replacement( self ):

        from Products.CMFSetup.tool import TOOLSET_XML
        from Products.CMFSetup.tool import importToolset

        site = self._initSite()

        mandatory = DummyTool()
        mandatory._setId( 'mandatory' )
        site._setObject( 'mandatory', mandatory )

        obligatory = DummyTool()
        obligatory._setId( 'obligatory' )
        site._setObject( 'obligatory', obligatory )

        self.assertEqual( len( site.objectIds() ), 3 )

        context = DummyImportContext( site )
        context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML

        importToolset( context )

        self.assertEqual( len( site.objectIds() ), 3 )
        self.failUnless( aq_base( site._getOb( 'mandatory' ) ) is mandatory )
        self.failUnless( aq_base( site._getOb( 'obligatory' ) ) is obligatory )
Ejemplo n.º 6
0
    def test_applyContext(self):
        from Products.GenericSetup.tool import IMPORT_STEPS_XML
        from Products.GenericSetup.tool import EXPORT_STEPS_XML
        from Products.GenericSetup.tool import TOOLSET_XML
        from test_registry import _SINGLE_IMPORT_XML
        from test_registry import _SINGLE_EXPORT_XML
        from test_registry import _NORMAL_TOOLSET_XML
        from test_registry import ONE_FUNC

        site = self._makeSite()
        tool = self._makeOne('setup_tool').__of__(site)
        tool.getImportStepRegistry().clear()
        tool.getExportStepRegistry().clear()
        tool.getToolsetRegistry().clear()

        context = DummyImportContext( site, tool=tool )
        context._files[ IMPORT_STEPS_XML ] = _SINGLE_IMPORT_XML
        context._files[ EXPORT_STEPS_XML ] = _SINGLE_EXPORT_XML
        context._files[ TOOLSET_XML ] = _NORMAL_TOOLSET_XML

        tool.applyContext(context)

        import_registry = tool.getImportStepRegistry()
        self.assertEqual( len( import_registry.listSteps() ), 1 )
        self.failUnless( 'one' in import_registry.listSteps() )
        info = import_registry.getStepMetadata( 'one' )
        self.assertEqual( info[ 'id' ], 'one' )
        self.assertEqual( info[ 'title' ], 'One Step' )
        self.assertEqual( info[ 'version' ], '1' )
        self.failUnless( 'One small step' in info[ 'description' ] )
        self.assertEqual( info[ 'handler' ]
                        , 'Products.GenericSetup.tests.test_registry.ONE_FUNC' )

        self.assertEqual( import_registry.getStep( 'one' ), ONE_FUNC )

        export_registry = tool.getExportStepRegistry()
        self.assertEqual( len( export_registry.listSteps() ), 1 )
        self.failUnless( 'one' in import_registry.listSteps() )
        info = export_registry.getStepMetadata( 'one' )
        self.assertEqual( info[ 'id' ], 'one' )
        self.assertEqual( info[ 'title' ], 'One Step' )
        self.failUnless( 'One small step' in info[ 'description' ] )
        self.assertEqual( info[ 'handler' ]
                        , 'Products.GenericSetup.tests.test_registry.ONE_FUNC' )

        self.assertEqual( export_registry.getStep( 'one' ), ONE_FUNC )

        toolset = tool.getToolsetRegistry()
        self.assertEqual( len( toolset.listForbiddenTools() ), 1 )
        self.failUnless( 'doomed' in toolset.listForbiddenTools() )
        self.assertEqual( len( toolset.listRequiredTools() ), 2 )
        self.failUnless( 'mandatory' in toolset.listRequiredTools() )
        info = toolset.getRequiredToolInfo( 'mandatory' )
        self.assertEqual( info[ 'class' ], 'path.to.one' )
        self.failUnless( 'obligatory' in toolset.listRequiredTools() )
        info = toolset.getRequiredToolInfo( 'obligatory' )
        self.assertEqual( info[ 'class' ], 'path.to.another' )
Ejemplo n.º 7
0
    def test_tool_id_required(self):
        # Tests that tool creation will still work when an id is required
        # by the tool constructor.
        from Products.GenericSetup.tool import TOOLSET_XML
        from Products.GenericSetup.tool import importToolset

        site = self._initSite()
        context = DummyImportContext( site, tool=site.setup_tool )
        context._files[ TOOLSET_XML ] = _WITH_ID_TOOLSET_XML

        importToolset( context )

        for tool_id in ( 'mandatory', 'requires_id' ):
            tool = getattr( site, tool_id )
            self.assertEqual( tool.getId(), tool_id )
Ejemplo n.º 8
0
    def test_tool_ids( self ):
        # The tool import mechanism used to rely on the fact that all tools
        # have unique IDs set at the class level and that you can call their
        # constructor with no arguments. However, there might be tools
        # that need IDs set.
        from Products.GenericSetup.tool import TOOLSET_XML
        from Products.GenericSetup.tool import importToolset

        site = self._initSite()
        context = DummyImportContext( site, tool=site.setup_tool )
        context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML

        importToolset( context )

        for tool_id in ( 'mandatory', 'obligatory' ):
            tool = getattr( site, tool_id )
            self.assertEqual( tool.getId(), tool_id )
Ejemplo n.º 9
0
    def test_required_tools_missing( self ):

        from Products.GenericSetup.tool import TOOLSET_XML
        from Products.GenericSetup.tool import importToolset

        site = self._initSite()
        self.assertEqual( len( site.objectIds() ), 1 )

        context = DummyImportContext( site, tool=site.setup_tool )
        context._files[ TOOLSET_XML ] = _REQUIRED_TOOLSET_XML

        importToolset( context )

        self.assertEqual( len( site.objectIds() ), 3 )
        self.failUnless( isinstance( aq_base( site._getOb( 'mandatory' ) )
                                   , DummyTool ) )
        self.failUnless( isinstance( aq_base( site._getOb( 'obligatory' ) )
                                   , DummyTool ) )
Ejemplo n.º 10
0
    def test_unacquired_permission_added_role_explicit_purge( self ):

        ACI = 'Access contents information'
        VIEW = 'View'

        self.root.site = Folder( id='site' )
        site = self.root.site
        site.manage_permission( VIEW, () )

        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.acquiredRolesAreUsedBy( VIEW ) )

        self.failIf( site._has_user_defined_role( 'ZZZ' ) )

        context = DummyImportContext( site, True )
        context._files[ 'rolemap.xml' ] = _COMBINED_EXPORT

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap( context )

        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 ) )
        self.failUnless( site.acquiredRolesAreUsedBy( VIEW ) )
Ejemplo n.º 11
0
    def test_normal_encode_as_ascii(self):

        site = self._initSite(1, 1)
        atool = site.portal_actions
        foo = site.portal_foo
        bar = site.portal_bar

        context = DummyImportContext(site, encoding='ascii')
        context._files['actions.xml'] = _NORMAL_EXPORT

        from Products.CMFSetup.actions import importActionProviders
        importActionProviders(context)

        self.assertEqual(len(atool.listActionProviders()), 1)
        self.failIf('portal_foo' in atool.listActionProviders())
        self.failUnless('portal_actions' in atool.listActionProviders())

        self.assertEqual(len(atool.objectIds()), 1)
        self.failUnless('dummy' in atool.objectIds())
        self.assertEqual(len(atool.dummy.objectIds()), 2)
        self.failUnless('foo' in atool.dummy.objectIds())
        self.failUnless('bar' in atool.dummy.objectIds())
        self.failIf(foo.listActions())
        self.failIf(bar.listActions())