Commit b2ad5dad authored by Nicolas Delaby's avatar Nicolas Delaby

Cleanup test

  * harmonize indentation
  * import transaction
  * remove quiet and run_all_test variables
  * cosmetic changes


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26973 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1fc28dcf
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -34,11 +35,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase ...@@ -34,11 +35,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.CachePlugins.DummyCache import DummyCache from Products.ERP5Type.CachePlugins.DummyCache import DummyCache
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG from zLOG import LOG
import transaction
try:
from transaction import get as get_transaction
except ImportError:
pass
class TestingCache(DummyCache): class TestingCache(DummyCache):
"""A dummy cache that mark cache miss, so that you can later count access """A dummy cache that mark cache miss, so that you can later count access
...@@ -53,42 +50,25 @@ class TestingCache(DummyCache): ...@@ -53,42 +50,25 @@ class TestingCache(DummyCache):
class TestCacheTool(ERP5TypeTestCase): class TestCacheTool(ERP5TypeTestCase):
run_all_test = 1
def getTitle(self): def getTitle(self):
return "Cache Tool" return "Cache Tool"
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
def login(self, quiet=0, run=run_all_test): def login(self):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('seb', '', ['Manager'], []) uf._doAddUser('admin', '', ['Manager'], [])
uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], []) uf._doAddUser('ERP5TypeTestCase', '', ['Manager'], [])
user = uf.getUserById('seb').__of__(uf) user = uf.getUserById('admin').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def test_01_CheckCacheTool(self, quiet=0, run=run_all_test): def test_01_CheckCacheTool(self):
if not run:
return
if not quiet:
message = '\nCheck CacheTool '
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal() portal = self.getPortal()
self.assertNotEqual(None,getattr(portal,'portal_caches',None)) self.assertNotEqual(None,getattr(portal,'portal_caches',None))
get_transaction().commit() transaction.commit()
def test_02_CheckPortalTypes(self, quiet=0, run=run_all_test):
if not run:
return
if not quiet:
message = '\nCheck Portal Types'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
def test_02_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",
...@@ -99,15 +79,9 @@ class TestCacheTool(ERP5TypeTestCase): ...@@ -99,15 +79,9 @@ 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)
get_transaction().commit() transaction.commit()
def test_03_CreateCacheFactories(self, quiet=0, run=run_all_test): def test_03_CreateCacheFactories(self):
if not run:
return
if not quiet:
message = '\nCreate Cache Tool Factories'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal() portal = self.getPortal()
portal_caches = portal.portal_caches portal_caches = portal.portal_caches
...@@ -153,7 +127,7 @@ class TestCacheTool(ERP5TypeTestCase): ...@@ -153,7 +127,7 @@ class TestCacheTool(ERP5TypeTestCase):
sql_cache_plugin.setIntIndex(2) sql_cache_plugin.setIntIndex(2)
## ##
get_transaction().commit() transaction.commit()
## update Ram Cache structure ## update Ram Cache structure
portal_caches.updateCache() portal_caches.updateCache()
...@@ -165,13 +139,7 @@ class TestCacheTool(ERP5TypeTestCase): ...@@ -165,13 +139,7 @@ class TestCacheTool(ERP5TypeTestCase):
self.assert_('sql_cache_factory' in CachingMethod.factories) self.assert_('sql_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, quiet=0, run=run_all_test): def test_04_CreateCachedMethod(self):
if not run:
return
if not quiet:
message = '\nCreate Cache Method (Python Script)'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal() portal = self.getPortal()
## add test cached method ## add test cached method
...@@ -194,16 +162,10 @@ return result ...@@ -194,16 +162,10 @@ 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)
get_transaction().commit() transaction.commit()
def test_05_CacheFactoryOnePlugin(self, quiet=0, run=run_all_test): def test_05_CacheFactoryOnePlugin(self):
""" Test cache factory containing only one cache plugin. """ """ Test cache factory containing only one cache plugin. """
if not run:
return
if not quiet:
message = '\nTest each type of cache plugin individually.'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal() portal = self.getPortal()
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
py_script_id = "testCachedMethod" py_script_id = "testCachedMethod"
...@@ -216,15 +178,8 @@ return result ...@@ -216,15 +178,8 @@ 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, quiet=0, run=run_all_test): def test_06_CacheFactoryMultiPlugins(self):
""" Test a cache factory containing multiple cache plugins. """ """ Test a cache factory containing multiple cache plugins. """
if not run:
return
if not quiet:
message = '\nTest combination of available cache plugins under a cache'\
' factory'
ZopeTestCase._print(message)
LOG('Testing... ',0,message)
portal = self.getPortal() portal = self.getPortal()
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
py_script_id = "testCachedMethod" py_script_id = "testCachedMethod"
...@@ -297,7 +252,6 @@ return result ...@@ -297,7 +252,6 @@ 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_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