[CMF-checkins] CVS: CMF/CMFCore/tests - test_DirectoryView.py:1.5.2.2 test_FSSecurity.py:1.1.2.3

Chris Withers chrisw@nipltd.com
Tue, 14 May 2002 15:54:25 -0400


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

Modified Files:
      Tag: chrisw_fssecurity_branch
	test_DirectoryView.py test_FSSecurity.py 
Log Message:
All tests pass, although some suck a bit. Maybe someone else could haev a look?

=== CMF/CMFCore/tests/test_DirectoryView.py 1.5.2.1 => 1.5.2.2 ===
 from os.path import join, abspath, dirname
 from shutil import copy2
+from time import sleep
 
 try:
     __file__
@@ -137,6 +138,43 @@
         else:
             self.fail('test2 still exists')
 
+    def test_DeleteAddEditMethod( self ):
+        """
+        Check that if we delete a method, then add it back,
+        then edit it, the DirectoryView notices.
+
+        This excecises yet another Win32 mtime weirdity.
+        """
+        remove(test2path)
+        try:
+            self.ob.fake_skin.test2
+        except AttributeError:
+            pass
+        else:
+            self.fail('test2 still exists')
+            
+        # add method back to the fake skin folder
+        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
+        # than a second ;-)
+        sleep(1)
+        
+        # check
+        self.assertEqual(self.ob.fake_skin.test2(),'test2.2')
+
+        
+        # edit method
+        f = open(test2path,'w')
+        f.write("return 'test2.3'")
+        f.close()
+
+        # check
+        self.assertEqual(self.ob.fake_skin.test2(),'test2.3')
+        
     def test_DeleteFolder( self ):
         """
         Make sure a deleted folder goes away


=== CMF/CMFCore/tests/test_FSSecurity.py 1.1.2.2 => 1.1.2.3 ===
 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
@@ -28,22 +29,23 @@
                 got={}
                 for role in groles:
                     got[role]=1
-                self.assertEqual(expected,got)
-                self.assertEqual(acquire,acquired)
+                self.assertEqual((acquire,expected),(acquired,got))
                 happy=1
         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(_prefix,filename)
+        thePath = join(self._path,filename)
         f = open(thePath,'w')
         f.write(stuff)
         f.close()
         
     def _deleteFile(self,filename):
         # nuke it
-        remove(join(_prefix,filename))
+        remove(join(self._path,filename))
         
     def setUp( self ):
         # initialise skins
@@ -55,7 +57,6 @@
         try: root._delObject('fake_skin')
         except AttributeError: pass
         root._setObject( 'fake_skin', self.ob.fake_skin )
-        self.layer = root.fake_skin
 
     def tearDown( self ):
         try:
@@ -69,37 +70,28 @@
     def test_basicPermissions( self ):
         """ Test basic FS permissions """
         # check a normal method is as we'd expect
-        self._checkSettings(self.layer.test1,'View',1,[])
+        self._checkSettings(self.ob.fake_skin.test1,'View',1,[])
         # now do some checks on the method with FS permissions
-        self._checkSettings(self.layer.test4,'View',1,['Manager','Owner'])
-        self._checkSettings(self.layer.test4,'Access contents information',0,[])
+        self._checkSettings(self.ob.fake_skin.test4,'View',1,['Manager','Owner'])
+        self._checkSettings(self.ob.fake_skin.test4,'Access contents information',0,[])
 
     def test_invalidPermissionNames( self ):
         """ Test for an invalid permission name """
         # baseline
-        self._checkSettings(self.layer.test5,'View',1,[])
+        self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
         # add .rpm with dodgy permission name
         self._writeFile('test5.py.security','Access stoopid contents::')
         # check baseline
-        self._checkSettings(self.layer.test5,'View',1,[])
+        self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
         
-    def test_invalidRoleNames( self ):
-        """ Test for an invalid role name """
-        # baseline
-        self._checkSettings(self.layer.test5,'View',1,[])
-        # add dodgy .rpm
-        self._writeFile('test5.py.security','view::Monkey, Butler, Manager ')
-        # check baseline
-        self._checkSettings(self.layer.test5,'View',1,[])
-
     def test_invalidAcquireNames( self ):
         """ Test for an invalid spelling of acquire """
         # baseline
-        self._checkSettings(self.layer.test5,'View',1,[])
+        self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
         # add dodgy .rpm
         self._writeFile('test5.py.security','View:aquire:')
         # check baseline
-        self._checkSettings(self.layer.test5,'View',1,[])
+        self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
 
 if DevelopmentMode:
 
@@ -108,32 +100,66 @@
         def test_addPRM( self ):
             """ Test adding of a .security """
             # baseline
-            self._checkSettings(self.layer.test5,'View',1,[])
+            self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
             # add
             self._writeFile('test5.py.security','View:acquire:Manager')
             # test            
-            self._checkSettings(self.layer.test5,'View',1,['Manager'])
+            self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
+
+        def test_delPRM( self ):
+            """ Test deleting of a .security """
+            # baseline
+            self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
+            self._writeFile('test5.py.security','View:acquire:Manager')
+            self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
+            # delete
+            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
             self._writeFile('test5.py.security','View::Manager,Anonymous')
-            self._checkSettings(self.layer.test5,'View',0,['Manager','Anonymous'])
+            self._checkSettings(self.ob.fake_skin.test5,'View',0,['Manager','Anonymous'])
+            
+            
+
             # edit
             self._writeFile('test5.py.security','View:acquire:Manager')
-            # test            
-            self._checkSettings(self.layer.test5,'View',1,['Manager'])
+            # test
+            self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
 
-        def test_delPRM( self ):
-            """ Test deleting of a .security """
+
+        def test_DelAddEditPRM( self ):
+            """ Test deleting, then adding, then editing a .security file """
             # baseline
-            self._checkSettings(self.layer.test5,'View',1,[])
-            self._writeFile('test5.py.security','View:acquire:Manager')
-            self._checkSettings(self.layer.test5,'View',1,['Manager'])
+            self._writeFile('test5.py.security','View::Manager')
+
             # delete
             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
+            self._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')
+
             # test
-            self._checkSettings(self.layer.test5,'View',1,[])
+            self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])
 
 else: