Commit 80a67fd8 authored by Jérome Perrin's avatar Jérome Perrin

testNotificationMessageModule: cleanups

parent d220132e
...@@ -27,11 +27,10 @@ ...@@ -27,11 +27,10 @@
# #
############################################################################## ##############################################################################
import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
from Products.ERP5Type.tests.utils import DummyMailHost
class TestNotificationMessageModule(ERP5TypeTestCase): class TestNotificationMessageModule(ERP5TypeTestCase):
""" """
...@@ -40,39 +39,26 @@ class TestNotificationMessageModule(ERP5TypeTestCase): ...@@ -40,39 +39,26 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
return ('erp5_base',) return ('erp5_base',)
def getTitle(self):
return 'Notification Message Module'
def getNotificationMessageModule(self):
return self.getPortal().notification_message_module
def createUser(self, name, role_list): def createUser(self, name, role_list):
user_folder = self.getPortal().acl_users self.portal.acl_users._doAddUser(name, self.newPassword(), role_list, [])
user_folder._doAddUser(name, 'password', role_list, [])
def afterSetUp(self): def afterSetUp(self):
self.createUser('erp5user', ['Auditor', 'Author']) self.createUser('erp5user', ['Auditor', 'Author'])
self.createUser('manager', ['Manager']) self.createUser('manager', ['Manager'])
portal = self.getPortal() self.portal.email_from_address = 'site@example.invalid'
if 'MailHost' in portal.objectIds():
portal.manage_delObjects(['MailHost'])
portal._setObject('MailHost', DummyMailHost('MailHost'))
portal.email_from_address = 'site@example.invalid'
self.portal.portal_caches.clearAllCache()
self.tic()
self.loginByUserName('erp5user') self.loginByUserName('erp5user')
def beforeTearDown(self): def beforeTearDown(self):
self.abort() self.abort()
# clear modules if necessary # clear modules if necessary
module_list = (self.getNotificationMessageModule(),) module_list = (self.portal.notification_message_module,)
for module in module_list: for module in module_list:
module.manage_delObjects(list(module.objectIds())) module.manage_delObjects(list(module.objectIds()))
self.tic() self.tic()
def test_01_get_document(self): def test_notification_tool_getDocumentValue(self):
module = self.getNotificationMessageModule() module = self.portal.notification_message_module
tool = self.getPortal().portal_notifications tool = self.portal.portal_notifications
self.loginByUserName('manager') self.loginByUserName('manager')
#Test Document A in english #Test Document A in english
n_m_en = module.newContent(portal_type='Notification Message', n_m_en = module.newContent(portal_type='Notification Message',
...@@ -108,11 +94,10 @@ class TestNotificationMessageModule(ERP5TypeTestCase): ...@@ -108,11 +94,10 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
result = tool.getDocumentValue(reference='A', language='fr') result = tool.getDocumentValue(reference='A', language='fr')
self.assertEqual(result.getRelativeUrl(), n_m_fr_02.getRelativeUrl()) self.assertEqual(result.getRelativeUrl(), n_m_fr_02.getRelativeUrl())
def test_substitution_content(self): def test_substitution_content(self):
"""Tests that content and subject have string.Template based substitutions """Tests that content and subject have string.Template based substitutions
""" """
module = self.getNotificationMessageModule() module = self.portal.notification_message_module
createZODBPythonScript(self.portal, createZODBPythonScript(self.portal,
'NotificationMessage_getDummySubstitionMapping', 'NotificationMessage_getDummySubstitionMapping',
'**kw', '**kw',
...@@ -130,11 +115,10 @@ class TestNotificationMessageModule(ERP5TypeTestCase): ...@@ -130,11 +115,10 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
self.assertEqual('Test b', doc.asSubjectText()) self.assertEqual('Test b', doc.asSubjectText())
def test_substitution_content_parameters(self): def test_substitution_content_parameters(self):
"""Tests that we can pass parameters to convert to the substitution method, """Tests that we can pass parameters to convert to the substitution method,
by using substitution_method_parameter_dict """ by using substitution_method_parameter_dict """
module = self.getNotificationMessageModule() module = self.portal.notification_message_module
createZODBPythonScript(self.portal, createZODBPythonScript(self.portal,
'NotificationMessage_getDummySubstitionMapping', 'NotificationMessage_getDummySubstitionMapping',
'**kw', '**kw',
...@@ -150,11 +134,10 @@ class TestNotificationMessageModule(ERP5TypeTestCase): ...@@ -150,11 +134,10 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
substitution_method_parameter_dict=dict(a='b')) substitution_method_parameter_dict=dict(a='b'))
self.assertEqual('substitution text: b', text.rstrip()) self.assertEqual('substitution text: b', text.rstrip())
def test_substitution_content_and_convert(self): def test_substitution_content_and_convert(self):
"""Tests that substitution also works with different target format. """Tests that substitution also works with different target format.
""" """
module = self.getNotificationMessageModule() module = self.portal.notification_message_module
createZODBPythonScript(self.portal, createZODBPythonScript(self.portal,
'NotificationMessage_getDummySubstitionMapping', 'NotificationMessage_getDummySubstitionMapping',
'**kw', '**kw',
...@@ -172,7 +155,7 @@ class TestNotificationMessageModule(ERP5TypeTestCase): ...@@ -172,7 +155,7 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
"""Tests that 'safe' substitution is performed, unless safe_substitute is """Tests that 'safe' substitution is performed, unless safe_substitute is
explicitly passed to False. explicitly passed to False.
""" """
module = self.getNotificationMessageModule() module = self.portal.notification_message_module
createZODBPythonScript(self.portal, createZODBPythonScript(self.portal,
'NotificationMessage_getDummySubstitionMapping', 'NotificationMessage_getDummySubstitionMapping',
'**kw', '**kw',
...@@ -191,9 +174,3 @@ class TestNotificationMessageModule(ERP5TypeTestCase): ...@@ -191,9 +174,3 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
self.assertRaises(KeyError, doc.convert, 'txt', safe_substitute=False) self.assertRaises(KeyError, doc.convert, 'txt', safe_substitute=False)
self.assertRaises(KeyError, doc.convert, 'html', safe_substitute=False) self.assertRaises(KeyError, doc.convert, 'html', safe_substitute=False)
self.assertRaises(KeyError, doc.asSubjectText, safe_substitute=False) self.assertRaises(KeyError, doc.asSubjectText, safe_substitute=False)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestNotificationMessageModule))
return suite
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