[CMF-checkins] CVS: CMF/CMFCore/tests - test_DirectoryView.py:1.11 test_FSImage.py:1.5 test_FSPageTemplate.py:1.8 test_FSPythonScript.py:1.5 test_FSSecurity.py:1.5
Chris Withers
chrisw@nipltd.com
Mon, 19 Aug 2002 13:29:33 -0400
Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv9522/CMFCore/tests
Modified Files:
test_DirectoryView.py test_FSImage.py test_FSPageTemplate.py
test_FSPythonScript.py test_FSSecurity.py
Log Message:
Merge from branch:
1. Make tests using FSDV's work on a copy of the fake skin in the temporary fiel space.
2. 2nd attempt at making DV dirpaths be a bit mroe flexible in cross platform situations
3. All tests should now pass on both Windows and Linux.
=== CMF/CMFCore/tests/test_DirectoryView.py 1.10 => 1.11 ===
--- CMF/CMFCore/tests/test_DirectoryView.py:1.10 Mon Aug 12 08:23:13 2002
+++ CMF/CMFCore/tests/test_DirectoryView.py Mon Aug 19 13:29:32 2002
@@ -1,49 +1,64 @@
import Zope
from unittest import TestCase, TestSuite, makeSuite, main
-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
-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):
- registerDirectory('fake_skins', _prefix)
- if self is not None:
- ob = self.ob = DummyFolder()
- addDirectoryViews(ob, 'fake_skins', _prefix)
-
-class DirectoryViewTests1( TestCase ):
-
- def test_registerDirectory( self ):
- """ Test registerDirectory """
- _registerDirectory()
-
-class DirectoryViewTests2( TestCase ):
+from Products.CMFCore.tests.base.dummy import DummyFolder
+from Products.CMFCore.tests.base.testcase import FSDVTest
+from Products.CMFCore.tests.base.testcase import _prefix
+
+from Globals import DevelopmentMode
+
+from os import remove, mkdir, rmdir
+from os.path import join
+
+class DirectoryViewPathTests( TestCase ):
+ """
+ These test that, no matter what is stored in their dirpath,
+ FSDV's will do their best to find an appropriate skin
+ and only do nothing in difficult cases (such as where
+ people have chosen to use PRODUCTS_PATH )
+ """
+ def setUp(self):
+ from Products.CMFCore.DirectoryView import registerDirectory
+ from Products.CMFCore.DirectoryView import addDirectoryViews
+ registerDirectory('fake_skins', _prefix)
+ self.ob = DummyFolder()
+ addDirectoryViews(self.ob, 'fake_skins', _prefix)
+
+ def test_getDirectoryInfo1( self ):
+ """ windows INSTANCE_HOME """
+ 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 """
+ 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 """
+ self.ob.fake_skin.manage_properties('Products/CMFCore/tests/fake_skins/fake_skin')
+ self.failUnless(hasattr(self.ob.fake_skin,'test1'))
+
+ def test_getDirectoryInfo5( self ):
+ """ *nix SOFTWARE_HOME """
+ 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_getDirectoryInfo5( self ):
+ """ Somewhere we won't be able to find """
+ from tempfile import mktemp
+ self.ob.fake_skin.manage_properties(mktemp()+'/CMFCore/tests/fake_skins/fake_skin')
+ self.assertEqual(self.ob.fake_skin.objectIds(),[])
+
+class DirectoryViewTests( FSDVTest ):
def setUp( self ):
- _registerDirectory(self)
+ FSDVTest.setUp(self)
+ self._registerDirectory(self)
def test_addDirectoryViews( self ):
""" Test addDirectoryViews """
+ # also test registration of driectory views doesn't barf
pass
def test_DirectoryViewExists( self ):
@@ -52,6 +67,7 @@
appears as a DirectoryViewSurrogate due
to Acquisition hackery.
"""
+ from Products.CMFCore.DirectoryView import DirectoryViewSurrogate
self.failUnless(isinstance(self.ob.fake_skin,DirectoryViewSurrogate))
def test_DirectoryViewMethod( self ):
@@ -62,51 +78,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
- f = open(test2path,'w')
- f.write("return 'test2'")
- f.close()
+ self._writeFile(self.test2path, "return 'test2'")
# edit the test1 method
- copy2(test1path,test1path+'.bak')
- f = open(test1path,'w')
- f.write("return 'new test1'")
- f.close()
+ self._writeFile(self.test1path, "return 'new test1'")
# add a new folder
- mkdir(test3path)
+ mkdir(self.test3path)
- def tearDown( self ):
-
- # 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
@@ -123,6 +116,7 @@
"""
See if a new folder shows up
"""
+ from Products.CMFCore.DirectoryView import DirectoryViewSurrogate
self.failUnless(isinstance(self.ob.fake_skin.test3,DirectoryViewSurrogate))
self.ob.fake_skin.test3.objectIds()
@@ -130,13 +124,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 ):
"""
@@ -145,32 +134,18 @@
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
- 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)
+ self._writeFile(self.test2path, "return 'test2.2'")
# check
self.assertEqual(self.ob.fake_skin.test2(),'test2.2')
# edit method
- f = open(test2path,'w')
- f.write("return 'test2.3'")
- f.close()
+ self._writeFile(self.test2path, "return 'test2.3'")
# check
self.assertEqual(self.ob.fake_skin.test2(),'test2.3')
@@ -179,13 +154,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:
@@ -194,8 +164,8 @@
def test_suite():
return TestSuite((
- # makeSuite(DirectoryViewTests1),
- # makeSuite(DirectoryViewTests2),
+ makeSuite(DirectoryViewPathTests),
+ makeSuite(DirectoryViewTests),
makeSuite(DebugModeTests),
))
=== CMF/CMFCore/tests/test_FSImage.py 1.4 => 1.5 ===
--- CMF/CMFCore/tests/test_FSImage.py:1.4 Wed Jul 3 14:01:35 2002
+++ CMF/CMFCore/tests/test_FSImage.py Mon Aug 19 13:29:32 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_FSPageTemplate.py 1.7 => 1.8 ===
--- CMF/CMFCore/tests/test_FSPageTemplate.py:1.7 Wed Jul 31 17:52:32 2002
+++ CMF/CMFCore/tests/test_FSPageTemplate.py Mon Aug 19 13:29:32 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_FSPythonScript.py 1.4 => 1.5 ===
--- CMF/CMFCore/tests/test_FSPythonScript.py:1.4 Thu Aug 15 16:03:49 2002
+++ CMF/CMFCore/tests/test_FSPythonScript.py Mon Aug 19 13:29:32 2002
@@ -3,18 +3,16 @@
from OFS.Folder import Folder
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
import sys, time
from thread import start_new_thread
-script_path = join(skin_path_name,'test1.py')
+class FSPythonScriptTests( FSDVTest ):
-class FSPythonScriptTests( TestCase ):
-
- def testGetSize(self):
- # Test get_size returns correct value
- script = FSPythonScript('test1', script_path)
+ def test_GetSize( self ):
+ """ Test get_size returns correct value """
+ script = FSPythonScript('test1', join(self.skin_path_name,'test1.py'))
self.assertEqual(len(script.read()),script.get_size())
def testInitializationRaceCondition(self):
@@ -23,7 +21,7 @@
# object was really parsed.
for n in range(10):
f = Folder()
- script = FSPythonScript('test1', script_path).__of__(f)
+ script = FSPythonScript('test1', join(self.skin_path_name,'test1.py')).__of__(f)
res = []
def call_script(script=script, res=res):
=== CMF/CMFCore/tests/test_FSSecurity.py 1.4 => 1.5 ===
--- CMF/CMFCore/tests/test_FSSecurity.py:1.4 Mon Aug 12 08:23:13 2002
+++ CMF/CMFCore/tests/test_FSSecurity.py Mon Aug 19 13:29:32 2002
@@ -8,10 +8,11 @@
from AccessControl.Permission import Permission
from Products.CMFCore.tests.base.testcase import RequestTest
-from test_DirectoryView import _registerDirectory, _prefix
+from Products.CMFCore.tests.base.testcase import FSDVTest
+
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
@@ -33,23 +34,11 @@
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(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)
+ FSDVTest.setUp(self)
+ self._registerDirectory(self)
# set up ZODB
RequestTest.setUp(self)
# put object in ZODB
@@ -59,11 +48,8 @@
root._setObject( 'fake_skin', self.ob.fake_skin )
def tearDown( self ):
- try:
- self._deleteFile('test5.py.security')
- except:
- pass
RequestTest.tearDown(self)
+ FSDVTest.tearDown(self)
class FSSecurityTests( FSSecurityBase ):
@@ -127,10 +113,7 @@
# baseline
self._writeFile('test5.py.security','View::Manager,Anonymous')
- self._checkSettings(self.ob.fake_skin.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
@@ -141,7 +124,6 @@
""" Test deleting, then adding, then editing a .security file """
# baseline
self._writeFile('test5.py.security','View::Manager')
-
# delete
self._deleteFile('test5.py.security')
self._checkSettings(self.ob.fake_skin.test5,'View',1,[])
@@ -157,7 +139,6 @@
# edit
self._writeFile('test5.py.security','View:acquire:Manager')
-
# test
self._checkSettings(self.ob.fake_skin.test5,'View',1,['Manager'])