[CMF-checkins] CVS: CMF/CMFSetup/tests - common.py:1.2
test_context.py:1.2 test_tool.py:1.2
Tres Seaver
tseaver at zope.com
Sun May 23 16:32:14 EDT 2004
Update of /cvs-repository/CMF/CMFSetup/tests
In directory cvs.zope.org:/tmp/cvs-serv14985/tests
Modified Files:
common.py test_context.py test_tool.py
Log Message:
- interfaces.py:
o Add API for updating / requesting the profile directory of the tool,
and the product (if any) to which it is relative.
o Add accessors to get tool's import and export step registries.
- tool.py:
o Create empty import / export step registries in __init__.
o Implement the new profile directory APIs.
o Implement the new registry accessors.
o Load registries from XML files in profile directory when it is
updated.
=== CMF/CMFSetup/tests/common.py 1.1 => 1.2 ===
--- CMF/CMFSetup/tests/common.py:1.1 Tue May 18 15:54:56 2004
+++ CMF/CMFSetup/tests/common.py Sun May 23 16:31:43 2004
@@ -1,5 +1,7 @@
""" CMFSetup product: unit test utilities.
"""
+import os
+import shutil
from Products.CMFCore.tests.base.testcase import SecurityRequestTest
@@ -17,3 +19,52 @@
found = parseString( found_text )
expected = parseString( expected_text )
self.assertEqual( found.toxml(), expected.toxml() )
+
+def _clearTestDirectory( root_path ):
+
+ if os.path.exists( root_path ):
+ shutil.rmtree( root_path )
+
+def _makeTestFile( filename, root_path, contents ):
+
+ path, filename = os.path.split( filename )
+
+ subdir = os.path.join( root_path, path )
+
+ if not os.path.exists( subdir ):
+ os.makedirs( subdir )
+
+ fqpath = os.path.join( subdir, filename )
+
+ file = open( fqpath, 'w' )
+ file.write( contents )
+ file.close()
+ return fqpath
+
+class TestBase( SecurityRequestTest ):
+
+ def _makeOne( self, *args, **kw ):
+
+ return self._getTargetClass()( *args, **kw )
+
+ def setUp( self ):
+
+ SecurityRequestTest.setUp( self )
+ self._clearTempDir()
+
+ def tearDown( self ):
+
+ self._clearTempDir()
+ SecurityRequestTest.tearDown( self )
+
+ def _clearTempDir( self ):
+
+ _clearTestDirectory( self._PROFILE_PATH )
+
+ def _makeFile( self, filename, contents ):
+
+ return _makeTestFile( filename, self._PROFILE_PATH, contents )
+
+def dummy_handler( context ):
+
+ pass
=== CMF/CMFSetup/tests/test_context.py 1.1 => 1.2 ===
--- CMF/CMFSetup/tests/test_context.py:1.1 Fri May 21 17:12:40 2004
+++ CMF/CMFSetup/tests/test_context.py Sun May 23 16:31:43 2004
@@ -5,56 +5,20 @@
import unittest
import os
-import shutil
from OFS.Folder import Folder
from Products.CMFCore.tests.base.testcase import SecurityRequestTest
+from common import TestBase
from conformance import ConformsToISetupContext
from conformance import ConformsToIImportContext
from conformance import ConformsToIExportContext
+
class DummySite( Folder ):
pass
-
-class TestBase( SecurityRequestTest ):
-
- def _makeOne( self, *args, **kw ):
-
- return self._getTargetClass()( *args, **kw )
-
- def setUp( self ):
-
- SecurityRequestTest.setUp( self )
- self._clearTempDir()
-
- def tearDown( self ):
-
- self._clearTempDir()
- SecurityRequestTest.tearDown( self )
-
- def _clearTempDir( self ):
-
- if os.path.exists( self._PROFILE_PATH ):
- shutil.rmtree( self._PROFILE_PATH )
-
- def _makeFile( self, filename, contents ):
-
- path, filename = os.path.split( filename )
-
- subdir = os.path.join( self._PROFILE_PATH, path )
-
- if not os.path.exists( subdir ):
- os.makedirs( subdir )
-
- fqpath = os.path.join( subdir, filename )
-
- file = open( fqpath, 'w' )
- file.write( contents )
- file.close()
- return fqpath
class ImportContextTests( TestBase
, ConformsToISetupContext
=== CMF/CMFSetup/tests/test_tool.py 1.1 => 1.2 ===
--- CMF/CMFSetup/tests/test_tool.py:1.1 Sun May 23 14:57:39 2004
+++ CMF/CMFSetup/tests/test_tool.py Sun May 23 16:31:43 2004
@@ -4,15 +4,17 @@
"""
import unittest
+import os
-from Products.CMFCore.tests.base.testcase import SecurityRequestTest
-
+from common import TestBase
from conformance import ConformsToISetupTool
-class SetupToolTests( SecurityRequestTest
+class SetupToolTests( TestBase
, ConformsToISetupTool
):
+ _PROFILE_PATH = '/tmp/STT_test'
+
def _getTargetClass( self ):
from Products.CMFSetup.tool import SetupTool
@@ -25,6 +27,154 @@
def test_empty( self ):
tool = self._makeOne()
+
+ self.assertEqual( tool.getProfileProduct(), None )
+ self.assertEqual( tool.getProfileDirectory(), None )
+
+ import_registry = tool.getImportStepRegistry()
+ self.assertEqual( len( import_registry.listSteps() ), 0 )
+
+ export_registry = tool.getExportStepRegistry()
+ self.assertEqual( len( export_registry.listSteps() ), 0 )
+
+ def test_getProfileDirectory_relative_no_product( self ):
+
+ from test_registry import _EMPTY_IMPORT_XML
+ from test_registry import _EMPTY_EXPORT_XML
+ from common import _makeTestFile
+
+ tool = self._makeOne()
+
+ _makeTestFile( tool.IMPORT_STEPS_XML
+ , self._PROFILE_PATH
+ , _EMPTY_IMPORT_XML
+ )
+
+ _makeTestFile( tool.EXPORT_STEPS_XML
+ , self._PROFILE_PATH
+ , _EMPTY_EXPORT_XML
+ )
+
+ tool.setProfileDirectory( self._PROFILE_PATH )
+
+ self.assertRaises( ValueError, tool.getProfileDirectory, True )
+
+ def test_setProfileDirectory_absolute_invalid( self ):
+
+ tool = self._makeOne()
+
+ self.assertRaises( ValueError
+ , tool.setProfileDirectory
+ , self._PROFILE_PATH
+ )
+
+ def test_setProfileDirectory_absolute( self ):
+
+ from test_registry import _SINGLE_IMPORT_XML
+ from test_registry import _SINGLE_EXPORT_XML
+ from test_registry import ONE_FUNC
+ from common import _makeTestFile
+
+ tool = self._makeOne()
+
+ _makeTestFile( tool.IMPORT_STEPS_XML
+ , self._PROFILE_PATH
+ , _SINGLE_IMPORT_XML
+ )
+
+ _makeTestFile( tool.EXPORT_STEPS_XML
+ , self._PROFILE_PATH
+ , _SINGLE_EXPORT_XML
+ )
+
+ tool.setProfileDirectory( self._PROFILE_PATH )
+
+ self.assertEqual( tool.getProfileProduct(), None )
+ self.assertEqual( tool.getProfileDirectory(), self._PROFILE_PATH )
+
+ 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.CMFSetup.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.CMFSetup.tests.test_registry.ONE_FUNC' )
+
+ self.assertEqual( export_registry.getStep( 'one' ), ONE_FUNC )
+
+ def test_setProfileDirectory_relative_invalid( self ):
+
+ _PATH = 'tests/nonesuch'
+
+ tool = self._makeOne()
+
+ self.assertRaises( ValueError
+ , tool.setProfileDirectory
+ , _PATH
+ , 'CMFSetup'
+ )
+
+ def test_setProfileDirectory_relative( self ):
+
+ import Products.CMFSetup
+ from common import dummy_handler
+
+ _PATH = 'tests/default_profile'
+ _PRODUCT_PATH = os.path.split( Products.CMFSetup.__file__ )[0]
+ _FQPATH = os.path.join( _PRODUCT_PATH, _PATH )
+
+ tool = self._makeOne()
+ tool.setProfileDirectory( _PATH, 'CMFSetup' )
+
+ self.assertEqual( tool.getProfileProduct(), 'CMFSetup' )
+ self.assertEqual( tool.getProfileDirectory(), _FQPATH )
+ self.assertEqual( tool.getProfileDirectory( True ), _PATH )
+
+ 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.CMFSetup.tests.common.dummy_handler' )
+ self.assertEqual( import_registry.getStep( 'one' ), dummy_handler )
+
+ 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.CMFSetup.tests.common.dummy_handler' )
+ self.assertEqual( export_registry.getStep( 'one' ), dummy_handler )
+
+ def test_setProfileDirectory_relative_invalid_product( self ):
+
+ _PATH = 'tests/default_profile'
+ tool = self._makeOne()
+
+ self.assertRaises( ValueError
+ , tool.setProfileDirectory, _PATH, 'NonesuchProduct' )
def test_suite():
More information about the CMF-checkins
mailing list