[CMF-checkins] CVS: CMF/CMFCore/tests - test_FSSecurity.py:1.3.4.2 test_FSPythonScript.py:1.3.20.1 test_FSPageTemplate.py:1.7.4.1 test_FSImage.py:1.4.10.1 test_DirectoryView.py:1.9.4.3

Chris Withers chrisw@nipltd.com
Mon, 19 Aug 2002 08:41:05 -0400


Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv13298/CMFCore/tests

Modified Files:
      Tag: chrisw-dirview-branch
	test_FSSecurity.py test_FSPythonScript.py 
	test_FSPageTemplate.py test_FSImage.py test_DirectoryView.py 
Log Message:
Restructrue tests involving FSDV to work on a copy in the tempfile space. Also comment out tests for FSDV paths for now.

=== CMF/CMFCore/tests/test_FSSecurity.py 1.3.4.1 => 1.3.4.2 ===
--- CMF/CMFCore/tests/test_FSSecurity.py:1.3.4.1	Mon Aug 12 08:16:11 2002
+++ CMF/CMFCore/tests/test_FSSecurity.py	Mon Aug 19 08:41:04 2002
@@ -6,22 +6,11 @@
 
 from AccessControl.Permission import Permission
 from Products.CMFCore.tests.base.testcase import RequestTest
+from Products.CMFCore.tests.base.testcase import FSDVTest
 
-#
-# XXX: 2002/08/12:  Tests shouldn't depend on one another;  common
-#       stuff like this should be factored out into a utilty module.
-#
-from test_DirectoryView import _registerDirectory
-from test_DirectoryView import _prefix
-
-#
-# XXX: 2002/08/12:  don't write to the filesystem (see test_DirectoryView)
-#
-from test_DirectoryView import _writeFile
-from test_DirectoryView import _deleteFile
 from Globals import DevelopmentMode
 
-class FSSecurityBase( RequestTest ):
+class FSSecurityBase( RequestTest, FSDVTest ):
 
     def _checkSettings(self,object,permissionname,acquire=0,roles=[]):
         # check the roles and acquire settings for a permission on an
@@ -46,7 +35,8 @@
             
     def setUp( self ):
         # initialise skins
-        _registerDirectory(self)
+        FSDVTest.setUp(self)
+        self._registerDirectory(self)
         # set up ZODB
         RequestTest.setUp(self)
         # put object in ZODB
@@ -56,11 +46,8 @@
         root._setObject( 'fake_skin', self.ob.fake_skin )
 
     def tearDown( self ):
-        try:
-            _deleteFile('test5.py.security')
-        except:
-            pass
         RequestTest.tearDown(self)
+        FSDVTest.tearDown(self)
         
 class FSSecurityTests( FSSecurityBase ):
 
@@ -77,7 +64,7 @@
         # baseline
         self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
         # add .rpm with dodgy permission name
-        _writeFile('test5.py.security','Access stoopid contents::')
+        self._writeFile('test5.py.security','Access stoopid contents::')
         # check baseline
         self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
         
@@ -86,7 +73,7 @@
         # baseline
         self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
         # add dodgy .rpm
-        _writeFile('test5.py.security','View:aquire:')
+        self._writeFile('test5.py.security','View:aquire:')
         # check baseline
         self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
 
@@ -99,7 +86,7 @@
             # baseline
             self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
             # add
-            _writeFile('test5.py.security','View:acquire:Manager')
+            self._writeFile('test5.py.security','View:acquire:Manager')
             # test            
             self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
 
@@ -107,20 +94,20 @@
             """ Test deleting of a .security """
             # baseline
             self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
-            _writeFile('test5.py.security','View:acquire:Manager')
+            self._writeFile('test5.py.security','View:acquire:Manager')
             self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
             # delete
-            _deleteFile('test5.py.security')
+            self._deleteFile('test5.py.security')
             # test
             self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
 
         def test_editPRM( self ):
             """ Test editing a .security """
             # baseline
-            _writeFile('test5.py.security','View::Manager,Anonymous')
+            self._writeFile('test5.py.security','View::Manager,Anonymous')
             self._checkSettings(self.ob.fake_skin.test5,'View',0,['Manager','Anonymous'])           
             # edit
-            _writeFile('test5.py.security','View:acquire:Manager')
+            self._writeFile('test5.py.security','View:acquire:Manager')
             # test
             self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
 
@@ -128,15 +115,15 @@
         def test_DelAddEditPRM( self ):
             """ Test deleting, then adding, then editing a .security file """
             # baseline
-            _writeFile('test5.py.security','View::Manager')
+            self._writeFile('test5.py.security','View::Manager')
             # delete
-            _deleteFile('test5.py.security')
+            self._deleteFile('test5.py.security')
             self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
             # add back
-            _writeFile('test5.py.security','View::Manager,Anonymous')
+            self._writeFile('test5.py.security','View::Manager,Anonymous')
             self._checkSettings(self.ob.fake_skin.test5,'View',0,['Manager','Anonymous'])
             # edit
-            _writeFile('test5.py.security','View:acquire:Manager')
+            self._writeFile('test5.py.security','View:acquire:Manager')
             # test
             self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
 


=== CMF/CMFCore/tests/test_FSPythonScript.py 1.3 => 1.3.20.1 ===
--- CMF/CMFCore/tests/test_FSPythonScript.py:1.3	Fri Feb 15 14:45:33 2002
+++ CMF/CMFCore/tests/test_FSPythonScript.py	Mon Aug 19 08:41:04 2002
@@ -1,16 +1,14 @@
 import Zope
 from unittest import TestCase, TestSuite, makeSuite, main
 from Products.CMFCore.FSPythonScript import FSPythonScript
-from test_DirectoryView import skin_path_name
+from Products.CMFCore.tests.base.testcase import FSDVTest
 from os.path import join
 
-script_path = join(skin_path_name,'test1.py')
-
-class FSPythonScriptTests( TestCase ):
+class FSPythonScriptTests( FSDVTest ):
 
     def test_GetSize( self ):
         """ Test get_size returns correct value """
-        script = FSPythonScript('test1', script_path)
+        script = FSPythonScript('test1', join(self.skin_path_name,'test1.py'))
         self.assertEqual(len(script.read()),script.get_size())
 
 def test_suite():


=== CMF/CMFCore/tests/test_FSPageTemplate.py 1.7 => 1.7.4.1 ===
--- CMF/CMFCore/tests/test_FSPageTemplate.py:1.7	Wed Jul 31 17:52:32 2002
+++ CMF/CMFCore/tests/test_FSPageTemplate.py	Mon Aug 19 08:41:04 2002
@@ -5,20 +5,27 @@
     def getHTTPCachingHeaders( self, content, view_name, keywords, time=None ):
         return ( ( 'foo', 'Foo' ), ( 'bar', 'Bar' ) )
 
-from Products.CMFCore.tests.base.testcase import RequestTest, SecurityTest
+from Products.CMFCore.tests.base.testcase import RequestTest, SecurityTest, FSDVTest
 
-class FSPTMaker:
+class FSPTMaker(FSDVTest):
 
     def _makeOne( self, id, filename ):
 
         from Products.CMFCore.FSPageTemplate import FSPageTemplate
-        from Products.CMFCore.tests.test_DirectoryView import skin_path_name
         from os.path import join
 
-        return FSPageTemplate( id, join( skin_path_name, filename ) )
+        return FSPageTemplate( id, join( self.skin_path_name, filename ) )
 
 class FSPageTemplateTests( RequestTest, FSPTMaker ):
 
+    def setUp(self):
+        FSPTMaker.setUp(self)
+        RequestTest.setUp(self)
+    
+    def tearDown(self):
+        RequestTest.tearDown(self)
+        FSPTMaker.tearDown(self)
+
     def test_Call( self ):
 
         script = self._makeOne( 'testPT', 'testPT.pt' )
@@ -69,6 +76,7 @@
 
         from OFS.Folder import Folder
 
+        FSPTMaker.setUp(self)
         SecurityTest.setUp( self )
 
         self.root._setObject( 'portal_skins', Folder( 'portal_skins' ) )
@@ -99,6 +107,9 @@
         customized = self.custom.testPT
         self.failIf( customized.expand )
 
+    def tearDown(self):
+        SecurityTest.tearDown(self)
+        FSPTMaker.tearDown(self)
 
 def test_suite():
     return unittest.TestSuite((


=== CMF/CMFCore/tests/test_FSImage.py 1.4 => 1.4.10.1 ===
--- CMF/CMFCore/tests/test_FSImage.py:1.4	Wed Jul  3 14:01:35 2002
+++ CMF/CMFCore/tests/test_FSImage.py	Mon Aug 19 08:41:04 2002
@@ -1,28 +1,32 @@
 import unittest
 import Zope
+import os.path
 
 class DummyCachingManager:
     def getHTTPCachingHeaders( self, content, view_name, keywords, time=None ):
         return ( ( 'foo', 'Foo' ), ( 'bar', 'Bar' ) )
 
-from Products.CMFCore.tests.base.testcase import RequestTest, SecurityTest
+from Products.CMFCore.tests.base.testcase import RequestTest, FSDVTest
 
-class FSImageTests( RequestTest ):
+class FSImageTests( RequestTest, FSDVTest):
+
+    def setUp(self):
+        FSDVTest.setUp(self)
+        RequestTest.setUp(self)
+
+    def tearDown(self):
+        RequestTest.tearDown(self)
+        FSDVTest.tearDown(self)
 
     def _makeOne( self, id, filename ):
 
         from Products.CMFCore.FSImage import FSImage
-        from Products.CMFCore.tests.test_DirectoryView import skin_path_name
-        import os.path
-
-        return FSImage( id, os.path.join( skin_path_name, filename ) )
+        
+        return FSImage( id, os.path.join( self.skin_path_name, filename ) )
 
     def _extractFile( self ):
 
-        from Products.CMFCore.tests.test_DirectoryView import skin_path_name
-        import os.path
-
-        path = os.path.join( skin_path_name, 'test_image.gif' )
+        path = os.path.join( self.skin_path_name, 'test_image.gif' )
         f = open( path, 'rb' )
         try:
             data = f.read()


=== CMF/CMFCore/tests/test_DirectoryView.py 1.9.4.2 => 1.9.4.3 ===
--- CMF/CMFCore/tests/test_DirectoryView.py:1.9.4.2	Mon Aug 19 06:59:36 2002
+++ CMF/CMFCore/tests/test_DirectoryView.py	Mon Aug 19 08:41:04 2002
@@ -2,63 +2,18 @@
 from unittest import TestCase, TestSuite, makeSuite, main
 
 from Products.CMFCore.tests.base.dummy import DummyFolder
+from Products.CMFCore.tests.base.testcase import FSDVTest
 
-from Globals import package_home, DevelopmentMode
+from Globals import DevelopmentMode
 
-from os import remove, mkdir, rmdir, curdir, stat
-from os.path import join, abspath, dirname
-from shutil import copy2
-from time import sleep
-
-try:
-    __file__
-except NameError:
-    # Test was called directly, so no __file__ global exists.
-    _prefix = abspath(curdir)
-else:
-    # Test was called by another test.
-    _prefix = abspath(dirname(__file__))
-
-# the path of our fake skin
-skin_path_name = join(_prefix, 'fake_skins', 'fake_skin')
-
-def _registerDirectory(self=None):
-    from Products.CMFCore.DirectoryView import registerDirectory
-    from Products.CMFCore.DirectoryView import addDirectoryViews
-    registerDirectory('fake_skins', _prefix)
-    if self is not None:
-        ob = self.ob = DummyFolder()
-        addDirectoryViews(ob, 'fake_skins', _prefix)
-
-#
-# XXX: 2002/08/12:  Another thumb-rule:  don't write to the filesystem
-#       as part of a unittest (failure modes are too hard to track down,
-#       and it should be possible to run them *anywhere*, including in
-#       a setup where the files / directories are readonly.
-#
-def _writeFile(filename, stuff):
-    # write some stuff to a file on disk
-    # make sure the file's modification time has changed
-    thePath = join(skin_path_name,filename)
-    try:
-        mtime1 = stat(thePath)[8]
-    except:
-        mtime1 = 0
-    mtime2 = mtime1
-    while mtime2==mtime1:
-        f = open(thePath,'w')
-        f.write(stuff)
-        f.close()
-        mtime2 = stat(thePath)[8]
-
-def _deleteFile(filename):
-    # nuke it
-    remove(join(skin_path_name,filename))
+from os import remove, mkdir, rmdir
+from os.path import join
 
-class DirectoryViewTests1( TestCase ):
+class DirectoryViewTests1( FSDVTest ):
 
     def setUp(self):
-        _registerDirectory()
+        FSDVTest.setUp(self)
+        self._registerDirectory()
         self.ob = DummyFolder()
         
     def test_registerDirectory( self ):
@@ -71,38 +26,39 @@
     #       you are hardwiring assumptions about the shape of
     #       SOFTWARE_HOME/INSTANCE_HOME).
     #
-    def test_getDirectoryInfo1( self ):
-        """ windows INSTANCE_HOME  """
-        from Products.CMFCore.DirectoryView import addDirectoryViews
-        addDirectoryViews(self.ob, 'fake_skins', _prefix)
-        self.ob.fake_skin.manage_properties(r'Products\CMFCore\tests\fake_skins\fake_skin')        
-        self.failUnless(hasattr(self.ob.fake_skin,'test1'))
-
-    def test_getDirectoryInfo2( self ):
-        """ windows SOFTWARE_HOME  """
-        from Products.CMFCore.DirectoryView import addDirectoryViews
-        addDirectoryViews(self.ob, 'fake_skins', _prefix)
-        self.ob.fake_skin.manage_properties(r'C:\Zope\2.5.1\Products\CMFCore\tests\fake_skins\fake_skin')        
-        self.failUnless(hasattr(self.ob.fake_skin,'test1'))
-
-    def test_getDirectoryInfo3( self ):
-        """ *nix INSTANCE_HOME  """
-        from Products.CMFCore.DirectoryView import addDirectoryViews
-        addDirectoryViews(self.ob, 'fake_skins', _prefix)
-        self.ob.fake_skin.manage_properties('Products/CMFCore/tests/fake_skins/fake_skin')        
-        self.failUnless(hasattr(self.ob.fake_skin,'test1'))
-
-    def test_getDirectoryInfo4( self ):
-        """ *nix SOFTWARE_HOME  """
-        from Products.CMFCore.DirectoryView import addDirectoryViews
-        addDirectoryViews(self.ob, 'fake_skins', _prefix)
-        self.ob.fake_skin.manage_properties('/usr/local/zope/2.5.1/Products/CMFCore/tests/fake_skins/fake_skin')        
-        self.failUnless(hasattr(self.ob.fake_skin,'test1'))
+##     def test_getDirectoryInfo1( self ):
+##         """ windows INSTANCE_HOME  """
+##         from Products.CMFCore.DirectoryView import addDirectoryViews
+##         addDirectoryViews(self.ob, 'fake_skins', _prefix)
+##         self.ob.fake_skin.manage_properties(r'Products\CMFCore\tests\fake_skins\fake_skin')        
+##         self.failUnless(hasattr(self.ob.fake_skin,'test1'))
+
+##     def test_getDirectoryInfo2( self ):
+##         """ windows SOFTWARE_HOME  """
+##         from Products.CMFCore.DirectoryView import addDirectoryViews
+##         addDirectoryViews(self.ob, 'fake_skins', _prefix)
+##         self.ob.fake_skin.manage_properties(r'C:\Zope\2.5.1\Products\CMFCore\tests\fake_skins\fake_skin')        
+##         self.failUnless(hasattr(self.ob.fake_skin,'test1'))
+
+##     def test_getDirectoryInfo3( self ):
+##         """ *nix INSTANCE_HOME  """
+##         from Products.CMFCore.DirectoryView import addDirectoryViews
+##         addDirectoryViews(self.ob, 'fake_skins', _prefix)
+##         self.ob.fake_skin.manage_properties('Products/CMFCore/tests/fake_skins/fake_skin')        
+##         self.failUnless(hasattr(self.ob.fake_skin,'test1'))
+
+##     def test_getDirectoryInfo4( self ):
+##         """ *nix SOFTWARE_HOME  """
+##         from Products.CMFCore.DirectoryView import addDirectoryViews
+##         addDirectoryViews(self.ob, 'fake_skins', _prefix)
+##         self.ob.fake_skin.manage_properties('/usr/local/zope/2.5.1/Products/CMFCore/tests/fake_skins/fake_skin')        
+##         self.failUnless(hasattr(self.ob.fake_skin,'test1'))
 
-class DirectoryViewTests2( TestCase ):
+class DirectoryViewTests2( FSDVTest ):
 
     def setUp( self ):
-        _registerDirectory(self)        
+        FSDVTest.setUp(self)
+        self._registerDirectory(self)        
 
     def test_addDirectoryViews( self ):
         """ Test addDirectoryViews  """
@@ -125,46 +81,28 @@
         """Make sure the directory view is reading properties"""
         self.assertEqual(self.ob.fake_skin.testPT.title, 'Zope Pope')
 
-test1path = join(skin_path_name,'test1.py')
-test2path = join(skin_path_name,'test2.py')
-test3path = join(skin_path_name,'test3')
-
 if DevelopmentMode:
 
-  class DebugModeTests( TestCase ):
+  class DebugModeTests( FSDVTest ):
 
     def setUp( self ):
+        FSDVTest.setUp(self)
+        self.test1path = join(self.skin_path_name,'test1.py')
+        self.test2path = join(self.skin_path_name,'test2.py')
+        self.test3path = join(self.skin_path_name,'test3')
         
         # initialise skins
-        _registerDirectory(self)
+        self._registerDirectory(self)
 
         # add a method to the fake skin folder
-        _writeFile(test2path, "return 'test2'")
+        self._writeFile(self.test2path, "return 'test2'")
 
         # edit the test1 method
-        copy2(test1path,test1path+'.bak')
-        _writeFile(test1path, "return 'new test1'")
+        self._writeFile(self.test1path, "return 'new test1'")
 
         # add a new folder
-        mkdir(test3path)
-        
-    def tearDown( self ):
+        mkdir(self.test3path)
         
-        # undo FS changes
-        remove(test1path)
-        copy2(test1path+'.bak',test1path)
-        remove(test1path+'.bak')
-        try:        
-            remove(test2path)
-        except (IOError,OSError):
-            # it might be gone already
-            pass
-        try:
-            rmdir(test3path)
-        except (IOError,OSError):
-            # it might be gone already
-            pass
-
     def test_AddNewMethod( self ):
         """
         See if a method added to the skin folder can be found
@@ -189,13 +127,8 @@
         """
         Make sure a deleted method goes away
         """
-        remove(test2path)
-        try:
-            self.ob.fake_skin.test2
-        except AttributeError:
-            pass
-        else:
-            self.fail('test2 still exists')
+        remove(self.test2path)
+        self.failIf(hasattr(self.ob.fake_skin,'test2'))
 
     def test_DeleteAddEditMethod( self ):
         """
@@ -204,27 +137,17 @@
 
         This excecises yet another Win32 mtime weirdity.
         """
-        remove(test2path)
-        try:
-            self.ob.fake_skin.test2
-        except AttributeError:
-            pass
-        else:
-            self.fail('test2 still exists')
+        remove(self.test2path)
+        self.failIf(hasattr(self.ob.fake_skin,'test2'))
             
         # add method back to the fake skin folder
-        _writeFile(test2path, "return 'test2.2'")
-        
-        # we need to wait a second here or the mtime will actually
-        # have the same value, no human makes two edits in less
-        # than a second ;-)
-        sleep(1)
+        self._writeFile(self.test2path, "return 'test2.2'")
         
         # check
         self.assertEqual(self.ob.fake_skin.test2(),'test2.2')
 
         # edit method
-        _writeFile(test2path, "return 'test2.3'")
+        self._writeFile(self.test2path, "return 'test2.3'")
 
         # check
         self.assertEqual(self.ob.fake_skin.test2(),'test2.3')
@@ -233,13 +156,8 @@
         """
         Make sure a deleted folder goes away
         """
-        rmdir(test3path)
-        try:
-            self.ob.fake_skin.test3
-        except AttributeError:
-            pass
-        else:
-            self.fail('test3 still exists')
+        rmdir(self.test3path)
+        self.failIf(hasattr(self.ob.fake_skin,'test3'))
 
 else: