def app(request): """Use `pytest.mark` decorator to pass options to your application factory:: @pytest.mark.app(static_folder='assets') def test_app(app): pass Set options to extension, e.g.:: @pytest.mark.config(foo=42) def test_app(app): pass """ options = dict(debug=True, testing=True, secret='secret') if 'app' in request.keywords: options.update(request.keywords['app'].kwargs) app = create_app(**options) if 'config' in request.keywords: for name, value in request.keywords['config'].kwargs.items(): app.config[key(name)] = value return app
def init_app(self, app): config = app.config config.setdefault(key('testing'), app.testing) config.setdefault(key('host'), 'localhost') config.setdefault(key('port'), 25) config.setdefault(key('use_tls'), False) config.setdefault(key('username'), None) config.setdefault(key('password'), None) config.setdefault(key('default_sender'), 'webmaster') config.setdefault(key('backend'), 'flask_mailer.backends.smtp.SMTPMailer') # Use dummy mailer for testing application. if config[key('testing')]: config[key('backend')] = 'flask_mailer.backends.dummy.DummyMailer' state = self.init_backend(config) # Register extension themselves for backwards compatibility. app.extensions = getattr(app, 'extensions', {}) app.extensions['mailer'] = state return state
def test_extension_config_overrides_application_config(app): Mailer(app) assert app.config[key('backend')] == 'flask_mailer.backends.dummy.DummyMailer'
def test_force_use_dummy_mailer_in_test_enviroment(app): Mailer(app) assert app.config[key('backend')] == 'flask_mailer.backends.dummy.DummyMailer'
def test_returns_uppercased_key(): assert key('port').isupper()
def test_attach_prefix_to_key(): assert key('host') == 'MAILER_HOST'