当前位置: 首页>>代码示例>>Python>>正文


Python Mail.record_messages方法代码示例

本文整理汇总了Python中flask.ext.mail.Mail.record_messages方法的典型用法代码示例。如果您正苦于以下问题:Python Mail.record_messages方法的具体用法?Python Mail.record_messages怎么用?Python Mail.record_messages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.ext.mail.Mail的用法示例。


在下文中一共展示了Mail.record_messages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EmailActivationTest

# 需要导入模块: from flask.ext.mail import Mail [as 别名]
# 或者: from flask.ext.mail.Mail import record_messages [as 别名]
class EmailActivationTest(TestCase):
    def setUp(self):
        self.app = Flask(__name__)
        self.app.register_blueprint(emailactivation.views.app)
        self.app.config['SECRET_KEY'] = 'SECRET'
        self.mail = Mail(self.app)
        
        @self.app.route('/index')
        def index():
            return 'index'
        
    def testSendEmail(self):
        callback = my_callback
        
        data = {'mail':'[email protected]'}
        email = {'subject':'subject', 
                 'sender':'[email protected]'}
        with patch('test_activation.my_callback') as c:
            with self.app.test_request_context():
                c.return_value = url_for('index') 
                signature = signature_serialize(callback, data)
                with self.mail.record_messages() as outbox:
                    send_activation_email(self.mail,
                                          '[email protected]',
                                          callback=callback,
                                          data=data,
                                          email_context=email,
                                          template_context={},
                                          body_template='test.html')
                                      
                self.assertEquals(1, len(outbox), 'Email was sent')
                self.assertIn(url_for('emailactivation.activation', 
                                      signature=signature, _external=True),
                              outbox[0].body)
                
                with self.app.test_client() as client:
                    response = client.get(url_for('emailactivation.activation', 
                                                   signature=signature,))
                    self.assertEquals(302, response.status_code)
                    self.assertEquals(url_for('index', _external=True), 
                                      response.location)
开发者ID:tomasd,项目名称:flask-emailactivation,代码行数:43,代码来源:test_activation.py


注:本文中的flask.ext.mail.Mail.record_messages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。