Пример #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')
Пример #2
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')
Пример #3
0
 def test_console_stream_kwarg(self):
     """
     Test that the console backend can be pointed at an arbitrary stream.
     """
     s = StringIO()
     connection = get_connection(self.EMAIL_BACKEND, stream=s)
     send_mail('Subject', 'Content', '*****@*****.**', ['*****@*****.**'], connection=connection)
     self.assertTrue(s.getvalue().startswith('Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Subject\nFrom: [email protected]\nTo: [email protected]\nDate: '))
Пример #4
0
 def test_console_stream_kwarg(self):
     """
     Test that the console backend can be pointed at an arbitrary stream.
     """
     s = StringIO()
     connection = get_connection(self.EMAIL_BACKEND, stream=s)
     send_mail('Subject',
               'Content',
               '*****@*****.**', ['*****@*****.**'],
               connection=connection)
     self.assertTrue(s.getvalue().startswith(
         'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nSubject: Subject\nFrom: [email protected]\nTo: [email protected]\nDate: '
     ))
Пример #5
0
 def test_recipient_without_domain(self):
     """
     Regression test for Django #15042
     """
     self.assertTrue(send_mail("Subject", "Content", "tester", ["django"]))
     message = self.get_the_message()
     self.assertEqual(message.get('subject'), 'Subject')
     self.assertEqual(message.get('from'), "tester")
     self.assertEqual(message.get('to'), "django")
Пример #6
0
 def test_recipient_without_domain(self):
     """
     Regression test for Django #15042
     """
     self.assertTrue(send_mail("Subject", "Content", "tester", ["django"]))
     message = self.get_the_message()
     self.assertEqual(message.get('subject'), 'Subject')
     self.assertEqual(message.get('from'), "tester")
     self.assertEqual(message.get('to'), "django")
Пример #7
0
    def test_idn_send(self):
        """
        Regression test for Django #14301
        """
        self.assertTrue(send_mail('Subject', 'Content', 'from@öäü.com', ['to@öäü.com']))
        message = self.get_the_message()
        self.assertEqual(message.get('subject'), 'Subject')
        self.assertEqual(message.get('from'), '*****@*****.**')
        self.assertEqual(message.get('to'), '*****@*****.**')

        self.flush_mailbox()
        m = EmailMessage('Subject', 'Content', 'from@öäü.com',
                     ['to@öäü.com'], cc=['cc@öäü.com'])
        m.send()
        message = self.get_the_message()
        self.assertEqual(message.get('subject'), 'Subject')
        self.assertEqual(message.get('from'), '*****@*****.**')
        self.assertEqual(message.get('to'), '*****@*****.**')
        self.assertEqual(message.get('cc'), '*****@*****.**')
Пример #8
0
    def test_idn_send(self):
        """
        Regression test for Django #14301
        """
        self.assertTrue(send_mail('Subject', 'Content', 'from@öäü.com', [u'to@öäü.com']))
        message = self.get_the_message()
        self.assertEqual(message.get('subject'), 'Subject')
        self.assertEqual(message.get('from'), '*****@*****.**')
        self.assertEqual(message.get('to'), '*****@*****.**')

        self.flush_mailbox()
        m = EmailMessage('Subject', 'Content', 'from@öäü.com',
                     [u'to@öäü.com'], cc=[u'cc@öäü.com'])
        m.send()
        message = self.get_the_message()
        self.assertEqual(message.get('subject'), 'Subject')
        self.assertEqual(message.get('from'), '*****@*****.**')
        self.assertEqual(message.get('to'), '*****@*****.**')
        self.assertEqual(message.get('cc'), '*****@*****.**')