[Zope-CVS] CVS: Products/FileCacheManager/tests - testFileCacheManager.py:1.7

Jens Vagelpohl jens at dataflake.org
Sun Aug 15 15:37:24 EDT 2004


Update of /cvs-repository/Products/FileCacheManager/tests
In directory cvs.zope.org:/tmp/cvs-serv27833/tests

Modified Files:
	testFileCacheManager.py 
Log Message:
- add simple test for setting a TAL naming expression
- add declarative security to Dummy content class
- better tearDown that won't leave turds on the file system


=== Products/FileCacheManager/tests/testFileCacheManager.py 1.6 => 1.7 ===
--- Products/FileCacheManager/tests/testFileCacheManager.py:1.6	Sun Aug 15 14:57:02 2004
+++ Products/FileCacheManager/tests/testFileCacheManager.py	Sun Aug 15 15:37:24 2004
@@ -14,7 +14,10 @@
 
 import os, unittest, warnings
 import random
+from AccessControl import ClassSecurityInfo
+from Globals import InitializeClass
 from ZPublisher.Iterators import filestream_iterator
+from Products.PageTemplates.PythonExpr import PythonExpr
 from Products.FileCacheManager.FileCacheManager import FileCache, \
      FileCacheManager
 
@@ -25,6 +28,8 @@
 
 class Dummy:
     """ fake content object """
+    security = ClassSecurityInfo()
+
     def __init__(self, id, fakepath, size):
         self.id = id
         randchar = chr(random.randint(0, 255))
@@ -32,16 +37,24 @@
         self.aq_explicit = self
         self.fakepath = fakepath
 
+    security.declarePublic('getPhysicalPath')
     def getPhysicalPath(self):
+        """ """
         fakepath = self.fakepath.split('/')
         fakepath.append(self.id)
         return fakepath
 
+    security.declarePublic('getId')
     def getId(self):
+        """ """
         return self.id
 
+    security.declarePublic('absolute_url')
     def absolute_url(self, relative=0):
+        """ """
         return self.fakepath
+
+InitializeClass(Dummy)
     
 
 class FileCacheTestBase(unittest.TestCase):
@@ -52,25 +65,38 @@
         self.all_files = (self.f1, self.f2)
         
     def tearDown(self):
-        # might leave some empty directories lying around, ugh.
-        for f in self.all_files:
-            fpath = self.FC._fileName(f)
-            try:
-                os.unlink(fpath)
-            except OSError:
-                pass
+        for root, dirs, files in os.walk(FCM_DIR, topdown=False):
+            for name in files:
+                os.unlink(os.path.join(root, name))
+            for name in dirs:
+                os.rmdir(os.path.join(root, name))
 
 
 class FileCacheTests(FileCacheTestBase):
 
     def testInstantiation(self):
         self.assertEqual(self.FC.getDir(), FCM_DIR)
+        self.assertEqual(self.FC._naming_expr, None)
 
     def testGetSetDir(self):
         self.assertEqual(self.FC.getDir(), FCM_DIR)
         self.FC.setDir('/tmp')
         self.assertEqual(self.FC.getDir(), '/tmp')
 
+    def testGetSetNamingExpression(self):
+        # By default, no naming expression is used
+        self.assertEqual(self.FC._naming_expr, None)
+
+        # Set an invalid TAL naming expression, no change should occur
+        self.FC.setNamingExpression('foo: 1+1')
+        self.assertEqual(self.FC._naming_expr, None)
+
+        # Set a valid expression
+        expr = "python: '%s.txt' % (object.getId())"
+        self.FC.setNamingExpression(expr)
+        self.assert_(self.FC._naming_expr != None)
+        self.assert_(isinstance(self.FC._naming_expr, PythonExpr))
+
     def testZCache_set(self):
         # First, test against the standard non-TAL-Expression munger
         for ob in self.all_files:
@@ -122,6 +148,14 @@
 
     def setUp(self):
         self.FCM = FileCacheManager(FCM_ID, path=FCM_DIR, title=FCM_TITLE)
+
+    def tearDown(self):
+        for root, dirs, files in os.walk(FCM_DIR, topdown=False):
+            for name in files:
+                os.unlink(os.path.join(root, name))
+            for name in dirs:
+                os.rmdir(os.path.join(root, name))
+
 
 class FileCacheManagerTests(FileCacheManagerTestBase):
 



More information about the Zope-CVS mailing list