[CMF-checkins] CVS: CMF/CMFCore/tests - test_DirectoryView.py:1.2
Chris Withers
chrisw@nipltd.com
Fri, 25 Jan 2002 09:50:52 -0500
Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv32278/CMFCore/tests
Modified Files:
test_DirectoryView.py
Log Message:
Merge fixes for #305
=== CMF/CMFCore/tests/test_DirectoryView.py 1.1 => 1.2 ===
from unittest import TestCase, TestSuite, makeSuite, main
-from Products.CMFCore.DirectoryView import registerDirectory,addDirectoryViews,DirectoryViewSurrogate
-from Globals import package_home
+from Products.CMFCore.DirectoryView import \
+ registerDirectory,addDirectoryViews,DirectoryViewSurrogate
+from Globals import package_home, DevelopmentMode
from Acquisition import Implicit
-from os import remove
+from os import remove, mkdir, rmdir
from os.path import join
from shutil import copy2
@@ -12,12 +13,6 @@
class DirectoryViewTests1( TestCase ):
- def setUp( self ):
- get_transaction().begin()
-
- def tearDown( self ):
- get_transaction().abort()
-
def test_registerDirectory( self ):
""" Test registerDirectory """
registerDirectory('fake_skins', globals())
@@ -34,14 +29,10 @@
class DirectoryViewTests2( TestCase ):
def setUp( self ):
- get_transaction().begin()
registerDirectory('fake_skins', globals())
ob = self.ob = Dummy()
addDirectoryViews(ob, 'fake_skins', globals())
- def tearDown( self ):
- get_transaction().abort()
-
def test_addDirectoryViews( self ):
""" Test addDirectoryViews """
pass
@@ -52,35 +43,27 @@
appears as a DirectoryViewSurrogate due
to Acquisition hackery.
"""
- assert isinstance(self.ob.fake_skin,DirectoryViewSurrogate)
+ self.failUnless(isinstance(self.ob.fake_skin,DirectoryViewSurrogate))
def test_DirectoryViewMethod( self ):
""" Check if DirectoryView method works """
- assert self.ob.fake_skin.test1()=='test1'
-
-import Globals
-import Products.CMFCore.DirectoryView
+ self.assertEqual(self.ob.fake_skin.test1(),'test1')
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( TestCase ):
def setUp( self ):
- get_transaction().begin()
- # put us in debug mode, preserve the DirectoryRegistry
- Globals.DevelopmentMode=1
- _dirreg = Products.CMFCore.DirectoryView._dirreg
- reload(Products.CMFCore.DirectoryView)
- Products.CMFCore.DirectoryView._dirreg = _dirreg
-
-
# initialise skins
- Products.CMFCore.DirectoryView.registerDirectory('fake_skins', globals())
+ registerDirectory('fake_skins', globals())
ob = self.ob = Dummy()
- Products.CMFCore.DirectoryView.addDirectoryViews(ob, 'fake_skins', globals())
-
+ addDirectoryViews(ob, 'fake_skins', globals())
+
# add a method to the fake skin folder
f = open(test2path,'w')
f.write("return 'test2'")
@@ -92,34 +75,74 @@
f.write("return 'new test1'")
f.close()
+ # add a new folder
+ mkdir(test3path)
+
def tearDown( self ):
# undo FS changes
remove(test1path)
copy2(test1path+'.bak',test1path)
remove(test1path+'.bak')
- remove(test2path)
+ try:
+ remove(test2path)
+ except (IOError,OSError):
+ # it might be gone already
+ pass
+ try:
+ rmdir(test3path)
+ except (IOError,OSError):
+ # it might be gone already
+ pass
- # take us out of debug mode, preserve the DirectoryRegistry
- Globals.DevelopmentMode=None
- _dirreg = Products.CMFCore.DirectoryView._dirreg
- reload(Products.CMFCore.DirectoryView)
- Products.CMFCore.DirectoryView._dirreg = _dirreg
-
- get_transaction().abort()
-
def test_AddNewMethod( self ):
"""
See if a method added to the skin folder can be found
"""
- assert self.ob.fake_skin.test2()=='test2'
+ self.assertEqual(self.ob.fake_skin.test2(),'test2')
def test_EditMethod( self ):
"""
See if an edited method exhibits its new behaviour
"""
- assert self.ob.fake_skin.test1()=='new test1'
+ self.assertEqual(self.ob.fake_skin.test1(),'new test1')
+
+ def test_NewFolder( self ):
+ """
+ See if a new folder shows up
+ """
+ # This fails for some bizarre reason :-( - CW
+ self.failUnless(isinstance(self.ob.fake_skin.test3,DirectoryViewSurrogate))
+ self.ob.fake_skin.test3.objectIds()
+ def test_DeleteMethod( self ):
+ """
+ Make sure a deleted method goes away
+ """
+ remove(test2path)
+ try:
+ self.ob.fake_skin.test2
+ except AttributeError:
+ pass
+ else:
+ self.fail('test2 still exists')
+
+ def test_DeleteFolder( self ):
+ """
+ Make sure a deleted folder goes away
+ """
+ rmdir(test3path)
+ try:
+ self.ob.fake_skin.test3
+ except AttributeError:
+ pass
+ else:
+ self.fail('test3 still exists')
+
+else:
+
+ class DebugModeTests( TestCase ):
+ pass
def test_suite():
return TestSuite((