示例#1
0
    def test_send_email(self):
        """Test sending mail."""

        self.mailhost.reset()

        portal.send_email(
            recipient="*****@*****.**",
            sender="*****@*****.**",
            subject="Trappist",
            body=u"One for you Bob!",
        )

        self.assertEqual(len(self.mailhost.messages), 1)
        msg = message_from_string(self.mailhost.messages[0])
        self.assertEqual(msg['To'], '*****@*****.**')
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Subject'], '=?utf-8?q?Trappist?=')
        self.assertEqual(msg.get_payload(), u'One for you Bob!')
        self.mailhost.reset()

        # When no sender is set, we take the portal properties.
        portal.send_email(
            recipient="*****@*****.**",
            subject="Trappist",
            body=u"One for you Bob!",
        )

        self.assertEqual(len(self.mailhost.messages), 1)
        msg = message_from_string(self.mailhost.messages[0])
        self.assertEqual(msg['From'], 'Portal Owner <*****@*****.**>')
示例#2
0
    def test_send_email(self):
        """Test sending mail."""

        self.mailhost.reset()

        portal.send_email(
            recipient="*****@*****.**",
            sender="*****@*****.**",
            subject="Trappist",
            body=u"One for you Bob!",
        )

        self.assertEqual(len(self.mailhost.messages), 1)
        msg = message_from_string(self.mailhost.messages[0])
        self.assertEqual(msg['To'], '*****@*****.**')
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Subject'], '=?utf-8?q?Trappist?=')
        self.assertEqual(msg.get_payload(), u'One for you Bob!')
        self.mailhost.reset()

        # When no sender is set, we take the portal properties.
        portal.send_email(
            recipient="*****@*****.**",
            subject="Trappist",
            body=u"One for you Bob!",
        )

        self.assertEqual(len(self.mailhost.messages), 1)
        msg = message_from_string(self.mailhost.messages[0])
        self.assertEqual(msg['From'], 'Portal Owner <*****@*****.**>')
示例#3
0
    def test_send_email_parseaddr(self, mock_parseaddr):
        """Simulate faulty parsing in parseaddr, from_address should be
        default email_from_address.
        """

        self.mailhost.reset()

        mock_parseaddr.return_value = ("Chuck Norris", "*****@*****.**")
        portal.send_email(recipient="*****@*****.**", subject="Trappist", body=u"One for you Bob!")
示例#4
0
 def test_send_email_without_configured_mailhost(self):
     """By default, the MailHost is not configured yet, so we cannot
     send email.
     """
     self.portal._updateProperty('email_from_address', None)
     with self.assertRaises(ValueError):
         portal.send_email(
             recipient="*****@*****.**",
             sender="*****@*****.**",
             subject="Trappist",
             body=u"One for you Bob!",
         )
示例#5
0
 def test_send_email_without_configured_mailhost(self):
     """By default, the MailHost is not configured yet, so we cannot
     send email.
     """
     self.portal._updateProperty('email_from_address', None)
     with self.assertRaises(ValueError):
         portal.send_email(
             recipient="*****@*****.**",
             sender="*****@*****.**",
             subject="Trappist",
             body=u"One for you Bob!",
         )
示例#6
0
    def test_send_email_parseaddr(self, mock_parseaddr):
        """Simulate faulty parsing in parseaddr, from_address should be
        default email_from_address.
        """

        self.mailhost.reset()

        mock_parseaddr.return_value = ('Chuck Norris', '*****@*****.**')
        portal.send_email(
            recipient="*****@*****.**",
            subject="Trappist",
            body=u"One for you Bob!",
        )
示例#7
0
    def test_send_email_parseaddr(self, mock_parseaddr):
        """Simulate faulty parsing in parseaddr, from_address should be
        default email_from_address.
        """

        self.mailhost.reset()

        mock_parseaddr.return_value = ('Chuck Norris', '*****@*****.**')
        portal.send_email(
            recipient='*****@*****.**',
            subject='Trappist',
            body=u'One for you Bob!',
        )
示例#8
0
 def test_send_email_with_config_in_portal_properties(self):
     """Test mail-setting being stored in portal_properties.
     Before Plone 5.0b2 the settings were stored in portal_properties.
     """
     self.portal._updateProperty('email_from_name', 'Properties')
     self.portal._updateProperty('email_from_address', '*****@*****.**')
     self.mailhost.reset()
     portal.send_email(
         recipient="*****@*****.**",
         subject="Trappist",
         body=u"One for you Bob!",
     )
     self.assertEqual(len(self.mailhost.messages), 1)
     msg = message_from_string(self.mailhost.messages[0])
     self.assertEqual(msg['From'], 'Properties <*****@*****.**>')
示例#9
0
 def test_send_email_with_config_in_portal_properties(self):
     """Test mail-setting being stored in portal_properties.
     Before Plone 5.0b2 the settings were stored in portal_properties.
     """
     self.portal._updateProperty('email_from_name', 'Properties')
     self.portal._updateProperty('email_from_address', '*****@*****.**')
     self.mailhost.reset()
     portal.send_email(
         recipient='*****@*****.**',
         subject='Trappist',
         body=u'One for you Bob!',
     )
     self.assertEqual(len(self.mailhost.messages), 1)
     msg = message_from_string(self.mailhost.messages[0])
     self.assertEqual(msg['From'], 'Properties <*****@*****.**>')
示例#10
0
    def test_send_email_with_config_in_registry(self):
        """Test mail-setting being stored in registry
        """
        self.mailhost.reset()

        portal.set_registry_record('plone.email_from_address',
                                   '*****@*****.**')  # ASCII
        portal.set_registry_record('plone.email_from_name',
                                   u'Registry')  # TextLine
        portal.send_email(
            recipient="*****@*****.**",
            subject="Trappist",
            body=u"One for you Bob!",
        )
        self.assertEqual(len(self.mailhost.messages), 1)
        msg = message_from_string(self.mailhost.messages[0])
        self.assertEqual(msg['From'], 'Registry <*****@*****.**>')
示例#11
0
    def test_send_email_with_config_in_registry(self):
        """Test mail-setting being stored in registry
        """
        self.mailhost.reset()

        portal.set_registry_record('plone.email_from_address',
                                   '*****@*****.**')  # ASCII
        portal.set_registry_record('plone.email_from_name',
                                   u'Registry')  # TextLine
        portal.send_email(
            recipient='*****@*****.**',
            subject='Trappist',
            body=u'One for you Bob!',
        )
        self.assertEqual(len(self.mailhost.messages), 1)
        msg = message_from_string(self.mailhost.messages[0])
        self.assertEqual(msg['From'], 'Registry <*****@*****.**>')
示例#12
0
    def test_send_email_with_printingmailhost(self):
        """ Test that send_email does not raise an exception when
        Products.PrintingMailHost is installed and active.
        """
        old_flag = portal.PRINTINGMAILHOST_ENABLED

        if HAS_PLONE5:
            old_value = portal.get_registry_record('plone.email_from_address')
            portal.set_registry_record('plone.email_from_address', '')  # ASCII
        else:
            old_smtp_host = self.portal.MailHost.smtp_host
            self.portal.MailHost.smtp_host = None

        # PrintingMailHost disabled
        portal.PRINTINGMAILHOST_ENABLED = False
        with self.assertRaises(ValueError):
            portal.send_email(
                recipient='*****@*****.**',
                sender='*****@*****.**',
                subject='Trappist',
                body=u'One for you Bob!',
            )

        # PrintingMailHost enabled
        portal.PRINTINGMAILHOST_ENABLED = True
        portal.send_email(
            recipient='*****@*****.**',
            sender='*****@*****.**',
            subject='Trappist',
            body=u'One for you Bob!',
        )

        # Prevents sideeffects in other tests.
        if HAS_PLONE5:
            portal.set_registry_record('plone.email_from_address', old_value)
        else:
            self.portal.MailHost.smtp_host = old_smtp_host
        portal.PRINTINGMAILHOST_ENABLED = old_flag
示例#13
0
    def test_send_email_with_printingmailhost(self):
        """ Test that send_email does not raise an exception when
        Products.PrintingMailHost is installed and active.
        """
        old_flag = portal.PRINTINGMAILHOST_ENABLED

        if HAS_PLONE5:
            old_value = portal.get_registry_record('plone.email_from_address')
            portal.set_registry_record('plone.email_from_address', '')  # ASCII
        else:
            old_smtp_host = self.portal.MailHost.smtp_host
            self.portal.MailHost.smtp_host = None

        # PrintingMailHost disabled
        portal.PRINTINGMAILHOST_ENABLED = False
        with self.assertRaises(ValueError):
            portal.send_email(
                recipient='*****@*****.**',
                sender='*****@*****.**',
                subject='Trappist',
                body=u'One for you Bob!'
            )

        # PrintingMailHost enabled
        portal.PRINTINGMAILHOST_ENABLED = True
        portal.send_email(
            recipient='*****@*****.**',
            sender='*****@*****.**',
            subject='Trappist',
            body=u'One for you Bob!',
        )

        # Prevents sideeffects in other tests.
        if HAS_PLONE5:
            portal.set_registry_record('plone.email_from_address', old_value)
        else:
            self.portal.MailHost.smtp_host = old_smtp_host
        portal.PRINTINGMAILHOST_ENABLED = old_flag
示例#14
0
    def test_send_email_without_configured_mailhost(self):
        """By default, the MailHost is not configured yet, so we cannot
        send email.
        """
        if HAS_PLONE5:
            old_value = portal.get_registry_record('plone.email_from_address')
            portal.set_registry_record('plone.email_from_address', '')  # ASCII
        else:
            old_smtp_host = self.portal.MailHost.smtp_host
            self.portal.MailHost.smtp_host = None

        with self.assertRaises(ValueError):
            portal.send_email(
                recipient='*****@*****.**',
                sender='*****@*****.**',
                subject='Trappist',
                body=u'One for you Bob!',
            )

        if HAS_PLONE5:
            portal.set_registry_record('plone.email_from_address', old_value)
        else:
            self.portal.MailHost.smtp_host = old_smtp_host
示例#15
0
    def test_send_email_without_configured_mailhost(self):
        """By default, the MailHost is not configured yet, so we cannot
        send email.
        """
        if HAS_PLONE5:
            old_value = portal.get_registry_record('plone.email_from_address')
            portal.set_registry_record('plone.email_from_address', '')  # ASCII
        else:
            old_smtp_host = self.portal.MailHost.smtp_host
            self.portal.MailHost.smtp_host = None

        with self.assertRaises(ValueError):
            portal.send_email(
                recipient="*****@*****.**",
                sender="*****@*****.**",
                subject="Trappist",
                body=u"One for you Bob!",
            )

        if HAS_PLONE5:
            portal.set_registry_record('plone.email_from_address', old_value)
        else:
            self.portal.MailHost.smtp_host = old_smtp_host
示例#16
0
    def test_send_email_constraints(self):
        """Test the constraints for sending an email."""
        from plone.api.exc import MissingParameterError

        # When no parameters are given an error is raised
        with self.assertRaises(MissingParameterError):
            portal.send_email()

        # recipient, subject and body are required
        with self.assertRaises(MissingParameterError):
            portal.send_email(
                subject='Beer',
                body="To beer or not to beer, that is the question",
            )
        with self.assertRaises(MissingParameterError):
            portal.send_email(
                recipient='*****@*****.**',
                subject='Beer',
            )
        with self.assertRaises(MissingParameterError):
            portal.send_email(
                recipient='*****@*****.**',
                body="To beer or not to beer, that is the question",
            )
示例#17
0
    def test_send_email_constraints(self):
        """Test the constraints for sending an email."""
        from plone.api.exc import MissingParameterError

        # When no parameters are given an error is raised
        with self.assertRaises(MissingParameterError):
            portal.send_email()

        # recipient, subject and body are required
        with self.assertRaises(MissingParameterError):
            portal.send_email(
                subject='Beer',
                body="To beer or not to beer, that is the question",
            )
        with self.assertRaises(MissingParameterError):
            portal.send_email(
                recipient='*****@*****.**',
                subject='Beer',
            )
        with self.assertRaises(MissingParameterError):
            portal.send_email(
                recipient='*****@*****.**',
                body="To beer or not to beer, that is the question",
            )