Commit 58325e48 authored by Nicolas Delaby's avatar Nicolas Delaby

* Run activities after ingestion.

  Because discoverMedata may change the portal_type of ingested Event.
* Get the last event according creation_date
* It has been decided to no hide portal_type added in Subject or in Body parts of message.
  getTitle() == 'Visit:Company A' even if 'Visit:' is a keyword to help contribution_tool
  to Construct Visit portal_type during ingestion process.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41493 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ba1e735b
......@@ -573,63 +573,85 @@ class TestCRMMailIngestion(BaseTestCRM):
Make sure that ingested email will be correctly converted to
appropriate portal type by email metadata.
"""
def getLastCreatedEvent(module):
object_list = module.contentValues()
object_list.sort(key=lambda e:e.getCreationDate())
return object_list[-1]
portal = self.portal
message = email.message_from_string(self._readTestData('simple'))
message.replace_header('subject', 'Visit:Company A')
data = message.as_string()
document = self._ingestMail(data=data)
self._ingestMail(data=data)
transaction.commit()
self.tic()
document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Visit')
self.assertEqual(document.getTitle(), 'Company A')
message = email.message_from_string(self._readTestData('simple'))
message.replace_header('subject', 'Fax:Company B')
data = message.as_string()
document = self._ingestMail(data=data)
self._ingestMail(data=data)
transaction.commit()
self.tic()
document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Fax Message')
self.assertEqual(document.getTitle(), 'Company B')
message = email.message_from_string(self._readTestData('simple'))
message.replace_header('subject', 'TEST:Company B')
data = message.as_string()
document = self._ingestMail(data=data)
self._ingestMail(data=data)
transaction.commit()
self.tic()
document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Mail Message')
self.assertEqual(document.getTitle(), 'TEST:Company B')
message = email.message_from_string(self._readTestData('simple'))
message.replace_header('subject', 'visit:Company A')
data = message.as_string()
document = self._ingestMail(data=data)
self._ingestMail(data=data)
transaction.commit()
self.tic()
document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Visit')
self.assertEqual(document.getTitle(), 'Company A')
message = email.message_from_string(self._readTestData('simple'))
message.replace_header('subject', 'phone:Company B')
data = message.as_string()
document = self._ingestMail(data=data)
self._ingestMail(data=data)
transaction.commit()
self.tic()
document = portal.event_module[portal.event_module.objectIds()[-1]]
self.assertEqual(document.getPortalType(), 'Phone Call')
self.assertEqual(document.getTitle(), 'Company B')
message = email.message_from_string(self._readTestData('simple'))
message.replace_header('subject', 'LETTER:Company C')
data = message.as_string()
document = self._ingestMail(data=data)
self._ingestMail(data=data)
transaction.commit()
self.tic()
document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Letter')
self.assertEqual(document.getTitle(), 'Company C')
message = email.message_from_string(self._readTestData('simple'))
body = message.get_payload()
message.set_payload('Visit:%s' % body)
data = message.as_string()
document = self._ingestMail(data=data)
self._ingestMail(data=data)
transaction.commit()
self.tic()
document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Visit')
self.assertEqual(document.getTextContent(), body)
message = email.message_from_string(self._readTestData('simple'))
body = message.get_payload()
message.set_payload('PHONE CALL:%s' % body)
data = message.as_string()
document = self._ingestMail(data=data)
self._ingestMail(data=data)
transaction.commit()
self.tic()
document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Phone Call')
self.assertEqual(document.getTextContent(), body)
def test_forwarder_mail(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