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'])
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)
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)
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, '*****@*****.**')
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)
def test_mail_renders_template(self): self.assertIn( 'MasoniteTesting', MailManager(self.app).driver('mailgun').to( '*****@*****.**').template('mail/welcome', { 'to': 'MasoniteTesting' }).message_body)
def test_log_driver(self): user = UserMock user.email = '*****@*****.**' self.assertEqual( MailManager(self.app).driver('log').to(user).to_addresses, ['*****@*****.**'])
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)
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)
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)
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)
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)
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>')
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)
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')
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)
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')
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>')
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)