Commit 7e503f59 authored by Rafael Monnerat's avatar Rafael Monnerat

Added more tests for _getTypeBaseMethod, including call the scripts.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35661 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d97fa19d
...@@ -38,11 +38,23 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase,\ ...@@ -38,11 +38,23 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase,\
_getConversionServerDict _getConversionServerDict
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.Base import Base
from zExceptions import BadRequest from zExceptions import BadRequest
from Products.ERP5Type.tests.backportUnittest import skip from Products.ERP5Type.tests.backportUnittest import skip
from Products.ERP5Type.Tool.ClassTool import _aq_reset from Products.ERP5Type.Tool.ClassTool import _aq_reset
from Products.ERP5Type.Workflow import addWorkflowByType from Products.ERP5Type.Workflow import addWorkflowByType
def getDummyTypeBaseMethod(self):
""" Use a type Base method
"""
script = self._getTypeBasedMethod('getDummyTypeBaseMethod')
if script is not None:
return script()
return "Script Not Found"
Base.getDummyTypeBaseMethod = getDummyTypeBaseMethod
class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional): class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
run_all_test = 1 run_all_test = 1
...@@ -1103,27 +1115,27 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -1103,27 +1115,27 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
'Base_fooMethod', 'Base_fooMethod',
'scripts_params=None', 'scripts_params=None',
'# Script body\n' '# Script body\n'
'return "something"' ) 'return context.getId()' )
xml_object_script = createZODBPythonScript(portal.portal_skins.custom, xml_object_script = createZODBPythonScript(portal.portal_skins.custom,
'XMLObject_dummyMethod', 'XMLObject_dummyMethod',
'scripts_params=None', 'scripts_params=None',
'# Script body\n' '# Script body\n'
'return "something"' ) 'return context.getId()' )
person_script = createZODBPythonScript(portal.portal_skins.custom, person_script = createZODBPythonScript(portal.portal_skins.custom,
'Person_dummyMethod', 'Person_dummyMethod',
'scripts_params=None', 'scripts_params=None',
'# Script body\n' '# Script body\n'
'return "something"' ) 'return context.getId()' )
copy_container_script = createZODBPythonScript(portal.portal_skins.custom, copy_container_script = createZODBPythonScript(portal.portal_skins.custom,
'CopyContainer_dummyFooMethod', 'CopyContainer_dummyFooMethod',
'scripts_params=None', 'scripts_params=None',
'# Script body\n' '# Script body\n'
'return "something"' ) 'return context.getId()' )
cmfbtree_folder_script = createZODBPythonScript(portal.portal_skins.custom, cmfbtree_folder_script = createZODBPythonScript(portal.portal_skins.custom,
'CMFBTreeFolder_dummyFoo2Method', 'CMFBTreeFolder_dummyFoo2Method',
'scripts_params=None', 'scripts_params=None',
'# Script body\n' '# Script body\n'
'return "something"' ) 'return context.getId()' )
org = portal.organisation_module.newContent(portal_type='Organisation') org = portal.organisation_module.newContent(portal_type='Organisation')
pers = portal.person_module.newContent(portal_type='Person') pers = portal.person_module.newContent(portal_type='Person')
...@@ -1133,7 +1145,37 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -1133,7 +1145,37 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual(pers._getTypeBasedMethod('fooMethod'), base_script) self.assertEqual(pers._getTypeBasedMethod('fooMethod'), base_script)
self.assertEqual(org._getTypeBasedMethod('dummyFooMethod'), None) self.assertEqual(org._getTypeBasedMethod('dummyFooMethod'), None)
self.assertEqual(org._getTypeBasedMethod('dummyFoo2Method'), None) self.assertEqual(org._getTypeBasedMethod('dummyFoo2Method'), None)
# Call the scripts to make sure the context are appropriated.
self.assertEqual(org._getTypeBasedMethod('dummyMethod')(), org.getId())
self.assertEqual(pers._getTypeBasedMethod('dummyMethod')(), pers.getId())
self.assertEqual(org._getTypeBasedMethod('fooMethod')(), org.getId())
self.assertEqual(pers._getTypeBasedMethod('fooMethod')(), pers.getId())
self.assertEqual(pers.getDummyTypeBaseMethod(), "Script Not Found")
person_dummy_script = createZODBPythonScript(portal.portal_skins.custom,
'Person_getDummyTypeBaseMethod',
'scripts_params=None',
'# Script body\n'
'return context.getId()' )
dummy_script_by_activity = createZODBPythonScript(portal.portal_skins.custom,
'Person_getDummyTypeBaseMethodByActivity',
'scripts_params=None',
'# Script body\n'
'context.getDummyTypeBaseMethod()\n'
'return context.getDummyTypeBaseMethod()' )
transaction.commit() # Flush transactional cache.
self.assertEqual(pers.getDummyTypeBaseMethod(), pers.getId())
# Call once more to check cache.
self.assertEqual(pers.getDummyTypeBaseMethod(), pers.getId())
pers.activate().Person_getDummyTypeBaseMethodByActivity()
self.stepTic()
def test_translate_table(self): def test_translate_table(self):
"""check if Person portal type that is installed in erp5_base is """check if Person portal type that is installed in erp5_base is
well indexed in translate table or not. well indexed in translate table or not.
......
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