Mail related functional tests ============================= Some initial setup: >>> from plone.testing.z2 import Browser >>> browser = Browser(app) We need to fake a valid mail setup: >>> from Products.CMFPlone.interfaces.controlpanel import IMailSchema >>> from plone.registry.interfaces import IRegistry >>> from zope.component import getUtility >>> registry = getUtility(IRegistry) >>> mail_settings = registry.forInterface(IMailSchema, prefix='plone') >>> mail_settings.email_from_address = "mail@plone.test" >>> mailhost = self.portal.MailHost >>> import transaction; transaction.commit() Contact form ------------ Let's go to the contact form: >>> browser.open('http://nohost/plone/contact-info') Now fill in the form: >>> form = browser.getForm(id='form') >>> form.getControl(name='form.widgets.sender_fullname').value = 'T\xc3\xa4st user' >>> form.getControl(name='form.widgets.sender_from_address').value = 'test@plone.test' >>> form.getControl(name='form.widgets.subject').value = 'Some t\xc3\xa4st subject.' >>> form.getControl(name='form.widgets.message').value = 'Another t\xc3\xa4st message.' And submit it: >>> form.getControl(name='form.buttons.send').click() We expect to return to the same page. >>> browser.url 'http://nohost/plone/contact-info' >>> 'A mail has now been sent' in browser.contents True As part of our test setup, we replaced the original MailHost with our own version. Our version doesn't mail messages, it just collects them in a list called ``messages``: >>> len(mailhost.messages) 1 >>> msg = mailhost.messages[0] Now that we have the message, we want to look at its contents: >>> 'To: mail@plone.test' in msg True >>> 'From: mail@plone.test' in msg True We expect the headers to be properly header encoded (7-bit): >>> 'Subject: =?utf-8?q?Some_t=C3=A4st_subject=2E?=' in msg True The output should be encoded in a reasonable manner (in this case quoted-printable). There may be some small differences in where exactly the lines are cut off, depending on whether you use five.pt or not, so we turn the message into one line first: >>> msg.replace('=\n', '').replace('\n', ' ') '...Another t=C3=A4st message...You are receiving this mail because T=C3=A4st user test@plone.test...is sending feedback about the site you administer at... We can also decode the string, though we should still be careful about lines ending in different spots: >>> import quopri >>> quopri.decodestring(msg).replace('\n', ' ') '...Another t\xc3\xa4st message...You are receiving this mail because T\xc3\xa4st user test@plone.test...is sending feedback about the site you administer at...'