Commit 7f486435 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_interface_post: test that Entity_sendEmail can retry on failure

But only one mail will be sent out by MailHost
parent e8c4f503
...@@ -28,6 +28,7 @@ import email ...@@ -28,6 +28,7 @@ import email
import time import time
from Products.ERP5Type.tests.ERP5TypeLiveTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeLiveTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript, removeZODBPythonScript
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
from DateTime import DateTime from DateTime import DateTime
...@@ -81,6 +82,14 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -81,6 +82,14 @@ class TestInterfacePost(ERP5TypeTestCase):
module = getattr(self.portal, module_id) module = getattr(self.portal, module_id)
module.manage_delObjects(list(module.objectIds())) module.manage_delObjects(list(module.objectIds()))
custom_skin = self.portal.portal_skins.custom
if 'Entity_sendEmail' in custom_skin.objectIds():
removeZODBPythonScript(
custom_skin,
'Entity_sendEmail',
)
self.commit()
def _portal_catalog(self, **kw): def _portal_catalog(self, **kw):
result_list = self.portal.portal_catalog(**kw) result_list = self.portal.portal_catalog(**kw)
uid_list = [x.uid for x in result_list] uid_list = [x.uid for x in result_list]
...@@ -333,6 +342,21 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -333,6 +342,21 @@ class TestInterfacePost(ERP5TypeTestCase):
pdf_document, = pdf_document_list pdf_document, = pdf_document_list
self.assertEqual(2, int(pdf_document.getContentInformation()['Pages'])) self.assertEqual(2, int(pdf_document.getContentInformation()['Pages']))
def stepMakeEntitySendEmailFailOnce(self, sequence=None):
createZODBPythonScript(
self.portal.portal_skins.custom,
'Entity_sendEmail',
self.portal.Entity_sendEmail.params(),
"""portal = context.getPortalObject()
for activity in portal.portal_activities.getMessageList():
if activity.method_id == script.id:
if activity.retry == 0:
raise ValueError('Failure on purpose')
else:
return context.skinSuper('custom', script.id)(%s)""" % (self.portal.Entity_sendEmail.params(),)
)
def test_emailSendingIsPilotedByInternetMessagePost(self): def test_emailSendingIsPilotedByInternetMessagePost(self):
""" """
""" """
...@@ -392,6 +416,27 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -392,6 +416,27 @@ class TestInterfacePost(ERP5TypeTestCase):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def test_Entity_sendEmailCanRaiseOnceWithoutSpammingRecipient(self):
"""
Entity_sendEmail used to be launched in an activity with retry_max=0 and
retry_conflict=False. But now that it creates Internet Message Posts, it
should be able to retry on ConflictError. We should also make sure that
in this case the mail isn't sent (as MailHost isn't transactional)
"""
sequence_list = SequenceList()
sequence_string = """
stepMakeEntitySendEmailFailOnce
stepCreateMailMessage
stepStartMailMessage
stepCheckMailMessage
stepTic
stepCheckInternetMessagePostCreated
stepCheckOnlyOneMessageHasBeenSentFromMailHost
stepCheckLatestMessageListFromMailHost
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_ingestedInternetMessagePostCreateMailMessageWithCausality(self): def test_ingestedInternetMessagePostCreateMailMessageWithCausality(self):
sequence_list = SequenceList() sequence_list = SequenceList()
sequence_string = """ sequence_string = """
......
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