Commit 170ef4c7 authored by Jérome Perrin's avatar Jérome Perrin

Use utility function createZODBPythonScript

set quiet to true, to prevent unnecessary debugging messages.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8481 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 283f7d8a
...@@ -40,6 +40,7 @@ os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log') ...@@ -40,6 +40,7 @@ os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300' os.environ['EVENT_LOG_SEVERITY'] = '-300'
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG from zLOG import LOG
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
...@@ -50,6 +51,7 @@ GROUP_STOREVER_PATH = 'group/nexedi/storever' ...@@ -50,6 +51,7 @@ GROUP_STOREVER_PATH = 'group/nexedi/storever'
GROUP_OTHER_PATH = 'group/other' GROUP_OTHER_PATH = 'group/other'
RUN_ALL_TESTS = 1 RUN_ALL_TESTS = 1
QUIET = 1
PREDICATE_FOLDER_NAME = "predicate_unit_test_folder" PREDICATE_FOLDER_NAME = "predicate_unit_test_folder"
class TestPredicates(ERP5TypeTestCase): class TestPredicates(ERP5TypeTestCase):
...@@ -71,10 +73,10 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -71,10 +73,10 @@ class TestPredicates(ERP5TypeTestCase):
self.login() self.login()
# XXX ... this method is a copy / paste # XXX ... this method is a copy / paste
def playSequence(self, sequence_string) : def playSequence(self, sequence_string, quiet=QUIET) :
sequence_list = SequenceList() sequence_list = SequenceList()
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self, quiet=QUIET)
# XXX ... this method is a copy / paste # XXX ... this method is a copy / paste
def createCategories(self): def createCategories(self):
...@@ -121,26 +123,16 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -121,26 +123,16 @@ class TestPredicates(ERP5TypeTestCase):
predicate_folder.allowedContentTypes()]) predicate_folder.allowedContentTypes()])
return predicate_folder return predicate_folder
def createPythonScript(self, method_id, script_params, script_content):
"""Generic method to create a python script"""
folder = self.getPortal().portal_skins.erp5_base
if method_id in folder.objectIds():
folder.manage_delObjects([method_id])
folder.manage_addProduct['PythonScripts']\
.manage_addPythonScript(id = method_id)
script = folder[method_id]
script.ZPythonScript_edit(script_params, script_content)
self.getPortal().changeSkin(None)
def stepCreatePredicateTrueScript(self, sequence=None, **kw) : def stepCreatePredicateTrueScript(self, sequence=None, **kw) :
"""Creates a script that always return true""" """Creates a script that always return true"""
self.createPythonScript('Predicate_true', '', """return 1""") createZODBPythonScript(self.getPortal().portal_skins.erp5_base,
'Predicate_true', '', """return 1""")
sequence.edit(test_method_id = 'Predicate_true') sequence.edit(test_method_id = 'Predicate_true')
def stepCreatePredicateFalseScript(self, sequence=None, **kw) : def stepCreatePredicateFalseScript(self, sequence=None, **kw) :
"""Creates a script that always return false""" """Creates a script that always return false"""
self.createPythonScript('Predicate_false', '', """return 0""") createZODBPythonScript(self.getPortal().portal_skins.erp5_base,
'Predicate_false', '', """return 0""")
sequence.edit(test_method_id = 'Predicate_false') sequence.edit(test_method_id = 'Predicate_false')
def createPredicate(self, **kw): def createPredicate(self, **kw):
...@@ -277,7 +269,7 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -277,7 +269,7 @@ class TestPredicates(ERP5TypeTestCase):
## Test Methods ############################################################ ## Test Methods ############################################################
############################################################################ ############################################################################
def test_Interface(self, quiet=0, run=RUN_ALL_TESTS): def test_Interface(self, quiet=QUIET, run=RUN_ALL_TESTS):
"""Test Predicate implements Predicate interface.""" """Test Predicate implements Predicate interface."""
if not run : return if not run : return
from Products.ERP5Type.Interface import Predicate as IPredicate from Products.ERP5Type.Interface import Predicate as IPredicate
...@@ -287,7 +279,7 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -287,7 +279,7 @@ class TestPredicates(ERP5TypeTestCase):
from Interface.Verify import verifyClass from Interface.Verify import verifyClass
verifyClass(IPredicate, Predicate) verifyClass(IPredicate, Predicate)
def test_CategoryMembership(self, quiet=0, run=RUN_ALL_TESTS): def test_CategoryMembership(self, quiet=QUIET, run=RUN_ALL_TESTS):
"""Test basic category membership""" """Test basic category membership"""
if not run : return if not run : return
self.playSequence(""" self.playSequence("""
...@@ -306,7 +298,7 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -306,7 +298,7 @@ class TestPredicates(ERP5TypeTestCase):
stepAssertPredicateFalse stepAssertPredicateFalse
""") """)
def test_EmptyPredicates(self, quiet=0, run=RUN_ALL_TESTS): def test_EmptyPredicates(self, quiet=QUIET, run=RUN_ALL_TESTS):
"""Test empty and always false predicates.""" """Test empty and always false predicates."""
if not run : return if not run : return
self.playSequence(""" self.playSequence("""
...@@ -317,7 +309,7 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -317,7 +309,7 @@ class TestPredicates(ERP5TypeTestCase):
stepAssertPredicateFalse stepAssertPredicateFalse
""") """)
def test_TestMethodId(self, quiet=0, run=RUN_ALL_TESTS): def test_TestMethodId(self, quiet=QUIET, run=RUN_ALL_TESTS):
"""Test test_method_id attribute.""" """Test test_method_id attribute."""
if not run : return if not run : return
self.playSequence(""" self.playSequence("""
...@@ -337,7 +329,7 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -337,7 +329,7 @@ class TestPredicates(ERP5TypeTestCase):
stepAssertPredicateFalse stepAssertPredicateFalse
""") """)
def test_PredicateFusion(self, quiet=0, run=RUN_ALL_TESTS): def test_PredicateFusion(self, quiet=QUIET, run=RUN_ALL_TESTS):
"""Test simple predicates fusion. """Test simple predicates fusion.
New predicate act as a logical AND between predicates New predicate act as a logical AND between predicates
""" """
...@@ -365,7 +357,7 @@ class TestPredicates(ERP5TypeTestCase): ...@@ -365,7 +357,7 @@ class TestPredicates(ERP5TypeTestCase):
stepAssertPredicateFalse stepAssertPredicateFalse
""") """)
def test_PredicateFusionAndTestMethodId(self, quiet=0, run=RUN_ALL_TESTS): def test_PredicateFusionAndTestMethodId(self, quiet=QUIET, run=RUN_ALL_TESTS):
"""Test predicates fusion and test_method_id attribute.""" """Test predicates fusion and test_method_id attribute."""
if not run : return if not run : return
self.playSequence(""" self.playSequence("""
......
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