def testExecuteTemplatedEmailUnicode(self): """ Create recipients email using a template variable exposed from AT. """ self.loginAsPortalOwner() sm = getSiteManager(self.portal) sm.unregisterUtility(provided=IMailHost) dummyMailHost = DummySecureMailHost('dMailhost') sm.registerUtility(dummyMailHost, IMailHost) e = MailAction() # Snatch email receiver from AT content title # Ugly but goes for a test self.folder.d1.setTitle(u"ÅÄÖ") e.source = "*****@*****.**" e.recipients = "*****@*****.**" e.subject = u"Testing åäö {{ title }}" e.message = u"Päge '{{ text }}' with title {{ title }} created in {{ object_url }} !" ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable) ex() self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText)) mailSent = dummyMailHost.sent[0] self.assertEqual('text/plain; charset="utf-8"', mailSent.get('Content-Type')) self.assertEqual("*****@*****.**", mailSent.get('To')) self.assertEqual("*****@*****.**", mailSent.get('From')) messages = IStatusMessage(self.portal.REQUEST).showStatusMessages() if messages: for m in messages: print str(m.message) # No template error messages self.assertEqual(len(messages), 0)
def testExecute(self): # Put in stub email sender self.loginAsPortalOwner() sm = getSiteManager(self.portal) sm.unregisterUtility(provided=IMailHost) dummyMailHost = DummySecureMailHost('dMailhost') sm.registerUtility(dummyMailHost, IMailHost) # Create an action e = MailAction() e.source = "*****@*****.**" e.recipients = "*****@*****.**" e.subject = "Test mail" e.message = u"Päge {{ text }}' with title {{ title }} created in {{ object_url }} !" ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable) ex() messages = IStatusMessage(self.portal.REQUEST).showStatusMessages() if messages: for m in messages: print str(m.message) # No template error messages self.assertEqual(len(messages), 0) self.assertEqual(len(dummyMailHost.sent), 1) self.failUnless(isinstance(dummyMailHost.sent[0], MIMEText)) mailSent = dummyMailHost.sent[0] self.assertEqual('text/plain; charset="utf-8"', mailSent.get('Content-Type')) self.assertEqual("*****@*****.**", mailSent.get('To')) self.assertEqual("*****@*****.**", mailSent.get('From'))
def xxx_testExecuteMissingVar(self): """ Template contains syntax errors, we should receive status messages. """ # # TODO: Jinja backend doesn't support missing variable catching - used to be Cheetah test case # self.loginAsPortalOwner() sm = getSiteManager(self.portal) sm.unregisterUtility(provided=IMailHost) dummyMailHost = DummySecureMailHost('dMailhost') sm.registerUtility(dummyMailHost, IMailHost) e = MailAction() e.recipients = '[email protected],[email protected]' e.subject = "Test mail" e.message = 'Missing template variable {{ missing }}' ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable) self.assertRaises(ValueError, ex) # if we provide a site mail address this won't fail anymore sm.manage_changeProperties({'email_from_address': '*****@*****.**'}) ex() messages = IStatusMessage(self.portal.REQUEST).showStatusMessages() if messages: for m in messages: print str(m.message) self.assertEqual(len(dummyMailHost.sent), 0) # No template error messages self.assertEqual(len(messages), 1)