Example #1
0
    def test_send_email_long_lines_use_quoted_printable(self):
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(fromaddr=u'"По" <*****@*****.**>',
                                      toaddr='*****@*****.**',
                                      text=(u'0123456789' * 100) + u'\n\n' +
                                      (u'Громады стро ' * 100),
                                      reply_to=g.noreply,
                                      subject=u'По оживлённым берегам',
                                      message_id=h.gen_message_id())
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')

            for line in body:
                assert_less(len(line), 991)

            # plain text
            assert_in(
                '012345678901234567890123456789012345678901234567890123456789012345678901234=',
                body)
            assert_in(
                '=D0=93=D1=80=D0=BE=D0=BC=D0=B0=D0=B4=D1=8B =D1=81=D1=82=D1=80=D0=BE =D0=93=',
                body)
            # html
            assert_in(
                '<div class=3D"markdown_content"><p>0123456789012345678901234567890123456789=',
                body)
            assert_in(
                '<p>=D0=93=D1=80=D0=BE=D0=BC=D0=B0=D0=B4=D1=8B =D1=81=D1=82=D1=80=D0=BE =D0=',
                body)
Example #2
0
    def test_email_sender_to_headers(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(fromaddr=str(c.user._id),
                                      toaddr='*****@*****.**',
                                      text=u'This is a test',
                                      reply_to=g.noreply,
                                      subject=u'Test subject',
                                      sender=u'*****@*****.**',
                                      message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Sender: [email protected]', body)
            assert_in('To: [email protected]', body)

            _client.reset_mock()
            mail_tasks.sendmail(fromaddr=str(c.user._id),
                                destinations=[str(c.user._id)],
                                text=u'This is a test',
                                reply_to=u'*****@*****.**',
                                subject=u'Test subject',
                                sender=u'*****@*****.**',
                                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Sender: [email protected]', body)
            assert_in('To: [email protected]', body)
Example #3
0
    def test_email_references_header(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(fromaddr=str(c.user._id),
                                      toaddr='*****@*****.**',
                                      text=u'This is a test',
                                      reply_to=g.noreply,
                                      subject=u'Test subject',
                                      references=['a', 'b', 'c'],
                                      message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('References: <a> <b> <c>', body)

            _client.reset_mock()
            mail_tasks.sendmail(fromaddr=str(c.user._id),
                                destinations=[str(c.user._id)],
                                text=u'This is a test',
                                reply_to=g.noreply,
                                subject=u'Test subject',
                                references=u'ref',
                                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('References: <ref>', body)
Example #4
0
    def test_email_references_header(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(
                fromaddr=str(c.user._id),
                toaddr='*****@*****.**',
                text=u'This is a test',
                reply_to=g.noreply,
                subject=u'Test subject',
                references=['a', 'b', 'c'],
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('References: <a> <b> <c>', body)

            _client.reset_mock()
            mail_tasks.sendmail(
                fromaddr=str(c.user._id),
                destinations=[str(c.user._id)],
                text=u'This is a test',
                reply_to=g.noreply,
                subject=u'Test subject',
                references=u'ref',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('References: <ref>', body)
Example #5
0
    def test_sendsimplemail_with_disabled_user(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(fromaddr=str(c.user._id),
                                      toaddr='*****@*****.**',
                                      text=u'This is a test',
                                      reply_to=g.noreply,
                                      subject=u'Test subject',
                                      message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)

            c.user.disabled = True
            ThreadLocalORMSession.flush_all()
            mail_tasks.sendsimplemail(fromaddr=str(c.user._id),
                                      toaddr='*****@*****.**',
                                      text=u'This is a test',
                                      reply_to=g.noreply,
                                      subject=u'Test subject',
                                      message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 2)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: %s' % g.noreply, body)
Example #6
0
    def test_email_sender_to_headers(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(
                fromaddr=str(c.user._id),
                toaddr='*****@*****.**',
                text=u'This is a test',
                reply_to=g.noreply,
                subject=u'Test subject',
                sender=u'*****@*****.**',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Sender: [email protected]', body)
            assert_in('To: [email protected]', body)

            _client.reset_mock()
            mail_tasks.sendmail(
                fromaddr=str(c.user._id),
                destinations=[str(c.user._id)],
                text=u'This is a test',
                reply_to=u'*****@*****.**',
                subject=u'Test subject',
                sender=u'*****@*****.**',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Sender: [email protected]', body)
            assert_in('To: [email protected]', body)
Example #7
0
    def test_sendsimplemail_with_disabled_user(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(
                fromaddr=str(c.user._id),
                toaddr='*****@*****.**',
                text=u'This is a test',
                reply_to=g.noreply,
                subject=u'Test subject',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)

            c.user.disabled = True
            ThreadLocalORMSession.flush_all()
            mail_tasks.sendsimplemail(
                fromaddr=str(c.user._id),
                toaddr='*****@*****.**',
                text=u'This is a test',
                reply_to=g.noreply,
                subject=u'Test subject',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 2)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: %s' % g.noreply, body)
Example #8
0
 def test_fromaddr_objectid_not_str(self):
     c.user = M.User.by_username('test-admin')
     with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
         mail_tasks.sendsimplemail(fromaddr=c.user._id,
                                   toaddr='*****@*****.**',
                                   text=u'This is a test',
                                   reply_to=g.noreply,
                                   subject=u'Test subject',
                                   message_id=h.gen_message_id())
         assert_equal(_client.sendmail.call_count, 1)
         return_path, rcpts, body = _client.sendmail.call_args[0]
         assert_in('From: "Test Admin" <*****@*****.**>', body)
Example #9
0
 def test_fromaddr_objectid_not_str(self):
     c.user = M.User.by_username('test-admin')
     with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
         mail_tasks.sendsimplemail(
             fromaddr=c.user._id,
             toaddr='*****@*****.**',
             text=u'This is a test',
             reply_to=g.noreply,
             subject=u'Test subject',
             message_id=h.gen_message_id())
         assert_equal(_client.sendmail.call_count, 1)
         return_path, rcpts, body = _client.sendmail.call_args[0]
         assert_in('From: "Test Admin" <*****@*****.**>', body)
Example #10
0
 def test_cc(self):
     c.user = M.User.by_username('test-admin')
     with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
         mail_tasks.sendsimplemail(fromaddr=str(c.user._id),
                                   toaddr='*****@*****.**',
                                   text=u'This is a test',
                                   reply_to=g.noreply,
                                   subject=u'Test subject',
                                   cc=u'*****@*****.**',
                                   message_id=h.gen_message_id())
         assert_equal(_client.sendmail.call_count, 1)
         return_path, rcpts, body = _client.sendmail.call_args[0]
         assert_in('CC: [email protected]', body)
         assert_in('*****@*****.**', rcpts)
Example #11
0
 def test_cc(self):
     c.user = M.User.by_username('test-admin')
     with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
         mail_tasks.sendsimplemail(
             fromaddr=str(c.user._id),
             toaddr='*****@*****.**',
             text=u'This is a test',
             reply_to=g.noreply,
             subject=u'Test subject',
             cc=u'*****@*****.**',
             message_id=h.gen_message_id())
         assert_equal(_client.sendmail.call_count, 1)
         return_path, rcpts, body = _client.sendmail.call_args[0]
         assert_in('CC: [email protected]', body)
         assert_in('*****@*****.**', rcpts)
Example #12
0
    def test_send_email_long_lines_use_quoted_printable(self):
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(
                fromaddr=u'"По" <*****@*****.**>',
                toaddr='*****@*****.**',
                text=(u'0123456789' * 100) + u'\n\n' + (u'Громады стро ' * 100),
                reply_to=g.noreply,
                subject=u'По оживлённым берегам',
                message_id=h.gen_message_id())
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')

            for line in body:
                assert_less(len(line), 991)

            # plain text
            assert_in('012345678901234567890123456789012345678901234567890123456789012345678901234=', body)
            assert_in('=D0=93=D1=80=D0=BE=D0=BC=D0=B0=D0=B4=D1=8B =D1=81=D1=82=D1=80=D0=BE =D0=93=', body)
            # html
            assert_in('<div class=3D"markdown_content"><p>0123456789012345678901234567890123456789=', body)
            assert_in('<p>=D0=93=D1=80=D0=BE=D0=BC=D0=B0=D0=B4=D1=8B =D1=81=D1=82=D1=80=D0=BE =D0=', body)