Commit 2f84834a authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_interface_post: update test suite

parent a11a81e2
......@@ -24,6 +24,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import email
import time
from Products.ERP5Type.tests.ERP5TypeLiveTestCase import ERP5TypeLiveTestCase
......@@ -181,23 +182,28 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
def stepCheckInternetMessagePostCreated(self, sequence=None, sequence_list=None):
mail_message = sequence['mail_message']
internet_message_post, = mail_message.getAggregateValueList(
internet_message_post_list = mail_message.getAggregateValueList(
portal_type='Internet Message Post')
sequence['internet_message_post'] = internet_message_post
self.assertEqual(len(internet_message_post_list), len(self.recipient_list))
sequence['internet_message_post'] = internet_message_post_list[0]
sequence['internet_message_post_list'] = internet_message_post_list
self.assertEqual(0, len(mail_message.getAggregateDocumentTitleList([])),
"Internet Message Post shouldn't be an attachment"
)
self.assertEqual(internet_message_post.getSimulationState(), 'exported')
self.assertEqual(
internet_message_post.getReference(), mail_message.getReference()
)
self.assertEqual(
mail_message.getTextContent(),
self.portal.Base_getFirstPartFromMultipartMessage(
internet_message_post.getData())
)
for internet_message_post in internet_message_post_list:
self.assertEqual(internet_message_post.getSimulationState(), 'exported')
self.assertEqual(
internet_message_post.getReference(), mail_message.getReference()
)
self.assertEqual(
mail_message.getTextContent(),
self.portal.Base_getFirstPartFromMultipartMessage(
internet_message_post.getData())
)
def stepCheckOnlyOneMessageHasBeenSentFromMailHost(self, sequence=None, sequence_list=None):
self.assertEqual(1, len(self.portal.MailHost.getMessageList()))
......@@ -205,8 +211,29 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
def stepCheckLatestMessageFromMailHost(self, sequence=None, sequence_list=None):
last_message, = self.portal.MailHost._message_list
self.assertNotEquals((), last_message)
_, _, messageText = last_message
self.assertIn(messageText, sequence['internet_message_post'].getData())
_, _, message_text = last_message
self.assertIn(message_text, sequence['internet_message_post'].getData())
def _getMailHostMessageForRecipient(self, recipient_email_address):
message_list = self.portal.MailHost._message_list
result_list = []
for message in message_list:
_, to_list, _ = message
for recipient in to_list:
if recipient_email_address in recipient:
result_list.append(message)
return result_list
def stepCheckLatestMessageListFromMailHost(self, sequence=None, sequence_list=None):
message_list = self.portal.MailHost._message_list
self.assertEqual(len(message_list), len(self.recipient_list))
for post in sequence['internet_message_post_list']:
post_recipient = email.message_from_string(post.getData())['to']
message_list = self._getMailHostMessageForRecipient(post_recipient)
self.assertEqual(len(message_list), 1)
message = message_list[0]
_, _, message_text = message
self.assertIn(message_text, post.getData())
def stepCheckMailMessagePreviewDisplaysLatestInternetMessagePostData(self, sequence=None, sequence_list=None):
mail_message = sequence['mail_message']
......@@ -248,3 +275,29 @@ class TestInterfacePost(ERP5TypeLiveTestCase):
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_sentMailMessageCreateOneInternetMessagePostForEachRecipient(self):
"""
In case of multi recipients for emails, one mail message content is generated
and sent through the MailHost. As the purpose of Internet Message Post is to
track what goes out of ERP5, one Internet Message Post must be created for each
of these mail message contents.
"""
recipient_2 = self.portal.person_module.newContent(
portal_type='Person',
title='recipient_2',
default_email_coordinate_text='recipient_2@nexedi.com',
)
self.recipient_list.append(recipient_2)
sequence_list = SequenceList()
sequence_string = """
stepCreateMailMessage
stepStartMailMessage
stepCheckMailMessage
stepTic
stepCheckInternetMessagePostCreated
stepCheckLatestMessageListFromMailHost
"""
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