本文整理汇总了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)