Exemple #1
0
 def test_modified_message(self):
     mail = MailManager(self.app).driver('mailgun').to(
         '*****@*****.**').text('test text')
     data = mail.message()
     data['o:tag'] = ['Foo', 'Bar']
     data = mail.send(data)
     self.assertEqual(data['o:tag'], ['Foo', 'Bar'])
Exemple #2
0
 def test_mail_sends_with_queue_and_without_queue(self):
     if env('RUN_MAIL'):
         self.assertEqual(
             MailManager(self.app).driver('mailgun').to(
                 '*****@*****.**').send('test queue'), None)
         self.assertEqual(
             MailManager(self.app).driver('mailgun').queue().to(
                 '*****@*****.**').send('test queue'), None)
Exemple #3
0
 def test_mail_text_and_html_content(self):
     mail = MailManager(self.app).driver('smtp').to('*****@*****.**').text(text_content).html(html_content)
     self.assertIn(html_content, mail.html_content)
     self.assertEqual(mail.message_body, mail.html_content)
     self.assertEqual(mail.text_content, text_content)
     _, _, message_as_string = mail.send()
     self.assertIn('Content-Type: text/plain', message_as_string)
     self.assertIn('Content-Type: text/html', message_as_string)
Exemple #4
0
        def test_mailgun_driver(self):
            user = UserMock
            user.email = '*****@*****.**'

            self.assertEqual(
                MailManager(self.app).driver('mailgun').to(user).to_addresses,
                ['*****@*****.**'])
            self.assertEqual(
                MailManager(self.app).driver('mailgun').reply_to(
                    '*****@*****.**').message_reply_to,
                '*****@*****.**')
Exemple #5
0
 def test_custom_message(self):
     mail = MailManager(self.app).driver('smtp')
     message = MIMEMultipart('alternative')
     message['From'] = '*****@*****.**'
     message['Cc'] = '*****@*****.**'
     message.add_header('X-My-Custom-Header', 'my custom value')
     _, _, message_as_string = mail.to('*****@*****.**').text('test text').send(message)
     self.assertIn('From: [email protected]\n', message_as_string)
     self.assertIn('Cc: [email protected]\n', message_as_string)
     self.assertIn('X-My-Custom-Header: my custom value\n', message_as_string)
     self.assertNotIn('Subject:', message_as_string)
     self.assertNotIn('test text', message_as_string)
Exemple #6
0
 def test_mail_renders_template(self):
     self.assertIn(
         'MasoniteTesting',
         MailManager(self.app).driver('mailgun').to(
             '*****@*****.**').template('mail/welcome', {
                 'to': 'MasoniteTesting'
             }).message_body)
Exemple #7
0
    def test_log_driver(self):
        user = UserMock
        user.email = '*****@*****.**'

        self.assertEqual(
            MailManager(self.app).driver('log').to(user).to_addresses,
            ['*****@*****.**'])
Exemple #8
0
    def test_terminal_driver(self):
        user = UserMock
        user.email = ['*****@*****.**']

        self.assertEqual(
            MailManager(self.app).driver('terminal').to(user).to_addresses,
            ['*****@*****.**'])
 def test_mail_renders_template_with_both_mimetypes(self):
     mail = MailManager(self.app).driver('base').to('*****@*****.**')\
         .template('mail/welcome.html', {'to': 'MasoniteHTMLTesting'}, mimetype='html')\
         .template('mail/welcome.txt', {'to': 'MasoniteTextTesting'}, mimetype='plain')
     self.assertIn(html_content, mail.html_content)
     self.assertEqual(mail.message_body, mail.html_content)
     self.assertEqual(mail.text_content, text_content)
Exemple #10
0
 def test_works(self):
     mailable = MailManager(self.container).driver('smtp').mailable(ForgotPasswordMailable())
     self.assertEqual(mailable.to_addresses, ['*****@*****.**'])
     self.assertEqual(mailable.from_address, '*****@*****.**')
     self.assertEqual(mailable.message_subject, 'Forgot Password')
     self.assertEqual(mailable.message_body, 'testing email')
     self.assertEqual(mailable.message_reply_to, '*****@*****.**')
     self.assertTrue(True)
Exemple #11
0
 def test_custom_message(self):
     data = {
         'from': '*****@*****.**',
         'to': '*****@*****.**',
         'subject': 'Custom Message',
         'text': 'Custom Text',
     }
     self.assertEqual(
         MailManager(self.app).driver('mailgun').to(
             '*****@*****.**').text('test text').send(data), data)
Exemple #12
0
    def test_terminal_driver_output(self):
        user = UserMock
        user.email = '*****@*****.**'
        with captured_output() as (_, err):
            MailManager(self.app).driver('terminal').to(user).reply_to(
                '*****@*****.**').send('Masonite')

        # This can go inside or outside the `with` block
        error = err.getvalue().strip()
        self.assertIn('*****@*****.**', error)
        self.assertIn('*****@*****.**', error)
Exemple #13
0
    def test_log_driver_output(self):
        user = UserMock
        user.email = '*****@*****.**'

        MailManager(self.app).driver('log').to(user).reply_to(
            '*****@*****.**').send('Masonite')

        filepath = '{0}/{1}'.format('bootstrap/mail', 'mail.log')
        self.logfile = open(filepath, 'r')
        file_string = self.logfile.read()

        self.assertIn('*****@*****.**', file_string)
        self.assertIn('*****@*****.**', file_string)
Exemple #14
0
 def test_html_together_with_text_content(self):
     data = MailManager(
         self.app).driver('mailgun').to('*****@*****.**').html(
             '<div>Hello</div>').text('hello').send()
     self.assertEqual(data['text'], 'hello')
     self.assertEqual(data['html'], '<div>Hello</div>')
Exemple #15
0
 def test_modified_message(self):
     mail = MailManager(self.app).driver('smtp').to('*****@*****.**').text(text_content).html(html_content)
     message = mail.message()
     message['Bcc'] = '*****@*****.**'
     _, _, message_as_string = mail.send(message)
     self.assertIn('Bcc: [email protected]\n', message_as_string)
Exemple #16
0
 def test_text_content_only(self):
     data = MailManager(self.app).driver('mailgun').to(
         '*****@*****.**').text('hello').send()
     self.assertNotIn('html', data)
     self.assertEqual(data['text'], 'hello')
Exemple #17
0
 def test_deprecated_send_method_using_named_arg(self):
     with self.assertWarns(DeprecationWarning) as dw:
         mail = MailManager(self.app).driver('mailgun')
         data = mail.to('*****@*****.**').text('My Text').html(
             'My HTML').send(message='<div>Foo</div>')
         self._assert_deprecated_send_method(data, dw)
Exemple #18
0
 def test_passing_message_to_send(self):
     data = MailManager(
         self.app).driver('mailgun').to('*****@*****.**').text(
             'hello').html('<div>hello</div>').send('Foo')
     self.assertNotIn('text', data)
     self.assertEqual(data['html'], 'Foo')
Exemple #19
0
 def test_html_content_only(self):
     data = MailManager(self.app).driver('mailgun').to(
         '*****@*****.**').html('<div>Hello</div>').send()
     self.assertNotIn('text', data)
     self.assertEqual(data['html'], '<div>Hello</div>')
Exemple #20
0
 def test_deprecated_send_method_using_named_arg(self):
     with self.assertWarns(DeprecationWarning) as dw:
         mail = MailManager(self.app).driver('smtp')
         _, _, message_as_string = mail.to('*****@*****.**').text('My Text').html('My HTML').send(message_contents='<div>Foo</div>')
         self._assert_deprecated_send_method(message_as_string, dw)