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
from Products.ERP5Type.tests.ERP5TypeLiveTestCase import ERP5TypeLiveTestCase
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.tests.utils import createZODBPythonScript, removeZODBPythonScript
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
from DateTime import DateTime
......@@ -47,9 +48,15 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
"""
This is ran before anything, used to set the environment
"""
self._setupLetterPostExportPythonScript()
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
# and creation_date of new documents, otherwise they won't be found by catalog
# during the fatest test sequences
......@@ -69,24 +76,14 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
self.recipient_list = [self.recipient,]
def beforeTearDown(self):
self._removeLetterPostExportPythonScript()
def _setupLetterPostExportPythonScript(self):
skin_folder = self.portal.portal_skins.custom
script_id = "LetterPost_export"
script = getattr(skin_folder, script_id, None)
if script is None:
skin_folder.manage_addProduct['PythonScripts']\
.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')
removeZODBPythonScript(
self.portal.portal_skins.custom,
"LetterPost_export"
)
for module_id in ('event_module', 'internet_message_post_module', 'letter_post_module'):
module = self.portal[module_id]
module.manage_delObjects(module.objectIds())
def _portal_catalog(self, **kw):
result_list = self.portal.portal_catalog(**kw)
......@@ -202,6 +199,9 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
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):
last_message, = self.portal.MailHost._message_list
self.assertNotEquals((), last_message)
......@@ -216,37 +216,42 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
mail_message.MailMessage_viewPreview.my_text_content.render(),
)
def test_onlyOneExportablePostIsExported(self):
def test_emailSendingIsPilotedByInternetMessagePost(self):
"""
"""
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 = """
stepCreateLetterPost
stepCreateLetterPost
stepCreateLetterPost
stepTic
stepAllowExportOfAllLetterPost
stepCreateMailMessage
stepStartMailMessage
stepTic
stepCheckOnlyOneLetterPostIsExported
stepCheckMailMessage
stepCheckInternetMessagePostCreated
stepCheckOnlyOneMessageHasBeenSentFromMailHost
stepCheckLatestMessageFromMailHost
"""
sequence_list.addSequenceString(sequence_string)
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()
# With 3 Letter Posts, we can trigger a race condition where 2 letters
# disallow export of each other, thus nothing is exported.
sequence_string = """
stepCreateMailMessage
stepStartMailMessage
stepCreateLetterPost
stepCreateLetterPost
stepCreateLetterPost
stepTic
stepCheckMailMessage
stepCheckInternetMessagePostCreated
stepCheckLatestMessageFromMailHost
stepAllowExportOfAllLetterPost
stepTic
stepCheckOnlyOneLetterPostIsExported
"""
sequence_list.addSequenceString(sequence_string)
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