Commit dc93a97d authored by Jérome Perrin's avatar Jérome Perrin

CRM py3

parent ab0546f0
...@@ -50,9 +50,6 @@ def makeFilePath(name): ...@@ -50,9 +50,6 @@ def makeFilePath(name):
return os.path.join(os.path.dirname(Products.ERP5.tests.__file__), return os.path.join(os.path.dirname(Products.ERP5.tests.__file__),
'test_data', 'crm_emails', name) 'test_data', 'crm_emails', name)
def makeFileUpload(name):
path = makeFilePath(name)
return FileUpload(path, name)
clear_module_name_list = """ clear_module_name_list = """
campaign_module campaign_module
...@@ -80,6 +77,13 @@ class BaseTestCRM(ERP5TypeTestCase): ...@@ -80,6 +77,13 @@ class BaseTestCRM(ERP5TypeTestCase):
self.tic() self.tic()
super(BaseTestCRM, self).beforeTearDown() super(BaseTestCRM, self).beforeTearDown()
def makeFileUpload(self, name):
path = makeFilePath(name)
fu = FileUpload(path, name)
self.addCleanup(fu.close)
return fu
class TestCRM(BaseTestCRM): class TestCRM(BaseTestCRM):
def getTitle(self): def getTitle(self):
return "CRM" return "CRM"
...@@ -885,7 +889,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -885,7 +889,7 @@ class TestCRMMailIngestion(BaseTestCRM):
return object_list[-1] return object_list[-1]
portal = self.portal portal = self.portal
message = message_from_string(self._readTestData('simple')) message = message_from_string(self._readTestData('simple').decode())
message.replace_header('subject', 'Visit:Company A') message.replace_header('subject', 'Visit:Company A')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -893,7 +897,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -893,7 +897,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Visit') self.assertEqual(document.getPortalType(), 'Visit')
message = message_from_string(self._readTestData('simple')) message = message_from_string(self._readTestData('simple').decode())
message.replace_header('subject', 'Fax:Company B') message.replace_header('subject', 'Fax:Company B')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -901,7 +905,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -901,7 +905,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Fax Message') self.assertEqual(document.getPortalType(), 'Fax Message')
message = message_from_string(self._readTestData('simple')) message = message_from_string(self._readTestData('simple').decode())
message.replace_header('subject', 'TEST:Company B') message.replace_header('subject', 'TEST:Company B')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -909,7 +913,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -909,7 +913,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Mail Message') self.assertEqual(document.getPortalType(), 'Mail Message')
message = message_from_string(self._readTestData('simple')) message = message_from_string(self._readTestData('simple').decode())
message.replace_header('subject', 'visit:Company A') message.replace_header('subject', 'visit:Company A')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -925,7 +929,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -925,7 +929,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = portal.event_module[portal.event_module.objectIds()[-1]] document = portal.event_module[portal.event_module.objectIds()[-1]]
self.assertEqual(document.getPortalType(), 'Phone Call') self.assertEqual(document.getPortalType(), 'Phone Call')
message = message_from_string(self._readTestData('simple')) message = message_from_string(self._readTestData('simple').decode())
message.replace_header('subject', 'LETTER:Company C') message.replace_header('subject', 'LETTER:Company C')
data = message.as_string() data = message.as_string()
self._ingestMail(data=data) self._ingestMail(data=data)
...@@ -933,7 +937,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -933,7 +937,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Letter') self.assertEqual(document.getPortalType(), 'Letter')
message = message_from_string(self._readTestData('simple')) message = message_from_string(self._readTestData('simple').decode())
body = message.get_payload() body = message.get_payload()
message.set_payload('Visit:%s' % body) message.set_payload('Visit:%s' % body)
data = message.as_string() data = message.as_string()
...@@ -942,7 +946,7 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -942,7 +946,7 @@ class TestCRMMailIngestion(BaseTestCRM):
document = getLastCreatedEvent(portal.event_module) document = getLastCreatedEvent(portal.event_module)
self.assertEqual(document.getPortalType(), 'Visit') self.assertEqual(document.getPortalType(), 'Visit')
message = message_from_string(self._readTestData('simple')) message = message_from_string(self._readTestData('simple').decode())
body = message.get_payload() body = message.get_payload()
message.set_payload('PHONE CALL:%s' % body) message.set_payload('PHONE CALL:%s' % body)
data = message.as_string() data = message.as_string()
...@@ -1153,14 +1157,14 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1153,14 +1157,14 @@ class TestCRMMailSend(BaseTestCRM):
self.assertEqual('"Me," <me@erp5.org>', mfrom) self.assertEqual('"Me," <me@erp5.org>', mfrom)
self.assertEqual(['"Recipient," <recipient@example.com>'], mto) self.assertEqual(['"Recipient," <recipient@example.com>'], mto)
self.assertEqual(event.getTextContent(), text_content) self.assertEqual(event.getTextContent(), text_content)
message = message_from_string(messageText) message = message_from_string(messageText.decode())
self.assertEqual('A Mail', decode_header(message['Subject'])[0][0]) self.assertEqual('A Mail', decode_header(message['Subject'])[0][0])
part = None part = None
for i in message.get_payload(): for i in message.get_payload():
if i.get_content_type()=='text/plain': if i.get_content_type()=='text/plain':
part = i part = i
self.assertEqual(text_content, part.get_payload(decode=True)) self.assertEqual(text_content, part.get_payload(decode=True).decode())
# #
# Test multiple recipients. # Test multiple recipients.
...@@ -1237,13 +1241,13 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1237,13 +1241,13 @@ class TestCRMMailSend(BaseTestCRM):
self.assertEqual('"Me," <me@erp5.org>', mfrom) self.assertEqual('"Me," <me@erp5.org>', mfrom)
self.assertEqual(['"Recipient," <recipient@example.com>'], mto) self.assertEqual(['"Recipient," <recipient@example.com>'], mto)
message = message_from_string(messageText) message = message_from_string(messageText.decode())
part = None part = None
for i in message.get_payload(): for i in message.get_payload():
if i.get_content_type()=='text/html': if i.get_content_type()=='text/html':
part = i part = i
self.assertNotEqual(part, None) self.assertNotEqual(part, None)
self.assertEqual('<html><body>%s</body></html>' % text_content, part.get_payload(decode=True)) self.assertEqual('<html><body>%s</body></html>' % text_content, part.get_payload(decode=True).decode())
def test_MailMessageEncoding(self): def test_MailMessageEncoding(self):
# test sending a mail message with non ascii characters # test sending a mail message with non ascii characters
...@@ -1260,7 +1264,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1260,7 +1264,7 @@ class TestCRMMailSend(BaseTestCRM):
self.assertEqual('=?utf-8?q?Me=2C_=F0=9F=90=88_fan?= <me@erp5.org>', mfrom) self.assertEqual('=?utf-8?q?Me=2C_=F0=9F=90=88_fan?= <me@erp5.org>', mfrom)
self.assertEqual(['=?utf-8?q?Recipient=2C_=F0=9F=90=88_fan?= <recipient@example.com>'], mto) self.assertEqual(['=?utf-8?q?Recipient=2C_=F0=9F=90=88_fan?= <recipient@example.com>'], mto)
message = message_from_string(messageText) message = message_from_string(messageText.decode())
self.assertEqual('Héhé', decode_header(message['Subject'])[0][0]) self.assertEqual('Héhé', decode_header(message['Subject'])[0][0])
self.assertEqual('Me, 🐈 fan', decode_header(message['From'])[0][0]) self.assertEqual('Me, 🐈 fan', decode_header(message['From'])[0][0])
...@@ -1269,7 +1273,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1269,7 +1273,7 @@ class TestCRMMailSend(BaseTestCRM):
for i in message.get_payload(): for i in message.get_payload():
if i.get_content_type()=='text/plain': if i.get_content_type()=='text/plain':
part = i part = i
self.assertEqual('Hàhà', part.get_payload(decode=True)) self.assertEqual(u'Hàhà', part.get_payload(decode=True).decode('utf-8'))
def test_MailAttachmentPdf(self): def test_MailAttachmentPdf(self):
""" """
...@@ -1278,7 +1282,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1278,7 +1282,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document which will be attached. # Add a document which will be attached.
# pdf # pdf
filename = 'sample_attachment.pdf' filename = 'sample_attachment.pdf'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_object) document = self.portal.portal_contributions.newContent(file=file_object)
self.tic() self.tic()
...@@ -1325,7 +1329,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1325,7 +1329,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.odt' filename = 'sample_attachment.odt'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_object) document = self.portal.portal_contributions.newContent(file=file_object)
self.tic() self.tic()
...@@ -1372,7 +1376,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1372,7 +1376,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.zip' filename = 'sample_attachment.zip'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_object) document = self.portal.portal_contributions.newContent(file=file_object)
self.tic() self.tic()
...@@ -1417,7 +1421,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1417,7 +1421,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.gif' filename = 'sample_attachment.gif'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file_object) document = self.portal.portal_contributions.newContent(file=file_object)
self.tic() self.tic()
...@@ -1514,7 +1518,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1514,7 +1518,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document which will be attached. # Add a document which will be attached.
# pdf # pdf
filename = 'sample_attachment.pdf' filename = 'sample_attachment.pdf'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
# Add a ticket # Add a ticket
ticket = self.portal.campaign_module.newContent(portal_type='Campaign', ticket = self.portal.campaign_module.newContent(portal_type='Campaign',
...@@ -1562,7 +1566,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1562,7 +1566,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.zip' filename = 'sample_attachment.zip'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
# Add a ticket # Add a ticket
ticket = self.portal.campaign_module.newContent(portal_type='Campaign', ticket = self.portal.campaign_module.newContent(portal_type='Campaign',
...@@ -1611,7 +1615,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1611,7 +1615,7 @@ class TestCRMMailSend(BaseTestCRM):
""" """
# Add a document which will be attached. # Add a document which will be attached.
filename = 'sample_attachment.zip' filename = 'sample_attachment.zip'
file_object = makeFileUpload(filename) file_object = self.makeFileUpload(filename)
# Add a ticket # Add a ticket
ticket = self.portal.campaign_module.newContent(portal_type='Campaign', ticket = self.portal.campaign_module.newContent(portal_type='Campaign',
...@@ -1688,7 +1692,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1688,7 +1692,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document on a person which will be attached. # Add a document on a person which will be attached.
def add_document(filename, container, portal_type): def add_document(filename, container, portal_type):
f = makeFileUpload(filename) f = self.makeFileUpload(filename)
document = container.newContent(portal_type=portal_type) document = container.newContent(portal_type=portal_type)
document.edit(file=f, reference=filename) document.edit(file=f, reference=filename)
return document return document
...@@ -1745,7 +1749,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1745,7 +1749,7 @@ class TestCRMMailSend(BaseTestCRM):
# Add a document on a person which will be attached. # Add a document on a person which will be attached.
def add_document(filename, container, portal_type): def add_document(filename, container, portal_type):
f = makeFileUpload(filename) f = self.makeFileUpload(filename)
document = container.newContent(portal_type=portal_type) document = container.newContent(portal_type=portal_type)
document.edit(file=f, reference=filename) document.edit(file=f, reference=filename)
return document return document
...@@ -1821,7 +1825,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -1821,7 +1825,7 @@ class TestCRMMailSend(BaseTestCRM):
self.tic() self.tic()
new_event = event.Base_createCloneDocument(batch_mode=1) new_event = event.Base_createCloneDocument(batch_mode=1)
self.assertFalse(new_event.hasFile(), '%r has a file' % (new_event,)) self.assertFalse(new_event.hasFile(), '%r has a file' % (new_event,))
self.assertEqual(new_event.getData(), '') self.assertEqual(new_event.getData(), b'')
self.assertEqual(new_event.getTitle(), real_title) self.assertEqual(new_event.getTitle(), real_title)
self.assertEqual(new_event.getTextContent(), real_content) self.assertEqual(new_event.getTextContent(), real_content)
self.assertNotEqual(new_event.getReference(), event.getReference()) self.assertNotEqual(new_event.getReference(), event.getReference())
...@@ -2036,8 +2040,8 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -2036,8 +2040,8 @@ class TestCRMMailSend(BaseTestCRM):
self.assertEqual(5, len(self.portal.MailHost._message_list)) self.assertEqual(5, len(self.portal.MailHost._message_list))
for message_info in self.portal.MailHost._message_list: for message_info in self.portal.MailHost._message_list:
self.assertIn(mail_text_content, message_info[-1]) self.assertIn(mail_text_content, message_info[-1].decode())
message = message_from_string(message_info[-1]) message = message_from_string(message_info[-1].decode())
self.assertTrue(DateTime(message.get("Date")).isCurrentDay()) self.assertTrue(DateTime(message.get("Date")).isCurrentDay())
def test_MailMessage_send_simple_case(self): def test_MailMessage_send_simple_case(self):
...@@ -2069,7 +2073,7 @@ class TestCRMMailSend(BaseTestCRM): ...@@ -2069,7 +2073,7 @@ class TestCRMMailSend(BaseTestCRM):
mail_message.send(extra_header_dict={"X-test-header": "test"}) mail_message.send(extra_header_dict={"X-test-header": "test"})
self.tic() self.tic()
(_, _, last_message,), = self.portal.MailHost._message_list (_, _, last_message,), = self.portal.MailHost._message_list
message = message_from_string(last_message) message = message_from_string(last_message.decode())
self.assertEqual("test", message.get("X-test-header")) self.assertEqual("test", message.get("X-test-header"))
......
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