示例#1
0
    def testExecute(self):
        self.loginAsPortalOwner()
        self.portal.portal_membership.getAuthenticatedMember().setProperties(email='*****@*****.**')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummyMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailAction()
        e.source = "$user_email"
        e.recipients = "[email protected], [email protected], $reviewer_emails, $manager_emails, $member_emails"
        e.message = "P\xc3\xa4ge '${title}' created in ${url} !".decode('utf-8')
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        self.assertTrue(isinstance(dummyMailHost.sent[0], Message))

        sent_mails = dict([(mailSent.get('To'), mailSent) for mailSent in dummyMailHost.sent])

        mailSent = sent_mails['*****@*****.**']
        self.assertEqual('text/plain; charset="utf-8"',
                        mailSent.get('Content-Type'))
        self.assertEqual("*****@*****.**", mailSent.get('From'))
        # The output message should be a utf-8 encoded string
        self.assertEqual("P\xc3\xa4ge 'W\xc3\xa4lkommen' created in http://nohost/plone/Members/test_user_1_/d1 !",
                         mailSent.get_payload(decode=True))

        # check interpolation of $reviewer_emails
        self.assertTrue("*****@*****.**" in sent_mails)

        # check interpolation of $manager_emails
        self.assertTrue("*****@*****.**" in sent_mails)

        # check interpolation of $member_emails
        self.assertEqual(set(["*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", ]),
                         set(sent_mails.keys()))
示例#2
0
    def send_mail(self, recipients='', subject='', message=''):

        msg = MailAction()

        msg.source = self.SENDER

        # If we're in debug mode, the email goes to the configured debug email.
        # Or, if we don't have recipients
        if self.debug or not recipients:
            msg.recipients = self.debug_email
        else:
            msg.recipients = recipients

        msg.subject = "%s: %s" % (self.SUBJECT_PREFIX, subject)
        msg.message = message

        # If we're in debug mode, log the message
        if self.debug:
            self.log(summary="DEBUG: Send email %s to %s" % (msg.subject, recipients))

        # Send the email and log error
        try:
            m = MailActionExecutor(self.context, msg, self.event)
            m()
        except:
            self.log(summary="Error sending email %s to %s" % (msg.subject, msg.recipients),
                     severity=ERROR)
示例#3
0
 def testExecuteMultiRecipients(self):
     dummyMailHost = self._setup_mockmail()
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = '[email protected],[email protected]'
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.messages), 2)
     # in py3 the order of mails is non-determininistic
     # because sending iterates over a set of recipients
     for msg in dummyMailHost.messages:
         if '*****@*****.**' in msg:
             mailSent1 = message_from_string(msg)
         else:
             mailSent2 = message_from_string(msg)
     self.assertEqual('text/plain; charset="utf-8"',
                      mailSent1.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent1.get('To'))
     self.assertEqual('*****@*****.**', mailSent1.get('From'))
     self.assertEqual('Document created !', mailSent1.get_payload())
     self.assertEqual('text/plain; charset="utf-8"',
                      mailSent2.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent2.get('To'))
     self.assertEqual('*****@*****.**', mailSent2.get('From'))
     self.assertEqual('Document created !', mailSent2.get_payload())
     self._teardown_mockmail()
 def testExecuteMultiRecipients(self):
     self.loginAsPortalOwner()
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummyMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = '[email protected],[email protected]'
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.sent), 2)
     self.failUnless(isinstance(dummyMailHost.sent[0], Message))
     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'))
     self.assertEqual('Document created !', mailSent.get_payload(decode=True))
     mailSent = dummyMailHost.sent[1]
     self.assertEqual('text/plain; charset="utf-8"',
                     mailSent.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent.get('To'))
     self.assertEqual('*****@*****.**', mailSent.get('From'))
     self.assertEqual('Document created !', mailSent.get_payload(decode=True))
示例#5
0
 def testExecuteMultiRecipients(self):
     self.loginAsPortalOwner()
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummyMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = '[email protected],[email protected]'
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.sent), 2)
     self.assertTrue(isinstance(dummyMailHost.sent[0], Message))
     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'))
     self.assertEqual('Document created !', mailSent.get_payload(decode=True))
     mailSent = dummyMailHost.sent[1]
     self.assertEqual('text/plain; charset="utf-8"',
                     mailSent.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent.get('To'))
     self.assertEqual('*****@*****.**', mailSent.get('From'))
     self.assertEqual('Document created !', mailSent.get_payload(decode=True))
示例#6
0
 def testExecuteMultiRecipients(self):
     dummyMailHost = self._setup_mockmail()
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = '[email protected],[email protected]'
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.messages), 2)
     mailSent = message_from_string(dummyMailHost.messages[0])
     self.assertEqual('text/plain; charset="utf-8"',
                      mailSent.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent.get('To'))
     self.assertEqual('*****@*****.**', mailSent.get('From'))
     self.assertEqual('Document created !',
                      mailSent.get_payload(decode=True))
     mailSent = message_from_string(dummyMailHost.messages[1])
     self.assertEqual('text/plain; charset="utf-8"',
                      mailSent.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent.get('To'))
     self.assertEqual('*****@*****.**', mailSent.get('From'))
     self.assertEqual('Document created !',
                      mailSent.get_payload(decode=True))
     self._teardown_mockmail()
 def testExecuteMultiRecipients(self):
     dummyMailHost = self._setup_mockmail()
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = '[email protected],[email protected]'
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.messages), 2)
     # in py3 the order of mails is non-determininistic
     # because sending iterates over a set of recipients
     for msg in dummyMailHost.messages:
         if '*****@*****.**' in msg:
             mailSent1 = message_from_string(msg)
         else:
             mailSent2 = message_from_string(msg)
     self.assertEqual('text/plain; charset="utf-8"',
                      mailSent1.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent1.get('To'))
     self.assertEqual('*****@*****.**', mailSent1.get('From'))
     self.assertEqual('Document created !',
                      mailSent1.get_payload())
     self.assertEqual('text/plain; charset="utf-8"',
                      mailSent2.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent2.get('To'))
     self.assertEqual('*****@*****.**', mailSent2.get('From'))
     self.assertEqual('Document created !',
                      mailSent2.get_payload())
     self._teardown_mockmail()
    def testExecute(self):
        self.loginAsPortalOwner()
        self.portal.portal_membership.getAuthenticatedMember().setProperties(email='*****@*****.**')
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummyMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        e = MailAction()
        e.source = "$user_email"
        e.recipients = "[email protected], $reviewer_emails, $manager_emails, $member_emails"
        e.message = "P\xc3\xa4ge '${title}' created in ${url} !".decode('utf-8')
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        self.failUnless(isinstance(dummyMailHost.sent[0], Message))
        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'))
        # The output message should be a utf-8 encoded string
        self.assertEqual("P\xc3\xa4ge 'W\xc3\xa4lkommen' created in http://nohost/plone/Members/test_user_1_/d1 !",
                         mailSent.get_payload(decode=True))

        # check interpolation of $reviewer_emails
        mailSent = dummyMailHost.sent[1]
        self.assertEqual("*****@*****.**", mailSent.get('To'))

        # check interpolation of $manager_emails
        mailSent = dummyMailHost.sent[2]
        self.assertEqual("*****@*****.**", mailSent.get('To'))

        # check interpolation of $member_emails
        members = set((mailSent.get('To') for mailSent in dummyMailHost.sent[2:7]))
        self.assertEqual(set(["*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", ]), members)
示例#9
0
 def testExecuteBadMailHost(self):
     # Our goal is that mailing errors should not cause exceptions
     self.loginAsPortalOwner()
     self.portal.portal_membership.getAuthenticatedMember().setProperties(email='*****@*****.**')
     e = MailAction()
     e.source = "$user_email"
     e.recipients = "[email protected], $reviewer_emails, $manager_emails, $member_emails"
     e.message = u"Päge '${title}' created in ${url} !"
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
 def testExecuteBadMailHost(self):
     # Our goal is that mailing errors should not cause exceptions
     self.loginAsPortalOwner()
     self.portal.portal_membership.getAuthenticatedMember().setProperties(email='*****@*****.**')
     e = MailAction()
     e.source = "$user_email"
     e.recipients = "[email protected], $reviewer_emails, $manager_emails, $member_emails"
     e.message = u"Päge '${title}' created in ${url} !"
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
示例#11
0
 def testExecuteNoRecipients(self):
     # no recipient
     dummyMailHost = self._setup_mockmail()
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = ''
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.messages), 0)
     self._teardown_mockmail()
 def testExecuteNoRecipients(self):
     # no recipient
     dummyMailHost = self._setup_mockmail()
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = ''
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.messages), 0)
     self._teardown_mockmail()
 def testExecuteNoRecipients(self):
     # no recipient
     self.loginAsPortalOwner()
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummyMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = ''
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.sent), 0)
示例#14
0
 def testExecuteNoRecipients(self):
     # no recipient
     self.loginAsPortalOwner()
     sm = getSiteManager(self.portal)
     sm.unregisterUtility(provided=IMailHost)
     dummyMailHost = DummyMailHost('dMailhost')
     sm.registerUtility(dummyMailHost, IMailHost)
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = ''
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.sent), 0)
    def testExecuteExcludeActor(self):
        dummyMailHost = self._setup_mockmail()
        self.portal.portal_membership.getAuthenticatedMember().setProperties(
            email='*****@*****.**')
        e = MailAction()
        e.source = '$user_email'
        e.exclude_actor = True
        e.recipients = '[email protected], [email protected]'
        e.message = u'A dummy event just happened !!!!!'
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        self.assertEqual(len(dummyMailHost.messages), 1)

        mailSent = message_from_string(dummyMailHost.messages[0])
        self.assertEqual('*****@*****.**', mailSent.get('To'))
        self._teardown_mockmail()
示例#16
0
    def testExecute(self):
        # this avoids sending mail as [email protected]
        self.loginAsPortalOwner()
        self.portal.portal_membership.getAuthenticatedMember().setProperties(
            email='*****@*****.**')
        dummyMailHost = self._setup_mockmail()
        e = MailAction()
        e.source = '$user_email'
        e.recipients = '[email protected], [email protected], $reviewer_emails, ' \
                       '$manager_emails, $member_emails'
        e.message = "P\xc3\xa4ge '${title}' created in ${url} !".decode(
            'utf-8')
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        sent_mails = {}
        for mail_sent in dummyMailHost.messages:
            mail_sent_msg = message_from_string(mail_sent)
            sent_mails[mail_sent_msg.get('To')] = mail_sent_msg

        mailSent = sent_mails['*****@*****.**']
        self.assertEqual('text/plain; charset="utf-8"',
                         mailSent.get('Content-Type'))
        self.assertEqual('*****@*****.**', mailSent.get('From'))
        # The output message should be a utf-8 encoded string
        self.assertEqual(
            "P\xc3\xa4ge 'W\xc3\xa4lkommen' created in "
            'http://nohost/plone/Members/test_user_1_/d1 !',
            mailSent.get_payload(decode=True))

        # check interpolation of $reviewer_emails
        self.assertTrue('*****@*****.**' in sent_mails)

        # check interpolation of $manager_emails
        self.assertTrue('*****@*****.**' in sent_mails)

        # check interpolation of $member_emails
        emails = [
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
        ]
        self.assertEqual(set(emails), set(sent_mails.keys()))
        self._teardown_mockmail()
示例#17
0
    def testExecuteExcludeActor(self):
        dummyMailHost = self._setup_mockmail()
        self.portal.portal_membership.getAuthenticatedMember().setProperties(
            email='*****@*****.**')
        e = MailAction()
        e.source = '$user_email'
        e.exclude_actor = True
        e.recipients = '[email protected], [email protected]'
        e.message = u'A dummy event just happened !!!!!'
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        self.assertEqual(len(dummyMailHost.messages), 1)

        mailSent = message_from_string(dummyMailHost.messages[0])
        self.assertEqual('*****@*****.**', mailSent.get('To'))
        self._teardown_mockmail()
    def testExecute(self):
        # this avoids sending mail as [email protected]
        self.portal.portal_membership.getAuthenticatedMember().setProperties(
            email='*****@*****.**')
        dummyMailHost = self._setup_mockmail()
        e = MailAction()
        e.source = '$user_email'
        e.recipients = '[email protected], [email protected], $reviewer_emails, ' \
                       '$manager_emails, $member_emails'
        e.message = u"Päge '${title}' created in ${url} !"
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        sent_mails = {}
        for mail_sent in dummyMailHost.messages:
            mail_sent_msg = message_from_string(mail_sent)
            sent_mails[mail_sent_msg.get('To')] = mail_sent_msg

        mailSent = sent_mails['*****@*****.**']
        self.assertEqual('text/plain; charset="utf-8"',
                         mailSent.get('Content-Type'))
        self.assertEqual('*****@*****.**', mailSent.get('From'))
        # The output message should be a utf-8 encoded string
        self.assertEqual(
            u"Päge 'Wälkommen' created in http://nohost/plone/f1/d1 !",
            mailSent.get_payload(decode=True).decode('utf8'))

        # check interpolation of $reviewer_emails
        self.assertTrue('*****@*****.**' in sent_mails)

        # check interpolation of $manager_emails
        self.assertTrue('*****@*****.**' in sent_mails)

        # check interpolation of $member_emails
        emails = [
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
        ]
        self.assertEqual(
            set(emails),
            set(sent_mails.keys()))
        self._teardown_mockmail()
示例#19
0
    def testExecuteExcludeActor(self):
        self.loginAsPortalOwner()
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummyMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        self.portal.portal_membership.getAuthenticatedMember().setProperties(email='*****@*****.**')
        e = MailAction()
        e.source = "$user_email"
        e.exclude_actor = True
        e.recipients = "[email protected], [email protected]"
        e.message = u"A dummy event juste happened !!!!!"
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        self.assertEqual(len(dummyMailHost.sent), 1)

        mailSent = dummyMailHost.sent[0]
        self.assertEqual("*****@*****.**", mailSent.get('To'))
    def testExecuteExcludeActor(self):
        self.loginAsPortalOwner()
        sm = getSiteManager(self.portal)
        sm.unregisterUtility(provided=IMailHost)
        dummyMailHost = DummyMailHost('dMailhost')
        sm.registerUtility(dummyMailHost, IMailHost)
        self.portal.portal_membership.getAuthenticatedMember().setProperties(email='*****@*****.**')
        e = MailAction()
        e.source = "$user_email"
        e.exclude_actor = True
        e.recipients = "[email protected], [email protected]"
        e.message = u"A dummy event juste happened !!!!!"
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        self.assertEqual(len(dummyMailHost.sent), 1)

        mailSent = dummyMailHost.sent[0]
        self.assertEqual("*****@*****.**", mailSent.get('To'))
示例#21
0
 def testExecuteMultiRecipients(self):
     dummyMailHost = self._setup_mockmail()
     e = MailAction()
     e.source = '*****@*****.**'
     e.recipients = '[email protected],[email protected]'
     e.message = 'Document created !'
     ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                          IExecutable)
     ex()
     self.assertEqual(len(dummyMailHost.messages), 2)
     mailSent = message_from_string(dummyMailHost.messages[0])
     self.assertEqual('text/plain; charset="utf-8"',
                      mailSent.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent.get('To'))
     self.assertEqual('*****@*****.**', mailSent.get('From'))
     self.assertEqual('Document created !', mailSent.get_payload(decode=True))
     mailSent = message_from_string(dummyMailHost.messages[1])
     self.assertEqual('text/plain; charset="utf-8"',
                      mailSent.get('Content-Type'))
     self.assertEqual('*****@*****.**', mailSent.get('To'))
     self.assertEqual('*****@*****.**', mailSent.get('From'))
     self.assertEqual('Document created !', mailSent.get_payload(decode=True))
     self._teardown_mockmail()
示例#22
0
    def testExecute(self):
        self.loginAsPortalOwner()   # this avoids sending mail as [email protected]
        self.portal.portal_membership.getAuthenticatedMember().setProperties(
            email='*****@*****.**')
        dummyMailHost = self._setup_mockmail()
        e = MailAction()
        e.source = "$user_email"
        e.recipients = "[email protected], [email protected], $reviewer_emails, $manager_emails, $member_emails"   # noqa
        e.message = "P\xc3\xa4ge '${title}' created in ${url} !".decode('utf-8')
        ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)),
                             IExecutable)
        ex()
        sent_mails = {}
        for mail_sent in dummyMailHost.messages:
            mail_sent_msg = message_from_string(mail_sent)
            sent_mails[mail_sent_msg.get('To')] = mail_sent_msg

        mailSent = sent_mails['*****@*****.**']
        self.assertEqual('text/plain; charset="utf-8"',
                         mailSent.get('Content-Type'))
        self.assertEqual("*****@*****.**", mailSent.get('From'))
        # The output message should be a utf-8 encoded string
        self.assertEqual(
            "P\xc3\xa4ge 'W\xc3\xa4lkommen' created in http://nohost/plone/Members/test_user_1_/d1 !",  # noqa
            mailSent.get_payload(decode=True))

        # check interpolation of $reviewer_emails
        self.assertTrue("*****@*****.**" in sent_mails)

        # check interpolation of $manager_emails
        self.assertTrue("*****@*****.**" in sent_mails)

        # check interpolation of $member_emails
        self.assertEqual(
            set(["*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", ]),  # noqa
            set(sent_mails.keys()))
        self._teardown_mockmail()