Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
GenericSetup.tests.test_tool.SetupToolTests Class Reference
Inheritance diagram for GenericSetup.tests.test_tool.SetupToolTests:
Inheritance graph
[legend]
Collaboration diagram for GenericSetup.tests.test_tool.SetupToolTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def beforeTearDown
def test_empty
def test_getBaselineContextID
def test_setBaselineContext_invalid
def test_setBaselineContext_empty_string
def test_setBaselineContext
def test_runImportStep_nonesuch
def test_runImportStep_simple
def test_runImportStep_dependencies
def test_runImportStep_skip_dependencies
def test_runImportStep_default_purge
def test_runImportStep_explicit_purge
def test_runImportStep_skip_purge
def test_runImportStep_consistent_context
def test_runAllImportSteps_empty
def test_runAllImportSteps_sorted_default_purge
def test_runAllImportSteps_unicode_profile_id_creates_reports
def test_runAllImportSteps_sorted_explicit_purge
def test_runAllImportSteps_sorted_skip_purge
def test_runAllImportStepsFromProfileWithoutDepends
def test_runAllImportStepsFromProfileWithDepends
def test_runAllImportStepsFromProfileStepRegistrationWithDepends
def test_runExportStep_nonesuch
def test_runExportStep_step_registry_empty
def test_runExportStep_step_registry_default
def test_runAllExportSteps_empty
def test_runAllExportSteps_default
def test_runAllExportSteps_extras
def test_createSnapshot_default
def test_applyContext
def test_listContextInfos_empty
def test_listContextInfos_with_snapshot
def test_listContextInfos_with_registered_base_profile
def test_listContextInfos_with_registered_extension_profile
def test_getProfileImportDate_nonesuch
def test_getProfileImportDate_simple_id
def test_getProfileImportDate_id_with_colon
def test_getProfileImportDate_id_with_prefix
def test_profileVersioning
def test_listExportSteps
def test_getSortedImportSteps

Static Public Attributes

 layer = ExportImportZCMLLayer

Private Member Functions

def _getTargetClass
def _makeSite

Private Attributes

 _profile_registry_info
 _profile_registry_ids

Static Private Attributes

string _PROFILE_PATH = '/tmp/STT_test'
string _PROFILE_PATH2 = '/tmp/STT_test2'

Detailed Description

Definition at line 68 of file test_tool.py.


Member Function Documentation

Definition at line 93 of file test_tool.py.

00093 
00094     def _getTargetClass(self):
00095         from Products.GenericSetup.tool import SetupTool
00096 
00097         return SetupTool

def GenericSetup.tests.test_tool.SetupToolTests._makeSite (   self,
  title = "Don't care" 
) [private]

Definition at line 98 of file test_tool.py.

00098 
00099     def _makeSite( self, title="Don't care" ):
00100 
00101         site = Folder()
00102         site._setId( 'site' )
00103         site.title = title
00104 
00105         self.app._setObject( 'site', site )
00106         return self.app._getOb( 'site' )

Here is the caller graph for this function:

Definition at line 75 of file test_tool.py.

00075 
00076     def afterSetUp(self):
00077         self._profile_registry_info = profile_registry._profile_info
00078         self._profile_registry_ids = profile_registry._profile_ids
00079         profile_registry.clear()
00080         global _before_import_events
00081         global _after_import_events
00082         _before_import_events = []
00083         provideHandler(handleBeforeProfileImportEvent)
00084         _after_import_events = []
00085         provideHandler(handleProfileImportedEvent)

Definition at line 86 of file test_tool.py.

00086 
00087     def beforeTearDown(self):
00088         profile_registry._profile_info = self._profile_registry_info
00089         profile_registry._profile_ids = self._profile_registry_ids
00090         base_registry.unregisterHandler(handleBeforeProfileImportEvent)
00091         base_registry.unregisterHandler(handleProfileImportedEvent)
00092         FilesystemTestBase.beforeTearDown(self)

Definition at line 764 of file test_tool.py.

00764 
00765     def test_applyContext(self):
00766         from Products.GenericSetup.tool import IMPORT_STEPS_XML
00767         from Products.GenericSetup.tool import EXPORT_STEPS_XML
00768         from Products.GenericSetup.tool import TOOLSET_XML
00769         from test_registry import _SINGLE_IMPORT_XML
00770         from test_registry import _SINGLE_EXPORT_XML
00771         from test_registry import _NORMAL_TOOLSET_XML
00772         from test_registry import ONE_FUNC
00773 
00774         site = self._makeSite()
00775         tool = self._makeOne('setup_tool').__of__(site)
00776         tool.getImportStepRegistry().clear()
00777         tool.getExportStepRegistry().clear()
00778         tool.getToolsetRegistry().clear()
00779 
00780         context = DummyImportContext( site, tool=tool )
00781         context._files[ IMPORT_STEPS_XML ] = _SINGLE_IMPORT_XML
00782         context._files[ EXPORT_STEPS_XML ] = _SINGLE_EXPORT_XML
00783         context._files[ TOOLSET_XML ] = _NORMAL_TOOLSET_XML
00784 
00785         tool.applyContext(context)
00786 
00787         import_registry = tool.getImportStepRegistry()
00788         self.assertEqual( len( import_registry.listSteps() ), 1 )
00789         self.failUnless( 'one' in import_registry.listSteps() )
00790         info = import_registry.getStepMetadata( 'one' )
00791 
00792         self.assertEqual( info[ 'id' ], 'one' )
00793         self.assertEqual( info[ 'title' ], 'One Step' )
00794         self.assertEqual( info[ 'version' ], '1' )
00795         self.failUnless( 'One small step' in info[ 'description' ] )
00796         self.assertEqual( info[ 'handler' ]
00797                         , 'Products.GenericSetup.tests.test_registry.ONE_FUNC' )
00798 
00799         self.assertEqual( import_registry.getStep( 'one' ), ONE_FUNC )
00800 
00801         export_registry = tool.getExportStepRegistry()
00802         self.assertEqual( len( export_registry.listSteps() ), 1 )
00803         self.failUnless( 'one' in import_registry.listSteps() )
00804         info = export_registry.getStepMetadata( 'one' )
00805         self.assertEqual( info[ 'id' ], 'one' )
00806         self.assertEqual( info[ 'title' ], 'One Step' )
00807         self.failUnless( 'One small step' in info[ 'description' ] )
00808         self.assertEqual( info[ 'handler' ]
00809                         , 'Products.GenericSetup.tests.test_registry.ONE_FUNC' )
00810 
00811         self.assertEqual( export_registry.getStep( 'one' ), ONE_FUNC )

Definition at line 711 of file test_tool.py.

00711 
00712     def test_createSnapshot_default( self ):
00713         _EXPECTED = [('import_steps.xml', _DEFAULT_STEP_REGISTRIES_IMPORT_XML),
00714                      ('export_steps.xml', _DEFAULT_STEP_REGISTRIES_EXPORT_XML),
00715                      ('rolemap.xml', 'dummy'),
00716                      ('toolset.xml', 'dummy'),
00717                      ('componentregistry.xml', 'dummy')]
00718 
00719         site = self._makeSite()
00720         site.setup_tool = self._makeOne('setup_tool')
00721         tool = site.setup_tool
00722         tool._import_registry.registerStep('foo', handler='foo.bar')
00723         tool._export_registry.registerStep('step_registries',
00724                 'Products.GenericSetup.tool.exportStepRegistries',
00725                 'Export import / export steps.')
00726 
00727         self.assertEqual( len( tool.listSnapshotInfo() ), 0 )
00728 
00729         result = tool.createSnapshot( 'default' )
00730 
00731         self.assertEqual( len(result['steps']), 4 )
00732         self.assertEqual( result['steps'][1], 'step_registries' )
00733         self.assertEqual( result[ 'messages' ][ 'step_registries' ]
00734                         , None
00735                         )
00736 
00737         snapshot = result[ 'snapshot' ]
00738 
00739         self.assertEqual( len( snapshot.objectIds() ), len( _EXPECTED ) )
00740 
00741         for id in [ x[0] for x in _EXPECTED ]:
00742             self.failUnless( id in snapshot.objectIds() )
00743 
00744         def normalize_xml(xml):
00745             # using this might mask a real problem on windows, but so far the
00746             # different newlines just caused problems in this test
00747             lines = [ line for line in xml.splitlines() if line ]
00748             return '\n'.join(lines) + '\n'
00749 
00750         fileobj = snapshot._getOb( 'import_steps.xml' )
00751         self.assertEqual( normalize_xml( fileobj.read() ),
00752                           _DEFAULT_STEP_REGISTRIES_IMPORT_XML )
00753 
00754         fileobj = snapshot._getOb( 'export_steps.xml' )
00755         self.assertEqual( normalize_xml( fileobj.read() ),
00756                           _DEFAULT_STEP_REGISTRIES_EXPORT_XML )
00757 
00758         self.assertEqual( len( tool.listSnapshotInfo() ), 1 )
00759 
00760         info = tool.listSnapshotInfo()[ 0 ]
00761 
00762         self.assertEqual( info[ 'id' ], 'default' )
00763         self.assertEqual( info[ 'title' ], 'default' )

Definition at line 107 of file test_tool.py.

00107 
00108     def test_empty( self ):
00109 
00110         tool = self._makeOne('setup_tool')
00111 
00112         self.assertEqual( tool.getBaselineContextID(), '' )
00113 
00114         import_registry = tool.getImportStepRegistry()
00115         self.assertEqual( len( import_registry.listSteps() ), 0 )
00116 
00117         export_registry = tool.getExportStepRegistry()
00118         export_steps = export_registry.listSteps()
00119         self.assertEqual(len(export_steps), 0)
00120 
00121         toolset_registry = tool.getToolsetRegistry()
00122         self.assertEqual( len( toolset_registry.listForbiddenTools() ), 0 )
00123         self.assertEqual( len( toolset_registry.listRequiredTools() ), 0 )

Definition at line 124 of file test_tool.py.

00124 
00125     def test_getBaselineContextID( self ):
00126 
00127         from Products.GenericSetup.tool import IMPORT_STEPS_XML
00128         from Products.GenericSetup.tool import EXPORT_STEPS_XML
00129         from Products.GenericSetup.tool import TOOLSET_XML
00130         from test_registry import _EMPTY_IMPORT_XML
00131         from test_registry import _EMPTY_EXPORT_XML
00132         from test_registry import _EMPTY_TOOLSET_XML
00133 
00134         tool = self._makeOne('setup_tool')
00135 
00136         self._makeFile(IMPORT_STEPS_XML, _EMPTY_IMPORT_XML)
00137         self._makeFile(EXPORT_STEPS_XML, _EMPTY_EXPORT_XML)
00138         self._makeFile(TOOLSET_XML, _EMPTY_TOOLSET_XML)
00139 
00140         profile_registry.registerProfile('foo', 'Foo', '', self._PROFILE_PATH)
00141         tool.setBaselineContext('profile-other:foo')
00142 
00143         self.assertEqual( tool.getBaselineContextID(), 'profile-other:foo' )

Definition at line 875 of file test_tool.py.

00875 
00876     def test_getProfileImportDate_id_with_colon(self):
00877         from OFS.Image import File
00878         site = self._makeSite()
00879         site.setup_tool = self._makeOne('setup_tool')
00880         tool = site.setup_tool
00881         filename = 'import-all-foo_bar-20070315123456.log'
00882         tool._setObject(filename, File(filename, '', ''))
00883         self.assertEqual(tool.getProfileImportDate('foo:bar'),
00884                          '2007-03-15T12:34:56Z')

Definition at line 885 of file test_tool.py.

00885 
00886     def test_getProfileImportDate_id_with_prefix(self):
00887         # Test if getProfileImportDate does not fail if there is another
00888         # item id with id with a longer id which starts with the same
00889         # prefix
00890         from OFS.Image import File
00891         site = self._makeSite()
00892         site.setup_tool = self._makeOne('setup_tool')
00893         tool = site.setup_tool
00894         filename = 'import-all-foo_bar-20070315123456.log'
00895         tool._setObject(filename, File(filename, '', ''))
00896         filename2 = 'import-all-foo_bar-boo-20070315123456.log'
00897         tool._setObject(filename2, File(filename2, '', ''))
00898         self.assertEqual(tool.getProfileImportDate('foo:bar'),
00899                          '2007-03-15T12:34:56Z')

Definition at line 859 of file test_tool.py.

00859 
00860     def test_getProfileImportDate_nonesuch(self):
00861         site = self._makeSite()
00862         site.setup_tool = self._makeOne('setup_tool')
00863         tool = site.setup_tool
00864         self.assertEqual(tool.getProfileImportDate('nonesuch'), None)

Definition at line 865 of file test_tool.py.

00865 
00866     def test_getProfileImportDate_simple_id(self):
00867         from OFS.Image import File
00868         site = self._makeSite()
00869         site.setup_tool = self._makeOne('setup_tool')
00870         tool = site.setup_tool
00871         filename = 'import-all-foo-20070315123456.log'
00872         tool._setObject(filename, File(filename, '', ''))
00873         self.assertEqual(tool.getProfileImportDate('foo'),
00874                          '2007-03-15T12:34:56Z')

Definition at line 971 of file test_tool.py.

00971 
00972     def test_getSortedImportSteps(self):
00973         site = self._makeSite()
00974         site.setup_tool = self._makeOne('setup_tool')
00975         tool = site.setup_tool
00976         result = tool.getSortedImportSteps()
00977         self.assertEqual(len(result), 3)
00978         self.failUnless(u'componentregistry' in result)
00979         self.failUnless(u'rolemap' in result)
00980         self.failUnless(u'toolset' in result)
00981         self.failUnless(list(result).index(u'componentregistry') >
00982                         list(result).index(u'toolset'))
00983 
00984         tool._import_registry.registerStep(u'foo', handler='foo.import')
00985         tool._import_registry.registerStep(u'toolset',
00986                                            handler='toolset.import')
00987         result = tool.getSortedImportSteps()
00988         self.assertEqual(len(result), 4)
00989         self.failUnless(u'componentregistry' in result)
00990         self.failUnless(u'foo' in result)
00991         self.failUnless(u'rolemap' in result)
00992         self.failUnless(u'toolset' in result)
00993         self.failUnless(list(result).index(u'componentregistry') >
00994                         list(result).index(u'toolset'))
00995 

Definition at line 812 of file test_tool.py.

00812 
00813     def test_listContextInfos_empty(self):
00814         site = self._makeSite()
00815         site.setup_tool = self._makeOne('setup_tool')
00816         tool = site.setup_tool
00817         infos = tool.listContextInfos()
00818         self.assertEqual(len(infos), 0)

Definition at line 831 of file test_tool.py.

00831 
00832     def test_listContextInfos_with_registered_base_profile(self):
00833         from Products.GenericSetup.interfaces import BASE
00834         profile_registry.registerProfile('foo', 'Foo', '', self._PROFILE_PATH,
00835                                          'Foo', BASE)
00836         site = self._makeSite()
00837         site.setup_tool = self._makeOne('setup_tool')
00838         tool = site.setup_tool
00839         infos = tool.listContextInfos()
00840         self.assertEqual(len(infos), 1)
00841         info = infos[0]
00842         self.assertEqual(info['id'], 'profile-Foo:foo')
00843         self.assertEqual(info['title'], 'Foo')
00844         self.assertEqual(info['type'], 'base')

Definition at line 845 of file test_tool.py.

00845 
00846     def test_listContextInfos_with_registered_extension_profile(self):
00847         from Products.GenericSetup.interfaces import EXTENSION
00848         profile_registry.registerProfile('foo', 'Foo', '', self._PROFILE_PATH,
00849                                          'Foo', EXTENSION)
00850         site = self._makeSite()
00851         site.setup_tool = self._makeOne('setup_tool')
00852         tool = site.setup_tool
00853         infos = tool.listContextInfos()
00854         self.assertEqual(len(infos), 1)
00855         info = infos[0]
00856         self.assertEqual(info['id'], 'profile-Foo:foo')
00857         self.assertEqual(info['title'], 'Foo')
00858         self.assertEqual(info['type'], 'extension')

Definition at line 819 of file test_tool.py.

00819 
00820     def test_listContextInfos_with_snapshot(self):
00821         site = self._makeSite()
00822         site.setup_tool = self._makeOne('setup_tool')
00823         tool = site.setup_tool
00824         tool.createSnapshot('testing')
00825         infos = tool.listContextInfos()
00826         self.assertEqual(len(infos), 1)
00827         info = infos[0]
00828         self.assertEqual(info['id'], 'snapshot-testing')
00829         self.assertEqual(info['title'], 'testing')
00830         self.assertEqual(info['type'], 'snapshot')

Definition at line 949 of file test_tool.py.

00949 
00950     def test_listExportSteps(self):
00951         site = self._makeSite()
00952         site.setup_tool = self._makeOne('setup_tool')
00953         tool = site.setup_tool
00954         result = tool.listExportSteps()
00955         self.assertEqual(len(result), 4)
00956         self.failUnless(u'componentregistry' in result)
00957         self.failUnless(u'rolemap' in result)
00958         self.failUnless(u'step_registries' in result)
00959         self.failUnless(u'toolset' in result)
00960 
00961         tool._export_registry.registerStep(u'foo', handler='foo.export')
00962         tool._export_registry.registerStep(u'toolset',
00963                                            handler='toolset.export')
00964         result = tool.listExportSteps()
00965         self.assertEqual(len(result), 5)
00966         self.failUnless(u'componentregistry' in result)
00967         self.failUnless(u'foo' in result)
00968         self.failUnless(u'rolemap' in result)
00969         self.failUnless(u'step_registries' in result)
00970         self.failUnless(u'toolset' in result)

Definition at line 900 of file test_tool.py.

00900 
00901     def test_profileVersioning(self):
00902         site = self._makeSite()
00903         site.setup_tool = self._makeOne('setup_tool')
00904         tool = site.setup_tool
00905         profile_id = 'dummy_profile'
00906         product_name = 'GenericSetup'
00907         directory = os.path.split(__file__)[0]
00908         path = os.path.join(directory, 'versioned_profile')
00909 
00910         # register profile
00911         orig_profile_reg = (profile_registry._profile_info.copy(),
00912                             profile_registry._profile_ids[:])
00913         profile_registry.registerProfile(profile_id,
00914                                          'Dummy Profile',
00915                                          'This is a dummy profile',
00916                                          path,
00917                                          product=product_name)
00918 
00919         # register upgrade step
00920         from Products.GenericSetup.upgrade import _upgrade_registry
00921         orig_upgrade_registry = copy.copy(_upgrade_registry._registry)
00922         step = UpgradeStep("Upgrade", "GenericSetup:dummy_profile", '*', '1.1', '',
00923                            dummy_upgrade_handler,
00924                            None, "1")
00925         _registerUpgradeStep(step)
00926 
00927         # test initial states
00928         profile_id = ':'.join((product_name, profile_id))
00929         self.assertEqual(tool.getVersionForProfile(profile_id), '1.1')
00930         self.assertEqual(tool.getLastVersionForProfile(profile_id),
00931                          'unknown')
00932 
00933         # run upgrade steps
00934         request = site.REQUEST
00935         request.form['profile_id'] = profile_id
00936         steps = listUpgradeSteps(tool, profile_id, '1.0')
00937         step_id = steps[0]['id']
00938         request.form['upgrades'] = [step_id]
00939         tool.manage_doUpgrades()
00940         self.assertEqual(tool.getLastVersionForProfile(profile_id),
00941                          ('1', '1'))
00942 
00943         # reset ugprade registry
00944         _upgrade_registry._registry = orig_upgrade_registry
00945 
00946         # reset profile registry
00947         (profile_registry._profile_info,
00948          profile_registry._profile_ids) = orig_profile_reg

Definition at line 632 of file test_tool.py.

00632 
00633     def test_runAllExportSteps_default(self):
00634         site = self._makeSite()
00635         site.setup_tool = self._makeOne('setup_tool')
00636         tool = site.setup_tool
00637         tool._import_registry.registerStep('foo', handler='foo.bar')
00638         tool._export_registry.registerStep('step_registries',
00639                 'Products.GenericSetup.tool.exportStepRegistries',
00640                 'Export import / export steps.')
00641 
00642         result = tool.runAllExportSteps()
00643 
00644         self.assertEqual( len(result['steps']), 4 )
00645         self.assertEqual( result['steps'][1], 'step_registries' )
00646         self.assertEqual( result[ 'messages' ][ 'step_registries' ]
00647                         , None
00648                         )
00649         fileish = StringIO( result[ 'tarball' ] )
00650 
00651         self._verifyTarballContents( fileish, [ 'componentregistry.xml'
00652                                               , 'import_steps.xml'
00653                                               , 'export_steps.xml'
00654                                               , 'rolemap.xml'
00655                                               , 'toolset.xml'
00656                                               ] )
00657         self._verifyTarballEntryXML( fileish, 'import_steps.xml'
00658                                    , _DEFAULT_STEP_REGISTRIES_IMPORT_XML )
00659         self._verifyTarballEntryXML( fileish, 'export_steps.xml'
00660                                    , _DEFAULT_STEP_REGISTRIES_EXPORT_XML )

Definition at line 619 of file test_tool.py.

00619 
00620     def test_runAllExportSteps_empty(self):
00621         site = self._makeSite()
00622         site.setup_tool = self._makeOne('setup_tool')
00623         tool = site.setup_tool
00624 
00625         result = tool.runAllExportSteps()
00626 
00627         self.assertEqual( len(result['steps'] ), 4 )
00628         self.assertEqual( result['steps'][1], 'step_registries' )
00629         self.assertEqual( result[ 'messages' ][ 'step_registries' ]
00630                         , None
00631                         )

Definition at line 661 of file test_tool.py.

00661 
00662     def test_runAllExportSteps_extras( self ):
00663         site = self._makeSite()
00664         site.setup_tool = self._makeOne('setup_tool')
00665         tool = site.setup_tool
00666         tool._export_registry.registerStep('step_registries',
00667                 'Products.GenericSetup.tool.exportStepRegistries',
00668                 'Export import / export steps.')
00669 
00670         import_reg = tool.getImportStepRegistry()
00671         import_reg.registerStep( 'dependable', '1'
00672                                , _underscoreSiteTitle, ( 'purging', ) )
00673         import_reg.registerStep( 'dependent', '1'
00674                                , _uppercaseSiteTitle, ( 'dependable', ) )
00675         import_reg.registerStep( 'purging', '1'
00676                                , _purgeIfRequired )
00677 
00678         export_reg = tool.getExportStepRegistry()
00679         export_reg.registerStep( 'properties'
00680                                , _exportPropertiesINI )
00681 
00682         result = tool.runAllExportSteps()
00683 
00684         self.assertEqual( len(result['steps']), 5 )
00685 
00686         self.failUnless( 'properties' in result[ 'steps' ] )
00687         self.assertEqual( result[ 'messages' ][ 'properties' ]
00688                         , 'Exported properties'
00689                         )
00690 
00691         self.failUnless( 'step_registries' in result[ 'steps' ] )
00692         self.assertEqual( result[ 'messages' ][ 'step_registries' ]
00693                         , None
00694                         )
00695 
00696         fileish = StringIO( result[ 'tarball' ] )
00697 
00698         self._verifyTarballContents( fileish, [ 'componentregistry.xml'
00699                                               , 'import_steps.xml'
00700                                               , 'export_steps.xml'
00701                                               , 'properties.ini'
00702                                               , 'rolemap.xml'
00703                                               , 'toolset.xml'
00704                                               ] )
00705         self._verifyTarballEntryXML( fileish, 'import_steps.xml'
00706                                    , _EXTRAS_STEP_REGISTRIES_IMPORT_XML )
00707         self._verifyTarballEntryXML( fileish, 'export_steps.xml'
00708                                    , _EXTRAS_STEP_REGISTRIES_EXPORT_XML )
00709         self._verifyTarballEntry( fileish, 'properties.ini'
00710                                 , _PROPERTIES_INI % site.title  )

Definition at line 385 of file test_tool.py.

00385 
00386     def test_runAllImportSteps_empty( self ):
00387 
00388         site = self._makeSite()
00389         tool = self._makeOne('setup_tool').__of__( site )
00390 
00391         result = tool.runAllImportStepsFromProfile('snapshot-dummy')
00392 
00393         self.assertEqual( len(result['steps']), 3 )

Definition at line 394 of file test_tool.py.

00394 
00395     def test_runAllImportSteps_sorted_default_purge( self ):
00396 
00397         TITLE = 'original title'
00398         PROFILE_ID = 'snapshot-testing'
00399         site = self._makeSite( TITLE )
00400         tool = self._makeOne('setup_tool').__of__( site )
00401 
00402         registry = tool.getImportStepRegistry()
00403         registry.registerStep( 'dependable', '1'
00404                              , _underscoreSiteTitle, ( 'purging', ) )
00405         registry.registerStep( 'dependent', '1'
00406                              , _uppercaseSiteTitle, ( 'dependable', ) )
00407         registry.registerStep( 'purging', '1'
00408                              , _purgeIfRequired )
00409 
00410         result = tool.runAllImportStepsFromProfile(PROFILE_ID)
00411 
00412         self.assertEqual( len(result['steps']), 6 )
00413 
00414         self.assertEqual( result['steps'][3], 'purging' )
00415         self.assertEqual( result[ 'messages' ][ 'purging' ]
00416                         , 'Purged' )
00417 
00418         self.assertEqual( result['steps'][4], 'dependable' )
00419         self.assertEqual( result[ 'messages' ][ 'dependable' ]
00420                         , 'Underscored title' )
00421 
00422         self.assertEqual( result['steps'][5], 'dependent' )
00423         self.assertEqual( result[ 'messages' ][ 'dependent' ]
00424                         , 'Uppercased title' )
00425 
00426         self.assertEqual( site.title, TITLE.replace( ' ', '_' ).upper() )
00427         self.failUnless( site.purged )
00428 
00429         prefix = 'import-all-%s' % PROFILE_ID
00430         logged = [x for x in tool.objectIds('File') if x.startswith(prefix)]
00431         self.assertEqual(len(logged), 1)

Definition at line 453 of file test_tool.py.

00453 
00454     def test_runAllImportSteps_sorted_explicit_purge( self ):
00455 
00456         site = self._makeSite()
00457         tool = self._makeOne('setup_tool').__of__( site )
00458 
00459         registry = tool.getImportStepRegistry()
00460         registry.registerStep( 'dependable', '1'
00461                              , _underscoreSiteTitle, ( 'purging', ) )
00462         registry.registerStep( 'dependent', '1'
00463                              , _uppercaseSiteTitle, ( 'dependable', ) )
00464         registry.registerStep( 'purging', '1'
00465                              , _purgeIfRequired )
00466 
00467         result = tool.runAllImportStepsFromProfile( 'snapshot-dummy', purge_old=True )
00468 
00469         self.assertEqual( len(result['steps']), 6 )
00470 
00471         self.assertEqual( result['steps'][3], 'purging' )
00472         self.assertEqual( result[ 'messages' ][ 'purging' ]
00473                         , 'Purged' )
00474 
00475         self.assertEqual( result['steps'][4], 'dependable' )
00476         self.assertEqual( result['steps'][5], 'dependent' )
00477         self.failUnless( site.purged )

Definition at line 478 of file test_tool.py.

00478 
00479     def test_runAllImportSteps_sorted_skip_purge( self ):
00480 
00481         site = self._makeSite()
00482         tool = self._makeOne('setup_tool').__of__( site )
00483 
00484         registry = tool.getImportStepRegistry()
00485         registry.registerStep( 'dependable', '1'
00486                              , _underscoreSiteTitle, ( 'purging', ) )
00487         registry.registerStep( 'dependent', '1'
00488                              , _uppercaseSiteTitle, ( 'dependable', ) )
00489         registry.registerStep( 'purging', '1'
00490                              , _purgeIfRequired )
00491 
00492         result = tool.runAllImportStepsFromProfile( 'snapshot-dummy', purge_old=False )
00493 
00494         self.assertEqual( len(result['steps']), 6 )
00495 
00496         self.assertEqual( result['steps'][3], 'purging' )
00497         self.assertEqual( result[ 'messages' ][ 'purging' ]
00498                         , 'Unpurged' )
00499 
00500         self.assertEqual( result['steps'][4], 'dependable' )
00501         self.assertEqual( result['steps'][5], 'dependent' )
00502         self.failIf( site.purged )

Definition at line 432 of file test_tool.py.

00432 
00433     def test_runAllImportSteps_unicode_profile_id_creates_reports( self ):
00434 
00435         TITLE = 'original title'
00436         PROFILE_ID = u'snapshot-testing'
00437         site = self._makeSite( TITLE )
00438         tool = self._makeOne('setup_tool').__of__( site )
00439 
00440         registry = tool.getImportStepRegistry()
00441         registry.registerStep( 'dependable', '1'
00442                              , _underscoreSiteTitle, ( 'purging', ) )
00443         registry.registerStep( 'dependent', '1'
00444                              , _uppercaseSiteTitle, ( 'dependable', ) )
00445         registry.registerStep( 'purging', '1'
00446                              , _purgeIfRequired )
00447 
00448         tool.runAllImportStepsFromProfile(PROFILE_ID)
00449 
00450         prefix = ('import-all-%s' % PROFILE_ID).encode('UTF-8')
00451         logged = [x for x in tool.objectIds('File') if x.startswith(prefix)]
00452         self.assertEqual(len(logged), 1)

Definition at line 542 of file test_tool.py.

00542 
00543     def test_runAllImportStepsFromProfileStepRegistrationWithDepends( self ):
00544         from Products.GenericSetup.metadata import METADATA_XML
00545 
00546         self._makeFile(METADATA_XML, _METADATA_XML)
00547 
00548         _IMPORT_STEPS_XML = """<?xml version="1.0"?>
00549 <import-steps>
00550  <import-step id="one"
00551              version="1"
00552              handler="Products.GenericSetup.tests.common.dummy_handler"
00553              title="One Step">
00554   One small step
00555  </import-step>
00556 </import-steps>
00557 """
00558         self._makeFile('import_steps.xml', _IMPORT_STEPS_XML)
00559 
00560         site = self._makeSite()
00561         tool = self._makeOne('setup_tool').__of__( site )
00562 
00563         profile_registry.registerProfile('foo', 'Foo', '', self._PROFILE_PATH)
00564         profile_registry.registerProfile('bar', 'Bar', '', self._PROFILE_PATH2)
00565 
00566         result = tool.runAllImportStepsFromProfile('profile-other:foo',
00567                                                    ignore_dependencies=False)
00568 
00569         # ensure the additional step on foo was imported
00570         self.failUnless('one' in result['steps'])
00571 
00572 

Definition at line 521 of file test_tool.py.

00521 
00522     def test_runAllImportStepsFromProfileWithDepends( self ):
00523         from Products.GenericSetup.metadata import METADATA_XML
00524 
00525         self._makeFile(METADATA_XML, _METADATA_XML)
00526 
00527         site = self._makeSite()
00528         tool = self._makeOne('setup_tool').__of__( site )
00529 
00530         profile_registry.registerProfile('foo', 'Foo', '', self._PROFILE_PATH)
00531         profile_registry.registerProfile('bar', 'Bar', '', self._PROFILE_PATH2)
00532 
00533         _imported = []
00534         def applyContext(context):
00535             _imported.append(context._profile_path)
00536 
00537         tool.applyContext=applyContext
00538         result = tool.runAllImportStepsFromProfile('profile-other:foo',
00539                                                    ignore_dependencies=False)
00540         self.assertEqual(_imported, [self._PROFILE_PATH2, self._PROFILE_PATH])
00541 

Definition at line 503 of file test_tool.py.

00503 
00504     def test_runAllImportStepsFromProfileWithoutDepends( self ):
00505         from Products.GenericSetup.metadata import METADATA_XML
00506 
00507         self._makeFile(METADATA_XML, _METADATA_XML)
00508 
00509         site = self._makeSite()
00510         tool = self._makeOne('setup_tool').__of__( site )
00511 
00512         profile_registry.registerProfile('foo', 'Foo', '', self._PROFILE_PATH)
00513 
00514         _imported = []
00515         def applyContext(context):
00516             _imported.append(context._profile_path)
00517 
00518         tool.applyContext=applyContext
00519         result = tool.runAllImportStepsFromProfile('profile-other:foo', ignore_dependencies=True)
00520         self.assertEqual(_imported, [self._PROFILE_PATH])

Definition at line 573 of file test_tool.py.

00573 
00574     def test_runExportStep_nonesuch( self ):
00575 
00576         site = self._makeSite()
00577         tool = self._makeOne('setup_tool').__of__( site )
00578 
00579         self.assertRaises( ValueError, tool.runExportStep, 'nonesuch' )

Definition at line 593 of file test_tool.py.

00593 
00594     def test_runExportStep_step_registry_default(self):
00595         site = self._makeSite()
00596         site.setup_tool = self._makeOne('setup_tool')
00597         tool = site.setup_tool
00598         tool._import_registry.registerStep('foo', handler='foo.bar')
00599         tool._export_registry.registerStep('step_registries',
00600                 'Products.GenericSetup.tool.exportStepRegistries',
00601                 'Export import / export steps.')
00602 
00603         result = tool.runExportStep( 'step_registries' )
00604 
00605         self.assertEqual( len( result[ 'steps' ] ), 1 )
00606         self.assertEqual( result[ 'steps' ][ 0 ], 'step_registries' )
00607         self.assertEqual( result[ 'messages' ][ 'step_registries' ]
00608                         , None
00609                         )
00610         fileish = StringIO( result[ 'tarball' ] )
00611 
00612         self._verifyTarballContents( fileish, [ 'import_steps.xml'
00613                                               , 'export_steps.xml'
00614                                               ] )
00615         self._verifyTarballEntryXML( fileish, 'import_steps.xml'
00616                                    , _DEFAULT_STEP_REGISTRIES_IMPORT_XML )
00617         self._verifyTarballEntryXML( fileish, 'export_steps.xml'
00618                                    , _DEFAULT_STEP_REGISTRIES_EXPORT_XML )

Definition at line 580 of file test_tool.py.

00580 
00581     def test_runExportStep_step_registry_empty(self):
00582         site = self._makeSite()
00583         site.setup_tool = self._makeOne('setup_tool')
00584         tool = site.setup_tool
00585 
00586         result = tool.runExportStep( 'step_registries' )
00587 
00588         self.assertEqual( len( result[ 'steps' ] ), 1 )
00589         self.assertEqual( result[ 'steps' ][ 0 ], 'step_registries' )
00590         self.assertEqual( result[ 'messages' ][ 'step_registries' ]
00591                         , None
00592                         )

Definition at line 370 of file test_tool.py.

00370 
00371     def test_runImportStep_consistent_context( self ):
00372 
00373         site = self._makeSite()
00374 
00375         tool = self._makeOne('setup_tool').__of__( site )
00376 
00377         registry = tool.getImportStepRegistry()
00378         registry.registerStep( 'purging', '1', _purgeIfRequired )
00379         registry.registerStep( 'dependent', '1'
00380                              , _uppercaseSiteTitle, ( 'purging', ) )
00381 
00382         result = tool.runImportStepFromProfile( 'snapshot-dummy', 'dependent',
00383                                                 purge_old=False )
00384         self.failIf( site.purged )

Definition at line 323 of file test_tool.py.

00323 
00324     def test_runImportStep_default_purge( self ):
00325 
00326         site = self._makeSite()
00327 
00328         tool = self._makeOne('setup_tool').__of__( site )
00329         registry = tool.getImportStepRegistry()
00330         registry.registerStep( 'purging', '1', _purgeIfRequired )
00331 
00332         result = tool.runImportStepFromProfile( 'snapshot-dummy', 'purging' )
00333 
00334         self.assertEqual( len( result[ 'steps' ] ), 1 )
00335         self.assertEqual( result[ 'steps' ][ 0 ], 'purging' )
00336         self.assertEqual( result[ 'messages' ][ 'purging' ], 'Purged' )
00337         self.failUnless( site.purged )

Definition at line 250 of file test_tool.py.

00250 
00251     def test_runImportStep_dependencies( self ):
00252 
00253         TITLE = 'original title'
00254         site = self._makeSite( TITLE )
00255 
00256         tool = self._makeOne('setup_tool').__of__( site )
00257 
00258         registry = tool.getImportStepRegistry()
00259         registry.registerStep( 'dependable', '1', _underscoreSiteTitle )
00260         registry.registerStep( 'dependent', '1'
00261                              , _uppercaseSiteTitle, ( 'dependable', ) )
00262 
00263         result = tool.runImportStepFromProfile( 'snapshot-dummy', 'dependent' )
00264 
00265         self.assertEqual( len( result[ 'steps' ] ), 2 )
00266 
00267         self.assertEqual( result[ 'steps' ][ 0 ], 'dependable' )
00268         self.assertEqual( result[ 'messages' ][ 'dependable' ]
00269                         , 'Underscored title' )
00270 
00271         self.assertEqual( result[ 'steps' ][ 1 ], 'dependent' )
00272         self.assertEqual( result[ 'messages' ][ 'dependent' ]
00273                         , 'Uppercased title' )
00274         self.assertEqual( site.title, TITLE.replace( ' ', '_' ).upper() )
00275 
00276         global _before_import_events
00277         self.assertEqual( len(_before_import_events), 1)
00278         self.assertEqual(_before_import_events[0].profile_id, 'snapshot-dummy')
00279         self.assertEqual(_before_import_events[0].steps, ['dependable', 'dependent'])
00280         self.assertEqual(_before_import_events[0].full_import, False)
00281 
00282         global _after_import_events
00283         self.assertEqual( len(_after_import_events), 1)
00284         self.assertEqual(_after_import_events[0].profile_id, 'snapshot-dummy')
00285         self.assertEqual(_after_import_events[0].steps, ['dependable', 'dependent'])
00286         self.assertEqual(_after_import_events[0].full_import, False)
00287 

Definition at line 338 of file test_tool.py.

00338 
00339     def test_runImportStep_explicit_purge( self ):
00340 
00341         site = self._makeSite()
00342 
00343         tool = self._makeOne('setup_tool').__of__( site )
00344         registry = tool.getImportStepRegistry()
00345         registry.registerStep( 'purging', '1', _purgeIfRequired )
00346 
00347         result = tool.runImportStepFromProfile( 'snapshot-dummy', 'purging',
00348                                                 purge_old=True )
00349 
00350         self.assertEqual( len( result[ 'steps' ] ), 1 )
00351         self.assertEqual( result[ 'steps' ][ 0 ], 'purging' )
00352         self.assertEqual( result[ 'messages' ][ 'purging' ], 'Purged' )
00353         self.failUnless( site.purged )

Definition at line 209 of file test_tool.py.

00209 
00210     def test_runImportStep_nonesuch( self ):
00211 
00212         site = self._makeSite()
00213 
00214         tool = self._makeOne('setup_tool').__of__( site )
00215 
00216         self.assertRaises( KeyError, tool.runImportStepFromProfile,
00217                            '', 'nonesuch' )

Definition at line 218 of file test_tool.py.

00218 
00219     def test_runImportStep_simple( self ):
00220 
00221         TITLE = 'original title'
00222         site = self._makeSite( TITLE )
00223 
00224         tool = self._makeOne('setup_tool').__of__( site )
00225 
00226         registry = tool.getImportStepRegistry()
00227         registry.registerStep( 'simple', '1', _uppercaseSiteTitle )
00228 
00229         result = tool.runImportStepFromProfile( 'snapshot-dummy', 'simple' )
00230 
00231         self.assertEqual( len( result[ 'steps' ] ), 1 )
00232 
00233         self.assertEqual( result[ 'steps' ][ 0 ], 'simple' )
00234         self.assertEqual( result[ 'messages' ][ 'simple' ]
00235                         , 'Uppercased title' )
00236 
00237         self.assertEqual( site.title, TITLE.upper() )
00238 
00239         global _before_import_events
00240         self.assertEqual( len(_before_import_events), 1)
00241         self.assertEqual(_before_import_events[0].profile_id, 'snapshot-dummy')
00242         self.assertEqual(_before_import_events[0].steps, ['simple'])
00243         self.assertEqual(_before_import_events[0].full_import, False)
00244 
00245         global _after_import_events
00246         self.assertEqual( len(_after_import_events), 1)
00247         self.assertEqual(_after_import_events[0].profile_id, 'snapshot-dummy')
00248         self.assertEqual(_after_import_events[0].steps, ['simple'])
00249         self.assertEqual(_after_import_events[0].full_import, False)

Definition at line 288 of file test_tool.py.

00288 
00289     def test_runImportStep_skip_dependencies( self ):
00290 
00291         TITLE = 'original title'
00292         site = self._makeSite( TITLE )
00293 
00294         tool = self._makeOne('setup_tool').__of__( site )
00295 
00296         registry = tool.getImportStepRegistry()
00297         registry.registerStep( 'dependable', '1', _underscoreSiteTitle )
00298         registry.registerStep( 'dependent', '1'
00299                              , _uppercaseSiteTitle, ( 'dependable', ) )
00300 
00301         result = tool.runImportStepFromProfile( 'snapshot-dummy', 'dependent',
00302                                                 run_dependencies=False )
00303 
00304         self.assertEqual( len( result[ 'steps' ] ), 1 )
00305 
00306         self.assertEqual( result[ 'steps' ][ 0 ], 'dependent' )
00307         self.assertEqual( result[ 'messages' ][ 'dependent' ]
00308                         , 'Uppercased title' )
00309 
00310         self.assertEqual( site.title, TITLE.upper() )
00311 
00312         global _before_import_events
00313         self.assertEqual( len(_before_import_events), 1)
00314         self.assertEqual(_before_import_events[0].profile_id, 'snapshot-dummy')
00315         self.assertEqual(_before_import_events[0].steps, ['dependent'])
00316         self.assertEqual(_before_import_events[0].full_import, False)
00317 
00318         global _after_import_events
00319         self.assertEqual( len(_after_import_events), 1)
00320         self.assertEqual(_after_import_events[0].profile_id, 'snapshot-dummy')
00321         self.assertEqual(_after_import_events[0].steps, ['dependent'])
00322         self.assertEqual(_after_import_events[0].full_import, False)

Definition at line 354 of file test_tool.py.

00354 
00355     def test_runImportStep_skip_purge( self ):
00356 
00357         site = self._makeSite()
00358 
00359         tool = self._makeOne('setup_tool').__of__( site )
00360         registry = tool.getImportStepRegistry()
00361         registry.registerStep( 'purging', '1', _purgeIfRequired )
00362 
00363         result = tool.runImportStepFromProfile( 'snapshot-dummy', 'purging',
00364                                                 purge_old=False )
00365 
00366         self.assertEqual( len( result[ 'steps' ] ), 1 )
00367         self.assertEqual( result[ 'steps' ][ 0 ], 'purging' )
00368         self.assertEqual( result[ 'messages' ][ 'purging' ], 'Unpurged' )
00369         self.failIf( site.purged )

Definition at line 162 of file test_tool.py.

00162 
00163     def test_setBaselineContext( self ):
00164 
00165         from Products.GenericSetup.tool import IMPORT_STEPS_XML
00166         from Products.GenericSetup.tool import EXPORT_STEPS_XML
00167         from Products.GenericSetup.tool import TOOLSET_XML
00168         from test_registry import _SINGLE_IMPORT_XML
00169         from test_registry import _SINGLE_EXPORT_XML
00170         from test_registry import _NORMAL_TOOLSET_XML
00171         from test_registry import ONE_FUNC
00172 
00173         tool = self._makeOne('setup_tool')
00174         tool.getExportStepRegistry().clear()
00175 
00176         self._makeFile(IMPORT_STEPS_XML, _SINGLE_IMPORT_XML)
00177         self._makeFile(EXPORT_STEPS_XML, _SINGLE_EXPORT_XML)
00178         self._makeFile(TOOLSET_XML, _NORMAL_TOOLSET_XML)
00179 
00180         profile_registry.registerProfile('foo', 'Foo', '', self._PROFILE_PATH)
00181         tool.setBaselineContext('profile-other:foo')
00182 
00183         self.assertEqual( tool.getBaselineContextID(), 'profile-other:foo' )
00184 
00185         import_registry = tool.getImportStepRegistry()
00186         self.assertEqual( len( import_registry.listSteps() ), 1 )
00187         self.failUnless( 'one' in import_registry.listSteps() )
00188         info = import_registry.getStepMetadata( 'one' )
00189         self.assertEqual( info[ 'id' ], 'one' )
00190         self.assertEqual( info[ 'title' ], 'One Step' )
00191         self.assertEqual( info[ 'version' ], '1' )
00192         self.failUnless( 'One small step' in info[ 'description' ] )
00193         self.assertEqual( info[ 'handler' ]
00194                         , 'Products.GenericSetup.tests.test_registry.ONE_FUNC')
00195 
00196         self.assertEqual( import_registry.getStep( 'one' ), ONE_FUNC )
00197 
00198         export_registry = tool.getExportStepRegistry()
00199         self.assertEqual( len( export_registry.listSteps() ), 1 )
00200         self.failUnless( 'one' in import_registry.listSteps() )
00201         info = export_registry.getStepMetadata( 'one' )
00202         self.assertEqual( info[ 'id' ], 'one' )
00203         self.assertEqual( info[ 'title' ], 'One Step' )
00204         self.failUnless( 'One small step' in info[ 'description' ] )
00205         self.assertEqual( info[ 'handler' ]
00206                         , 'Products.GenericSetup.tests.test_registry.ONE_FUNC')
00207 
00208         self.assertEqual( export_registry.getStep( 'one' ), ONE_FUNC )

Definition at line 153 of file test_tool.py.

00153 
00154     def test_setBaselineContext_empty_string( self ):
00155 
00156         tool = self._makeOne('setup_tool')
00157 
00158         self.assertRaises( KeyError
00159                          , tool.setBaselineContext
00160                          , ''
00161                          )

Definition at line 144 of file test_tool.py.

00144 
00145     def test_setBaselineContext_invalid( self ):
00146 
00147         tool = self._makeOne('setup_tool')
00148 
00149         self.assertRaises( KeyError
00150                          , tool.setBaselineContext
00151                          , 'profile-foo'
00152                          )


Member Data Documentation

string GenericSetup.tests.test_tool.SetupToolTests._PROFILE_PATH = '/tmp/STT_test' [static, private]

Definition at line 72 of file test_tool.py.

string GenericSetup.tests.test_tool.SetupToolTests._PROFILE_PATH2 = '/tmp/STT_test2' [static, private]

Definition at line 73 of file test_tool.py.

Definition at line 77 of file test_tool.py.

Definition at line 76 of file test_tool.py.

GenericSetup.tests.test_tool.SetupToolTests.layer = ExportImportZCMLLayer [static]

Definition at line 70 of file test_tool.py.


The documentation for this class was generated from the following file: