[CMF-checkins] CVS: CMF/CMFCore/tests - test_DirectoryView.py:1.10 test_FSSecurity.py:1.4

Tres Seaver tseaver@zope.com
Mon, 12 Aug 2002 08:23:14 -0400


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

Modified Files:
	test_DirectoryView.py test_FSSecurity.py 
Log Message:


  - Revert last week's problematic changes, after checking them in on
    a new branch ('chrisw-dirview-branch'), to keep the unittests clean
    on the HEAD while work continues on the branch.


=== CMF/CMFCore/tests/test_DirectoryView.py 1.9 => 1.10 ===
--- CMF/CMFCore/tests/test_DirectoryView.py:1.9	Mon Aug  5 10:23:41 2002
+++ CMF/CMFCore/tests/test_DirectoryView.py	Mon Aug 12 08:23:13 2002
@@ -1,17 +1,14 @@
 import Zope
 from unittest import TestCase, TestSuite, makeSuite, main
 
-from Products.CMFCore.tests.base.dummy import DummyFolder
-
-from Products.CMFCore.DirectoryView import registerDirectory
-from Products.CMFCore.DirectoryView import addDirectoryViews
-from Products.CMFCore.DirectoryView import DirectoryViewSurrogate
-from Products.CMFCore.DirectoryView import _dirreg
-from Products.CMFCore.DirectoryView import DirectoryInformation
+from Products.CMFCore.tests.base.dummy import \
+     DummyFolder
 
+from Products.CMFCore.DirectoryView import \
+     registerDirectory,addDirectoryViews,DirectoryViewSurrogate
 from Globals import package_home, DevelopmentMode
 
-from os import remove, mkdir, rmdir, curdir, stat
+from os import remove, mkdir, rmdir, curdir
 from os.path import join, abspath, dirname
 from shutil import copy2
 from time import sleep
@@ -34,58 +31,11 @@
         ob = self.ob = DummyFolder()
         addDirectoryViews(ob, 'fake_skins', _prefix)
     
-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))
-
 class DirectoryViewTests1( TestCase ):
 
-    def setUp(self):
-        _registerDirectory()
-        self.ob = DummyFolder()
-        
     def test_registerDirectory( self ):
         """ Test registerDirectory  """
-        pass
-    
-    def test_getDirectoryInfo1( self ):
-        """ windows INSTANCE_HOME  """
-        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  """
-        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  """
-        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  """
-        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'))
+        _registerDirectory()
 
 class DirectoryViewTests2( TestCase ):
 
@@ -112,6 +62,7 @@
         """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')
@@ -126,11 +77,15 @@
         _registerDirectory(self)
 
         # add a method to the fake skin folder
-        _writeFile(test2path, "return 'test2'")
+        f = open(test2path,'w')
+        f.write("return 'test2'")
+        f.close()
 
         # edit the test1 method
         copy2(test1path,test1path+'.bak')
-        _writeFile(test1path, "return 'new test1'")
+        f = open(test1path,'w')
+        f.write("return 'new test1'")
+        f.close()
 
         # add a new folder
         mkdir(test3path)
@@ -199,7 +154,9 @@
             self.fail('test2 still exists')
             
         # add method back to the fake skin folder
-        _writeFile(test2path, "return 'test2.2'")
+        f = open(test2path,'w')
+        f.write("return 'test2.2'")
+        f.close()
         
         # we need to wait a second here or the mtime will actually
         # have the same value, no human makes two edits in less
@@ -209,8 +166,11 @@
         # check
         self.assertEqual(self.ob.fake_skin.test2(),'test2.2')
 
+        
         # edit method
-        _writeFile(test2path, "return 'test2.3'")
+        f = open(test2path,'w')
+        f.write("return 'test2.3'")
+        f.close()
 
         # check
         self.assertEqual(self.ob.fake_skin.test2(),'test2.3')
@@ -234,8 +194,8 @@
 
 def test_suite():
     return TestSuite((
-        makeSuite(DirectoryViewTests1),
-        makeSuite(DirectoryViewTests2),
+        # makeSuite(DirectoryViewTests1),
+        # makeSuite(DirectoryViewTests2),
         makeSuite(DebugModeTests),
         ))
 


=== CMF/CMFCore/tests/test_FSSecurity.py 1.3 => 1.4 ===
--- CMF/CMFCore/tests/test_FSSecurity.py:1.3	Mon Aug  5 06:46:53 2002
+++ CMF/CMFCore/tests/test_FSSecurity.py	Mon Aug 12 08:23:13 2002
@@ -2,14 +2,13 @@
 
 from unittest import TestSuite, makeSuite, main
 from types import ListType
+from os import remove
+from os.path import join
 from time import sleep
 
 from AccessControl.Permission import Permission
 from Products.CMFCore.tests.base.testcase import RequestTest
-from test_DirectoryView import _registerDirectory
-from test_DirectoryView import _prefix
-from test_DirectoryView import _writeFile
-from test_DirectoryView import _deleteFile
+from test_DirectoryView import _registerDirectory, _prefix
 from Globals import DevelopmentMode
 
 class FSSecurityBase( RequestTest ):
@@ -35,6 +34,19 @@
         if not happy:
             raise ValueError,"'%s' not found in permissions: %s" % (permissionname,all_names)
             
+    _path = join(_prefix,'fake_skins','fake_skin')
+    
+    def _writeFile(self, filename, stuff):
+        # write some stuff to a file on disk
+        thePath = join(self._path,filename)
+        f = open(thePath,'w')
+        f.write(stuff)
+        f.close()
+        
+    def _deleteFile(self,filename):
+        # nuke it
+        remove(join(self._path,filename))
+        
     def setUp( self ):
         # initialise skins
         _registerDirectory(self)
@@ -48,7 +60,7 @@
 
     def tearDown( self ):
         try:
-            _deleteFile('test5.py.security')
+            self._deleteFile('test5.py.security')
         except:
             pass
         RequestTest.tearDown(self)
@@ -68,7 +80,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,[])
         
@@ -77,7 +89,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,[])
 
@@ -90,7 +102,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'])
 
@@ -98,20 +110,29 @@
             """ 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 """
+            # we need to wait a second here or the mtime will actually
+            # have the same value as set in the last test.
+            # Maybe someone brainier than me can figure out a way to make this
+            # suck less :-(            
+            sleep(1)
+            
             # baseline
-            _writeFile('test5.py.security','View::Manager,Anonymous')
-            self._checkSettings(self.ob.fake_skin.test5,'View',0,['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'])
 
@@ -119,15 +140,24 @@
         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,[])
+
+            # 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)
+            
             # 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'])