本文整理汇总了Python中common.DummyImportContext类的典型用法代码示例。如果您正苦于以下问题:Python DummyImportContext类的具体用法?Python DummyImportContext怎么用?Python DummyImportContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DummyImportContext类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_import_updates_registry
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' )
示例2: test_forbidden_tools
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() )
示例3: test_required_tools_missing_acquired_nofail
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 ) )
示例4: test_required_tools_with_replacement
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 ) )
示例5: test_required_tools_no_replacement
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 )
示例6: test_applyContext
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' )
示例7: test_tool_id_required
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 )
示例8: test_tool_ids
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 )
示例9: test_required_tools_missing
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 ) )