Exemple #1
0
    def test_connection_arg(self):
        """Test connection argument to send_mail(), et. al."""
        mail.outbox = []

        # Send using non-default connection
        connection = get_connection('tests.CustomMail')
        send_mail('Subject', 'Content', '*****@*****.**', ['*****@*****.**'], connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, 'Subject')

        connection = get_connection('tests.CustomMail')
        send_mass_mail([
                ('Subject1', 'Content1', '*****@*****.**', ['*****@*****.**']),
                ('Subject2', 'Content2', '*****@*****.**', ['*****@*****.**']),
            ], connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 2)
        self.assertEqual(connection.test_outbox[0].subject, 'Subject1')
        self.assertEqual(connection.test_outbox[1].subject, 'Subject2')

        connection = get_connection('tests.CustomMail')
        mail_admins('Admin message', 'Content', connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, '[Flask] Admin message')

        connection = get_connection('tests.CustomMail')
        mail_managers('Manager message', 'Content', connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, '[Flask] Manager message')
    def test_connection_arg(self):
        """Test connection argument to send_mail(), et. al."""
        mail.outbox = []

        # Send using non-default connection
        connection = get_connection('tests.CustomMail')
        send_mail('Subject', 'Content', '*****@*****.**', ['*****@*****.**'], connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, 'Subject')

        connection = get_connection('tests.CustomMail')
        send_mass_mail([
                ('Subject1', 'Content1', '*****@*****.**', ['*****@*****.**']),
                ('Subject2', 'Content2', '*****@*****.**', ['*****@*****.**']),
            ], connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 2)
        self.assertEqual(connection.test_outbox[0].subject, 'Subject1')
        self.assertEqual(connection.test_outbox[1].subject, 'Subject2')

        connection = get_connection('tests.CustomMail')
        mail_admins('Admin message', 'Content', connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, '[Flask] Admin message')

        connection = get_connection('tests.CustomMail')
        mail_managers('Manager message', 'Content', connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, '[Flask] Manager message')
Exemple #3
0
 def test_empty_admins(self):
     """
     Test that mail_admins/mail_managers doesn't connect to the mail server
     if there are no recipients (#9383)
     """
     mail_admins('hi', 'there')
     self.assertEqual(self.get_mailbox_content(), [])
     mail_managers('hi', 'there')
     self.assertEqual(self.get_mailbox_content(), [])
 def test_empty_admins(self):
     """
     Test that mail_admins/mail_managers doesn't connect to the mail server
     if there are no recipients (#9383)
     """
     mail_admins('hi', 'there')
     self.assertEqual(self.get_mailbox_content(), [])
     mail_managers('hi', 'there')
     self.assertEqual(self.get_mailbox_content(), [])
Exemple #5
0
    def test_manager_and_admin_mail_prefix(self):
        """
        String prefix + lazy translated subject = bad output
        Regression for #13494
        """
        mail_managers('Subject', 'Content')
        message = self.get_the_message()
        self.assertEqual(message.get('subject'), '[Flask] Subject')

        self.flush_mailbox()
        mail_admins('Subject', 'Content')
        message = self.get_the_message()
        self.assertEqual(message.get('subject'), '[Flask] Subject')
Exemple #6
0
    def test_html_mail_admins(self):
        """Test html_message argument to mail_admins """
        mail_admins('Subject', 'Content', html_message='HTML Content')
        message = self.get_the_message()

        self.assertEqual(message.get('subject'), '[Flask] Subject')
        self.assertEqual(message.get_all('to'), ['*****@*****.**'])
        self.assertTrue(message.is_multipart())
        self.assertEqual(len(message.get_payload()), 2)
        self.assertEqual(message.get_payload(0).get_payload(), 'Content')
        self.assertEqual(message.get_payload(0).get_content_type(), 'text/plain')
        self.assertEqual(message.get_payload(1).get_payload(), 'HTML Content')
        self.assertEqual(message.get_payload(1).get_content_type(), 'text/html')
    def test_manager_and_admin_mail_prefix(self):
        """
        String prefix + lazy translated subject = bad output
        Regression for #13494
        """
        mail_managers('Subject', 'Content')
        message = self.get_the_message()
        self.assertEqual(message.get('subject'), '[Flask] Subject')

        self.flush_mailbox()
        mail_admins('Subject', 'Content')
        message = self.get_the_message()
        self.assertEqual(message.get('subject'), '[Flask] Subject')
    def test_html_mail_admins(self):
        """Test html_message argument to mail_admins """
        mail_admins('Subject', 'Content', html_message='HTML Content')
        message = self.get_the_message()

        self.assertEqual(message.get('subject'), '[Flask] Subject')
        self.assertEqual(message.get_all('to'), ['*****@*****.**'])
        self.assertTrue(message.is_multipart())
        self.assertEqual(len(message.get_payload()), 2)
        self.assertEqual(message.get_payload(0).get_payload(), 'Content')
        self.assertEqual(message.get_payload(0).get_content_type(), 'text/plain')
        self.assertEqual(message.get_payload(1).get_payload(), 'HTML Content')
        self.assertEqual(message.get_payload(1).get_content_type(), 'text/html')