Commit 64d3875c authored by Nicolas Wavrant's avatar Nicolas Wavrant

fixup! erp5_interface_post: add test suite

parent dc13fca7
...@@ -28,6 +28,7 @@ import time ...@@ -28,6 +28,7 @@ import time
from Products.ERP5Type.tests.ERP5TypeLiveTestCase import ERP5TypeLiveTestCase from Products.ERP5Type.tests.ERP5TypeLiveTestCase import ERP5TypeLiveTestCase
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.tests.utils import createZODBPythonScript, removeZODBPythonScript
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
from DateTime import DateTime from DateTime import DateTime
...@@ -47,9 +48,15 @@ class TestInterfacePost(ERP5TypeLiveTestCase): ...@@ -47,9 +48,15 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
""" """
This is ran before anything, used to set the environment This is ran before anything, used to set the environment
""" """
self._setupLetterPostExportPythonScript()
self.portal.MailHost.reset() self.portal.MailHost.reset()
createZODBPythonScript(
self.portal.portal_skins.custom,
"LetterPost_export",
"",
"if context.getSimulationState() == 'exportable':\n context.export()",
)
# Make sure to have a difference of at least 1 second between test_launch_date # Make sure to have a difference of at least 1 second between test_launch_date
# and creation_date of new documents, otherwise they won't be found by catalog # and creation_date of new documents, otherwise they won't be found by catalog
# during the fatest test sequences # during the fatest test sequences
...@@ -69,24 +76,14 @@ class TestInterfacePost(ERP5TypeLiveTestCase): ...@@ -69,24 +76,14 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
self.recipient_list = [self.recipient,] self.recipient_list = [self.recipient,]
def beforeTearDown(self): def beforeTearDown(self):
self._removeLetterPostExportPythonScript() removeZODBPythonScript(
self.portal.portal_skins.custom,
def _setupLetterPostExportPythonScript(self): "LetterPost_export"
skin_folder = self.portal.portal_skins.custom )
script_id = "LetterPost_export"
script = getattr(skin_folder, script_id, None) for module_id in ('event_module', 'internet_message_post_module', 'letter_post_module'):
if script is None: module = self.portal[module_id]
skin_folder.manage_addProduct['PythonScripts']\ module.manage_delObjects(module.objectIds())
.manage_addPythonScript(id=script_id)
skin_folder[script_id].write("if context.getSimulationState() == 'exportable':\n context.export()")
self.tic()
def _removeLetterPostExportPythonScript(self):
skin_folder = self.portal.portal_skins.custom
script_id = "LetterPost_export"
script = getattr(skin_folder, script_id, None)
if script is not None:
skin_folder.manage_delObjects('LetterPost_export')
def _portal_catalog(self, **kw): def _portal_catalog(self, **kw):
result_list = self.portal.portal_catalog(**kw) result_list = self.portal.portal_catalog(**kw)
...@@ -202,6 +199,9 @@ class TestInterfacePost(ERP5TypeLiveTestCase): ...@@ -202,6 +199,9 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
internet_message_post.getData()) internet_message_post.getData())
) )
def stepCheckOnlyOneMessageHasBeenSentFromMailHost(self, sequence=None, sequence_list=None):
self.assertEqual(1, self.portal.MailHost.getMessageList())
def stepCheckLatestMessageFromMailHost(self, sequence=None, sequence_list=None): def stepCheckLatestMessageFromMailHost(self, sequence=None, sequence_list=None):
last_message, = self.portal.MailHost._message_list last_message, = self.portal.MailHost._message_list
self.assertNotEquals((), last_message) self.assertNotEquals((), last_message)
...@@ -216,37 +216,42 @@ class TestInterfacePost(ERP5TypeLiveTestCase): ...@@ -216,37 +216,42 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
mail_message.MailMessage_viewPreview.my_text_content.render(), mail_message.MailMessage_viewPreview.my_text_content.render(),
) )
def test_onlyOneExportablePostIsExported(self): def test_emailSendingIsPilotedByInternetMessagePost(self):
""" """
""" """
sequence_list = SequenceList() sequence_list = SequenceList()
# With 3 Letter Posts, we can trigger a race condition where 2 letters
# disallow export of each other, thus nothing is exported.
sequence_string = """ sequence_string = """
stepCreateLetterPost stepCreateMailMessage
stepCreateLetterPost stepStartMailMessage
stepCreateLetterPost
stepTic
stepAllowExportOfAllLetterPost
stepTic stepTic
stepCheckOnlyOneLetterPostIsExported stepCheckMailMessage
stepCheckInternetMessagePostCreated
stepCheckOnlyOneMessageHasBeenSentFromMailHost
stepCheckLatestMessageFromMailHost
""" """
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def test_emailSendingIsPilotedByInternetMessagePost(self): def test_onlyOneExportablePostIsExported(self):
""" """
interface_post_workflow defines "exportable" and "exported" states, as for some portal types
we may stack all new objects, and regularly export them all at once. Ie, for letters, we can
gather them all in a unique PDF and send it to a printer.
As a user may send an Event, then rework on it, and re-send it, it will create 2 Posts for
the same Event. In that case, we want only one of these posts to be exported, and the others
become "unexportable".
""" """
sequence_list = SequenceList() sequence_list = SequenceList()
# With 3 Letter Posts, we can trigger a race condition where 2 letters # With 3 Letter Posts, we can trigger a race condition where 2 letters
# disallow export of each other, thus nothing is exported. # disallow export of each other, thus nothing is exported.
sequence_string = """ sequence_string = """
stepCreateMailMessage stepCreateLetterPost
stepStartMailMessage stepCreateLetterPost
stepCreateLetterPost
stepTic stepTic
stepCheckMailMessage stepAllowExportOfAllLetterPost
stepCheckInternetMessagePostCreated stepTic
stepCheckLatestMessageFromMailHost stepCheckOnlyOneLetterPostIsExported
""" """
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
......
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