Commit ef42d24a authored by Nicolas Delaby's avatar Nicolas Delaby

Refactor Test

  * make tests independant each other
  * add Interface cheking test


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27015 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5c929d3c
...@@ -55,6 +55,11 @@ class TestCacheTool(ERP5TypeTestCase): ...@@ -55,6 +55,11 @@ class TestCacheTool(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
self.checkCacheTool()
self.checkPortalTypes()
self.createCacheFactories()
self.createCachedMethod()
transaction.commit()
def login(self): def login(self):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
...@@ -63,12 +68,11 @@ class TestCacheTool(ERP5TypeTestCase): ...@@ -63,12 +68,11 @@ class TestCacheTool(ERP5TypeTestCase):
user = uf.getUserById('admin').__of__(uf) user = uf.getUserById('admin').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def test_01_CheckCacheTool(self): def checkCacheTool(self):
portal = self.getPortal() portal = self.getPortal()
self.assertNotEqual(None, getattr(portal, 'portal_caches', None)) self.assertNotEqual(None, getattr(portal, 'portal_caches', None))
transaction.commit()
def test_02_CheckPortalTypes(self): def checkPortalTypes(self):
portal = self.getPortal() portal = self.getPortal()
portal_types = portal.portal_types portal_types = portal.portal_types
typeinfo_names = ("Cache Factory", typeinfo_names = ("Cache Factory",
...@@ -80,71 +84,71 @@ class TestCacheTool(ERP5TypeTestCase): ...@@ -80,71 +84,71 @@ class TestCacheTool(ERP5TypeTestCase):
for typeinfo_name in typeinfo_names: for typeinfo_name in typeinfo_names:
portal_type = getattr(portal_types, typeinfo_name, None) portal_type = getattr(portal_types, typeinfo_name, None)
self.assertNotEqual(None, portal_type) self.assertNotEqual(None, portal_type)
transaction.commit()
def test_03_CreateCacheFactories(self): def createCacheFactories(self):
portal = self.getPortal() portal = self.getPortal()
portal_caches = portal.portal_caches portal_caches = portal.portal_caches
# Cache plugins are organised into 'Cache factories' so we create # Cache plugins are organised into 'Cache factories' so we create
# factories first ram_cache_factory (to test Ram Cache Plugin) # factories first ram_cache_factory (to test Ram Cache Plugin)
ram_cache_factory = portal_caches.newContent(portal_type="Cache Factory", if getattr(portal_caches, 'ram_cache_factory', None) is None:
id='ram_cache_factory', ram_cache_factory = portal_caches.newContent(portal_type="Cache Factory",
container=portal_caches) id='ram_cache_factory',
ram_cache_plugin = ram_cache_factory.newContent(portal_type="Ram Cache", container=portal_caches)
container=ram_cache_factory) ram_cache_plugin = ram_cache_factory.newContent(portal_type="Ram Cache",
ram_cache_plugin.setIntIndex(0) container=ram_cache_factory)
ram_cache_plugin.setIntIndex(0)
## distributed_ram_cache_factory (to test Distributed Ram Cache Plugin) if getattr(portal_caches, 'distributed_ram_cache_factory', None) is None:
dram_cache_factory = portal_caches.newContent(portal_type="Cache Factory", ## distributed_ram_cache_factory (to test Distributed Ram Cache Plugin)
id='distributed_ram_cache_factory', dram_cache_factory = portal_caches.newContent(portal_type="Cache Factory",
container=portal_caches) id='distributed_ram_cache_factory',
dram_cache_plugin = dram_cache_factory.newContent( container=portal_caches)
portal_type="Distributed Ram Cache", container=dram_cache_factory) dram_cache_plugin = dram_cache_factory.newContent(
dram_cache_plugin.setIntIndex(0) portal_type="Distributed Ram Cache", container=dram_cache_factory)
dram_cache_plugin.setIntIndex(0)
## sql_cache_factory (to test SQL Cache Plugin)
sql_cache_factory = portal_caches.newContent(portal_type="Cache Factory", if getattr(portal_caches, 'sql_cache_factory', None) is None:
id='sql_cache_factory', ## sql_cache_factory (to test SQL Cache Plugin)
container=portal_caches) sql_cache_factory = portal_caches.newContent(portal_type="Cache Factory",
sql_cache_plugin = sql_cache_factory.newContent( id='sql_cache_factory',
portal_type="SQL Cache", container=sql_cache_factory) container=portal_caches)
sql_cache_plugin.setIntIndex(0) sql_cache_plugin = sql_cache_factory.newContent(
portal_type="SQL Cache", container=sql_cache_factory)
## zodb_cache_factory (to test ZODB Cache Plugin) sql_cache_plugin.setIntIndex(0)
zodb_cache_factory = portal_caches.newContent(portal_type="Cache Factory",
id='zodb_cache_factory', if getattr(portal_caches, 'zodb_cache_factory', None) is None:
container=portal_caches) ## zodb_cache_factory (to test ZODB Cache Plugin)
zodb_cache_plugin = zodb_cache_factory.newContent( zodb_cache_factory = portal_caches.newContent(portal_type="Cache Factory",
portal_type="Zodb Cache", container=zodb_cache_factory) id='zodb_cache_factory',
zodb_cache_plugin.setIntIndex(0) container=portal_caches)
zodb_cache_plugin = zodb_cache_factory.newContent(
## erp5_user_factory (to test a combination of all cache plugins) portal_type="Zodb Cache", container=zodb_cache_factory)
erp5_user_factory = portal_caches.newContent(portal_type="Cache Factory", zodb_cache_plugin.setIntIndex(0)
id="erp5_user_factory",
container=portal_caches) if getattr(portal_caches, 'erp5_user_factory', None) is None:
ram_cache_plugin = erp5_user_factory.newContent( ## erp5_user_factory (to test a combination of all cache plugins)
portal_type="Ram Cache", container=erp5_user_factory) erp5_user_factory = portal_caches.newContent(portal_type="Cache Factory",
ram_cache_plugin.setIntIndex(0) id="erp5_user_factory",
dram_cache_plugin = erp5_user_factory.newContent( container=portal_caches)
portal_type="Distributed Ram Cache", container=erp5_user_factory)
dram_cache_plugin.setIntIndex(1) ram_cache_plugin = erp5_user_factory.newContent(
sql_cache_plugin = erp5_user_factory.newContent( portal_type="Ram Cache", container=erp5_user_factory)
portal_type="SQL Cache", container=erp5_user_factory) ram_cache_plugin.setIntIndex(0)
sql_cache_plugin.setIntIndex(2) dram_cache_plugin = erp5_user_factory.newContent(
zodb_cache_plugin = erp5_user_factory.newContent( portal_type="Distributed Ram Cache", container=erp5_user_factory)
portal_type="Zodb Cache", container=erp5_user_factory) dram_cache_plugin.setIntIndex(1)
zodb_cache_plugin.setIntIndex(3) sql_cache_plugin = erp5_user_factory.newContent(
portal_type="SQL Cache", container=erp5_user_factory)
## sql_cache_plugin.setIntIndex(2)
transaction.commit() zodb_cache_plugin = erp5_user_factory.newContent(
portal_type="Zodb Cache", container=erp5_user_factory)
zodb_cache_plugin.setIntIndex(3)
## update Ram Cache structure ## update Ram Cache structure
portal_caches.updateCache() portal_caches.updateCache()
## commit PersistantMapping for zodb_cache
transaction.commit()
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
## do we have the same structure we created above? ## do we have the same structure we created above?
...@@ -154,9 +158,10 @@ class TestCacheTool(ERP5TypeTestCase): ...@@ -154,9 +158,10 @@ class TestCacheTool(ERP5TypeTestCase):
self.assert_('zodb_cache_factory' in CachingMethod.factories) self.assert_('zodb_cache_factory' in CachingMethod.factories)
self.assert_('erp5_user_factory' in CachingMethod.factories) self.assert_('erp5_user_factory' in CachingMethod.factories)
def test_04_CreateCachedMethod(self): def createCachedMethod(self):
portal = self.getPortal() portal = self.getPortal()
if getattr(portal, 'testCachedMethod', None) is not None:
return
## add test cached method ## add test cached method
py_script_id = "testCachedMethod" py_script_id = "testCachedMethod"
py_script_params = "value=10000, portal_path=('','erp5')" py_script_params = "value=10000, portal_path=('','erp5')"
...@@ -177,9 +182,8 @@ return result ...@@ -177,9 +182,8 @@ return result
id=py_script_id) id=py_script_id)
py_script_obj = getattr(portal, py_script_id) py_script_obj = getattr(portal, py_script_id)
py_script_obj.ZPythonScript_edit(py_script_params, py_script_body) py_script_obj.ZPythonScript_edit(py_script_params, py_script_body)
transaction.commit()
def test_05_CacheFactoryOnePlugin(self): def test_01_CacheFactoryOnePlugin(self):
""" Test cache factory containing only one cache plugin. """ """ Test cache factory containing only one cache plugin. """
portal = self.getPortal() portal = self.getPortal()
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
...@@ -194,7 +198,7 @@ return result ...@@ -194,7 +198,7 @@ return result
cache_factory=cf_name) cache_factory=cf_name)
self._cacheFactoryInstanceTest(my_cache, cf_name) self._cacheFactoryInstanceTest(my_cache, cf_name)
def test_06_CacheFactoryMultiPlugins(self): def test_02_CacheFactoryMultiPlugins(self):
""" Test a cache factory containing multiple cache plugins. """ """ Test a cache factory containing multiple cache plugins. """
portal = self.getPortal() portal = self.getPortal()
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
...@@ -252,7 +256,7 @@ return result ...@@ -252,7 +256,7 @@ return result
## Cache cleared shouldn't be previously cached ## Cache cleared shouldn't be previously cached
self.assert_(1.0 < calculation_time) self.assert_(1.0 < calculation_time)
def test_CachePersistentObjects(self): def test_03_cachePersistentObjects(self):
# storing persistent objects in cache is not allowed, but this check is # storing persistent objects in cache is not allowed, but this check is
# only performed in unit tests. # only performed in unit tests.
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
...@@ -268,6 +272,21 @@ return result ...@@ -268,6 +272,21 @@ return result
cached_func = CachingMethod(func, 'cache_bound_method') cached_func = CachingMethod(func, 'cache_bound_method')
self.assertRaises(TypeError, cached_func) self.assertRaises(TypeError, cached_func)
def test_04_CachePluginInterface(self):
"""Test Class against Interface
"""
from Products.ERP5Type.CachePlugins.DistributedRamCache import DistributedRamCache
from Products.ERP5Type.CachePlugins.RamCache import RamCache
from Products.ERP5Type.CachePlugins.SQLCache import SQLCache
from Products.ERP5Type.CachePlugins.ZODBCache import ZODBCache
from Products.ERP5Type.Interface.ICachePlugin import ICachePlugin
from Interface.Verify import verifyClass
verifyClass(ICachePlugin, ZODBCache)
verifyClass(ICachePlugin, DistributedRamCache)
verifyClass(ICachePlugin, RamCache)
verifyClass(ICachePlugin, SQLCache)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCacheTool)) suite.addTest(unittest.makeSuite(TestCacheTool))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment