[CMF-checkins] CVS: CMF/CMFCore/tests - test_DirectoryView.py:1.8 test_FSSecurity.py:1.3
Chris Withers
chrisw@nipltd.com
Mon, 5 Aug 2002 06:46:54 -0400
Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv24201/CMFCore/tests
Modified Files:
test_DirectoryView.py test_FSSecurity.py
Log Message:
More robustly test the FS Security stuff, also check even harder that stuff has been modified in a driectory view on Windows.
=== CMF/CMFCore/tests/test_DirectoryView.py 1.7 => 1.8 ===
registerDirectory,addDirectoryViews,DirectoryViewSurrogate
from Globals import package_home, DevelopmentMode
-from os import remove, mkdir, rmdir, curdir
+from os import remove, mkdir, rmdir, curdir, stat
from os.path import join, abspath, dirname
from shutil import copy2
from time import sleep
@@ -31,6 +31,25 @@
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 test_registerDirectory( self ):
@@ -77,15 +96,11 @@
_registerDirectory(self)
# add a method to the fake skin folder
- f = open(test2path,'w')
- f.write("return 'test2'")
- f.close()
+ _writeFile(test2path, "return 'test2'")
# edit the test1 method
copy2(test1path,test1path+'.bak')
- f = open(test1path,'w')
- f.write("return 'new test1'")
- f.close()
+ _writeFile(test1path, "return 'new test1'")
# add a new folder
mkdir(test3path)
@@ -154,9 +169,7 @@
self.fail('test2 still exists')
# add method back to the fake skin folder
- f = open(test2path,'w')
- f.write("return 'test2.2'")
- f.close()
+ _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
@@ -166,11 +179,8 @@
# check
self.assertEqual(self.ob.fake_skin.test2(),'test2.2')
-
# edit method
- f = open(test2path,'w')
- f.write("return 'test2.3'")
- f.close()
+ _writeFile(test2path, "return 'test2.3'")
# check
self.assertEqual(self.ob.fake_skin.test2(),'test2.3')
=== CMF/CMFCore/tests/test_FSSecurity.py 1.2 => 1.3 ===
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, _prefix
+from test_DirectoryView import _registerDirectory
+from test_DirectoryView import _prefix
+from test_DirectoryView import _writeFile
+from test_DirectoryView import _deleteFile
from Globals import DevelopmentMode
class FSSecurityBase( RequestTest ):
@@ -34,19 +35,6 @@
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)
@@ -60,7 +48,7 @@
def tearDown( self ):
try:
- self._deleteFile('test5.py.security')
+ _deleteFile('test5.py.security')
except:
pass
RequestTest.tearDown(self)
@@ -80,7 +68,7 @@
# baseline
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
# add .rpm with dodgy permission name
- self._writeFile('test5.py.security','Access stoopid contents::')
+ _writeFile('test5.py.security','Access stoopid contents::')
# check baseline
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
@@ -89,7 +77,7 @@
# baseline
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
# add dodgy .rpm
- self._writeFile('test5.py.security','View:aquire:')
+ _writeFile('test5.py.security','View:aquire:')
# check baseline
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
@@ -102,7 +90,7 @@
# baseline
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
# add
- self._writeFile('test5.py.security','View:acquire:Manager')
+ _writeFile('test5.py.security','View:acquire:Manager')
# test
self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
@@ -110,29 +98,20 @@
""" Test deleting of a .security """
# baseline
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
- self._writeFile('test5.py.security','View:acquire:Manager')
+ _writeFile('test5.py.security','View:acquire:Manager')
self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
# delete
- self._deleteFile('test5.py.security')
+ _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
- self._writeFile('test5.py.security','View::Manager,Anonymous')
- self._checkSettings(self.ob.fake_skin.test5,'View',0,['Manager','Anonymous'])
-
-
-
+ _writeFile('test5.py.security','View::Manager,Anonymous')
+ self._checkSettings(self.ob.fake_skin.test5,'View',0,['Manager','Anonymous'])
# edit
- self._writeFile('test5.py.security','View:acquire:Manager')
+ _writeFile('test5.py.security','View:acquire:Manager')
# test
self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
@@ -140,24 +119,15 @@
def test_DelAddEditPRM( self ):
""" Test deleting, then adding, then editing a .security file """
# baseline
- self._writeFile('test5.py.security','View::Manager')
-
+ _writeFile('test5.py.security','View::Manager')
# delete
- self._deleteFile('test5.py.security')
+ _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
- self._writeFile('test5.py.security','View::Manager,Anonymous')
+ _writeFile('test5.py.security','View::Manager,Anonymous')
self._checkSettings(self.ob.fake_skin.test5,'View',0,['Manager','Anonymous'])
-
# edit
- self._writeFile('test5.py.security','View:acquire:Manager')
-
+ _writeFile('test5.py.security','View:acquire:Manager')
# test
self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])