def test_extension_use_the_application_bound_to_the_current_context(app, mail): mailer = Mailer() mailer.init_app(app) with app.test_request_context(): mailer.send(mail) assert mailer.outbox == [mail,]
def test_extension_raises_error_if_no_application_bound_to_context(app, mail): mailer = Mailer() mailer.init_app(app) with pytest.raises(RuntimeError) as exc: mailer.send(mail) assert 'no application bound to current context' in exc.exconly()
def test_extension_raises_error_if_not_properly_initialized(app, mail): mailer = Mailer() err = 'Mailer extension does not registered ' \ 'with current application or' \ 'no application bound to current context' with pytest.raises(RuntimeError) as exc: mailer.send(mail) assert err in exc.exconly() with app.test_request_context(): with pytest.raises(RuntimeError) as exc: mailer.send(mail) assert err in exc.exconly()
from flask import Flask from flask_mailer import Mailer, Email app = Flask(__name__) smtp = Mailer(app) mail = Email(subject='hi, there', text='awesome message', to=['*****@*****.**'], from_addr='*****@*****.**') smtp.send(mail)