Commit 698bc8d5 authored by Yusei Tahara's avatar Yusei Tahara

Update test for new email ingestion system.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18252 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1a93c01b
...@@ -91,8 +91,8 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -91,8 +91,8 @@ class TestIngestion(ERP5TypeTestCase):
""" """
Return the list of required business templates. Return the list of required business templates.
""" """
return ('erp5_base', 'erp5_web', 'erp5_dms_mysql_innodb_catalog', 'erp5_dms') return ('erp5_base', 'erp5_web', 'erp5_crm',
#return ('erp5_base', 'erp5_trade', 'erp5_project', 'erp5_dms') 'erp5_dms_mysql_innodb_catalog', 'erp5_dms')
def afterSetUp(self, quiet=QUIET, run=RUN_ALL_TEST): def afterSetUp(self, quiet=QUIET, run=RUN_ALL_TEST):
""" """
...@@ -105,33 +105,12 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -105,33 +105,12 @@ class TestIngestion(ERP5TypeTestCase):
self.portal_catalog = self.getCatalogTool() self.portal_catalog = self.getCatalogTool()
self.createDefaultCategoryList() self.createDefaultCategoryList()
self.setSystemPreference() self.setSystemPreference()
self.createTools()
self.setSimulatedNotificationScript() self.setSimulatedNotificationScript()
self.setTools()
def beforeTearDown(self): def beforeTearDown(self):
self.portal.portal_caches.clearAllCache() self.portal.portal_caches.clearAllCache()
def createTools(self):
"""
Set up missing portal_mailin tool.
"""
# Delete and create portal_contributions
#try:
# self.portal._delObject('portal_contributions')
#except AttributeError:
# pass
#addTool = self.portal.manage_addProduct['ERP5'].manage_addTool
#addTool('ERP5 Contribution Tool', None)
# Delete and create portal_mailin
try:
self.portal._delObject('portal_mailin')
except AttributeError:
pass
addTool = self.portal.manage_addProduct['CMFMailIn'].manage_addTool
addTool('CMF Mail In Tool', None)
mailin = self.portal.portal_mailin
mailin.edit_configuration('Document_ingestEmail')
def setSystemPreference(self): def setSystemPreference(self):
default_pref = self.portal.portal_preferences.default_site_preference default_pref = self.portal.portal_preferences.default_site_preference
default_pref.setPreferredOoodocServerAddress(conversion_server_host[0]) default_pref.setPreferredOoodocServerAddress(conversion_server_host[0])
...@@ -152,6 +131,13 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -152,6 +131,13 @@ class TestIngestion(ERP5TypeTestCase):
script = getattr(context, script_id) script = getattr(context, script_id)
script.ZPythonScript_edit('email_to, event, doc, **kw', 'return') script.ZPythonScript_edit('email_to, event, doc, **kw', 'return')
def setTools(self):
# XXX FIX ME
# XXX We should use business template to install these tools.(Yusei)
if getattr(self.portal, 'mimetypes_registry', None) is None:
self.portal.manage_addProduct['MimetypesRegistry'].manage_addTool(type='MimeTypes Registry')
if getattr(self.portal, 'portal_transforms', None) is None:
self.portal.manage_addProduct['PortalTransforms'].manage_addTool(type='Portal Transforms')
################################## ##################################
## Useful methods ## Useful methods
...@@ -447,6 +433,15 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -447,6 +433,15 @@ class TestIngestion(ERP5TypeTestCase):
for k, v in expected_metadata.items(): for k, v in expected_metadata.items():
self.assertEquals(context.getProperty(k), v) self.assertEquals(context.getProperty(k), v)
def receiveEmail(self, data,
portal_type='Document Ingestion Message',
container_path='document_ingestion_module',
file_name='email.emx'):
return self.portal.portal_contributions.newContent(data=data,
portal_type=portal_type,
container_path=container_path,
file_name=file_name)
################################## ##################################
## Basic steps ## Basic steps
################################## ##################################
...@@ -459,16 +454,21 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -459,16 +454,21 @@ class TestIngestion(ERP5TypeTestCase):
Create a person with ID "john" if it does not exists already Create a person with ID "john" if it does not exists already
""" """
portal_type = 'Person' portal_type = 'Person'
id = 'john' person_id = 'john'
reference = 'john_doe' reference = 'john_doe'
person_module = self.portal.person_module person_module = self.portal.person_module
if getattr(person_module, 'john', False): return if getattr(person_module, person_id, None) is not None:
person = person_module.newContent( portal_type='Person' return
, id=id person = person_module.newContent(portal_type='Person',
, reference = reference id=person_id,
) reference=reference,
first_name='John',
last_name='Doe'
)
person.setDefaultEmailText('john@doe.com') person.setDefaultEmailText('john@doe.com')
person.reindexObject(); get_transaction().commit(); self.tic() person.reindexObject()
get_transaction().commit()
self.tic()
def stepCreateTextDocument(self, sequence=None, sequence_list=None, **kw): def stepCreateTextDocument(self, sequence=None, sequence_list=None, **kw):
""" """
...@@ -792,7 +792,7 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -792,7 +792,7 @@ class TestIngestion(ERP5TypeTestCase):
Clean up DMS system from old content. Clean up DMS system from old content.
""" """
portal = self.getPortal() portal = self.getPortal()
for module in (portal.document_module, portal.image_module,): for module in (portal.document_module, portal.image_module, portal.document_ingestion_module):
module.manage_delObjects(map(None, module.objectIds())) module.manage_delObjects(map(None, module.objectIds()))
def stepContributeFileListWithType(self, sequence=None, sequence_list=None, **kw): def stepContributeFileListWithType(self, sequence=None, sequence_list=None, **kw):
...@@ -872,23 +872,17 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -872,23 +872,17 @@ class TestIngestion(ERP5TypeTestCase):
""" """
email was sent in by someone who is not in the person_module email was sent in by someone who is not in the person_module
""" """
self.failUnless(hasattr(self.portal, 'portal_mailin'))
f = open(makeFilePath('email_from.txt')) f = open(makeFilePath('email_from.txt'))
res = self.portal.portal_mailin.postMailMessage(f.read()) document = self.receiveEmail(data=f.read())
# we check if the mailin returned anything - it should return a message saying that the recipient does not exist get_transaction().commit()
# the exact wording may differ self.tic()
# the way mailin works is that if mail was accepted it returns None
self.failUnless(res)
def stepReceiveEmailFromJohn(self, sequence=None, sequence_list=None, **kw): def stepReceiveEmailFromJohn(self, sequence=None, sequence_list=None, **kw):
""" """
email was sent in by someone who is in the person_module email was sent in by someone who is in the person_module
""" """
self.failUnless(hasattr(self.portal, 'portal_mailin'))
f = open(makeFilePath('email_from.txt')) f = open(makeFilePath('email_from.txt'))
res = self.portal.portal_mailin.postUTF8MailMessage(f.read()) document = self.receiveEmail(f.read())
printAndLog(res)
self.failIf(res)
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
...@@ -897,15 +891,24 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -897,15 +891,24 @@ class TestIngestion(ERP5TypeTestCase):
find the newly mailed-in document by its reference find the newly mailed-in document by its reference
check its properties check its properties
""" """
res = self.portal_catalog(reference='MAIL') # First, check document ingestion message
self.assertEquals(len(res), 1) # check if it is there result = self.portal_catalog(portal_type='Document Ingestion Message',
document = res[0].getObject() title='A Test Mail',
john_is_owner = 0 source_title='John Doe'
for role in document.get_local_roles(): )
if role[0] == 'john_doe' and 'Owner' in role[1]: self.assertEqual(len(result), 1)
john_is_owner = 1 ingestion_message = result[0].getObject()
break
self.failUnless(john_is_owner) # Second, check attachments
attachment_list = ingestion_message.getAggregateValueList()
self.assertEqual(len(attachment_list), 1)
# Third, check document
result = self.portal_catalog(portal_type='Text')
self.assertEqual(len(result), 1)
document = result[0].getObject()
self.assertEqual(document.getRelativeUrl(), result[0].getRelativeUrl())
def playSequence(self, step_list, quiet): def playSequence(self, step_list, quiet):
sequence_list = SequenceList() sequence_list = SequenceList()
......
...@@ -12,7 +12,7 @@ From: john <john@doe.com> ...@@ -12,7 +12,7 @@ From: john <john@doe.com>
User-Agent: Thunderbird 1.5.0.7 (X11/20060921) User-Agent: Thunderbird 1.5.0.7 (X11/20060921)
MIME-Version: 1.0 MIME-Version: 1.0
To: bartek@erp5.pl To: bartek@erp5.pl
Subject: blebleble Subject: A Test Mail
Content-Type: multipart/mixed; Content-Type: multipart/mixed;
boundary="------------070902080602050309080805" boundary="------------070902080602050309080805"
......
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