Commit 96551f72 authored by Jérome Perrin's avatar Jérome Perrin

interface_post: don't acces restricted attributes in test

Accessing attributes of CMFActivity messages was never supposed to be
allowed from restricted python.
Write this part with a mock instead.
parent 4558c52d
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
# #
############################################################################## ##############################################################################
import email import email
import mock
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
...@@ -82,14 +82,6 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -82,14 +82,6 @@ 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]
...@@ -342,20 +334,19 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -342,20 +334,19 @@ 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): def stepMakeEntitySendEmailFailOnce(self, sequence=None):
createZODBPythonScript( def Entity_sendEmail(*args, **kw):
self.portal.portal_skins.custom, self.Entity_sendEmail_patcher.stop()
'Entity_sendEmail', raise ValueError("Fail on first execution")
self.portal.Entity_sendEmail.params(), self.Entity_sendEmail_patcher = mock.patch(
"""portal = context.getPortalObject() 'erp5.portal_type.Person.Entity_sendEmail',
for activity in portal.portal_activities.getMessageList(): create=True,
if activity.method_id == script.id: side_effect=Entity_sendEmail)
if activity.retry == 0: self.Entity_sendEmail_mock = self.Entity_sendEmail_patcher.start()
raise ValueError('Failure on purpose') self.addCleanup(self.Entity_sendEmail_patcher.stop)
else:
return context.skinSuper('custom', script.id)(%s)""" % (self.portal.Entity_sendEmail.params(),) def stepCheckEntitySendEmailCalled(self, sequence=None):
) self.Entity_sendEmail_mock.assert_called()
def test_emailSendingIsPilotedByInternetMessagePost(self): def test_emailSendingIsPilotedByInternetMessagePost(self):
""" """
...@@ -433,6 +424,7 @@ for activity in portal.portal_activities.getMessageList(): ...@@ -433,6 +424,7 @@ for activity in portal.portal_activities.getMessageList():
stepCheckInternetMessagePostCreated stepCheckInternetMessagePostCreated
stepCheckOnlyOneMessageHasBeenSentFromMailHost stepCheckOnlyOneMessageHasBeenSentFromMailHost
stepCheckLatestMessageListFromMailHost stepCheckLatestMessageListFromMailHost
stepCheckEntitySendEmailCalled
""" """
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) 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