Esempio n. 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 <*****@*****.**>')
Esempio n. 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 <*****@*****.**>')
Esempio n. 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!")
Esempio n. 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!",
         )
Esempio n. 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!",
         )
Esempio n. 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!",
        )
Esempio n. 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!',
        )
Esempio n. 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 <*****@*****.**>')
Esempio n. 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 <*****@*****.**>')
Esempio n. 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 <*****@*****.**>')
Esempio n. 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 <*****@*****.**>')
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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",
            )
Esempio n. 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",
            )