[Zope-CVS] CVS: Products/FileCacheManager/tests - stresstest.py:1.2

Jens Vagelpohl jens at dataflake.org
Tue Aug 17 05:18:18 EDT 2004


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

Modified Files:
	stresstest.py 
Log Message:
- expand stresstest script to add images as content


=== Products/FileCacheManager/tests/stresstest.py 1.1 => 1.2 ===
--- Products/FileCacheManager/tests/stresstest.py:1.1	Mon Aug 16 06:03:09 2004
+++ Products/FileCacheManager/tests/stresstest.py	Tue Aug 17 05:17:47 2004
@@ -16,7 +16,12 @@
 
 import ZODB
 from ZODB.MappingStorage import MappingStorage
-from OFS.Folder import Folder
+from AccessControl.SecurityManagement import newSecurityManager
+from AccessControl.SecurityManagement import noSecurityManager
+from AccessControl.User import UnrestrictedUser
+from Globals import package_home
+from OFS.Folder import Folder, manage_addFolder
+from OFS.Image import manage_addImage
 from Products.PythonScripts.PythonScript import manage_addPythonScript
 
 from Products.FileCacheManager import FileCacheManager
@@ -24,6 +29,16 @@
 FCM_ID = 'fcm1'
 PYSCRIPT_ID = 'ps1'
 ROOT = None
+IMAGES = {}
+PROD_DIR = os.path.join(os.getcwd(), 'Products', 'FileCacheManager')
+IMAGE_DIR = os.path.join(PROD_DIR, 'tests', 'images')
+
+for test_file in os.listdir(IMAGE_DIR):
+    full_path = os.path.join(IMAGE_DIR, test_file)
+    if os.path.isfile(full_path):
+        fh = open(full_path, 'rb')
+        IMAGES[test_file] = fh.read()
+        fh.close()
 
 ######################
 # Tweakable items
@@ -47,6 +62,9 @@
     global ROOT
     ROOT = app_root.get('testing')
 
+    # Set up a Security Manager so we do everything as a manager
+    newSecurityManager(None, UnrestrictedUser('manager', '', ['Manager'], []))
+
     # Now stick a FileCacheManager object into our testing root
     factory = FileCacheManager.manage_addFileCacheManager
     factory(ROOT, FCM_ID, path=FCM_DIR, title='Testing FCM')
@@ -62,6 +80,32 @@
     pyscript.ZPythonScript_edit(PYSCRIPT_PARAMS, PYSCRIPT_BODY)
     assert pyscript.params() == PYSCRIPT_PARAMS
     assert pyscript.body() == PYSCRIPT_BODY.strip()
+
+    # Set up a series of folders for storing content
+    # and store content in it.
+    for i in range(1, 11):
+        folder_id = 'folder_%d' % i
+        manage_addFolder(ROOT, folder_id)
+        folder_ob = getattr(ROOT, folder_id)
+
+        for id, content in IMAGES.items():
+            manage_addImage(folder_ob, id, content)
+
+        assert len(folder_ob.objectIds()) == len(IMAGES.keys())
+
+    assert len(ROOT.objectIds(['Folder'])) == 10
+
+    # Now find and associate cacheable objects
+    # That ZCacheable API is a PITA
+    cacheables = fcm.ZCacheManager_locate(0, 1, meta_types=['Image', 'File'])
+    to_be_cached = {}
+    for cacheable in cacheables:
+        to_be_cached['associate_%s' % cacheable['path']] = 1
+    fcm.ZCacheManager_setAssociations(props=to_be_cached)
+
+    # Remove the Security Manager for now
+    noSecurityManager()
+
 
 def tearDown():
     for root, dirs, files in os.walk(FCM_DIR, topdown=False):



More information about the Zope-CVS mailing list