Skip to content
Myr

Add test for Blueprint app-wide url processing

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The test add coverage for methods: Blueprint.app_url_defaults, and Blueprint.app_url_preprocessing. This PR increases the coverage of blueprint module by 2%.

authored by Randy Liou · committed by Randy Liou · parent 39f7aaa · Browse files · 1 file+27 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−0 removed

  • tests:+27 added−0 removed

1 file+27 added−0 removed

modified:tests/test_blueprints.py+27 added
789 unmodified lines
790 # second request791 resp = app.test_client().get('/').data792 assert resp == b'request|after'793 assert evts == ['first'] + ['before', 'after', 'teardown'] * 2794795796def test_app_url_processors(app, client):797 bp = flask.Blueprint('bp', __name__)798799 # Register app-wide url defaults and preprocessor on blueprint800 @bp.app_url_defaults801 def add_language_code(endpoint, values):802 values.setdefault('lang_code', flask.g.lang_code)803804 @bp.app_url_value_preprocessor805 def pull_lang_code(endpoint, values):806 flask.g.lang_code = values.pop('lang_code')807808 # Register route rules at the app level809 @app.route('/<lang_code>/')810 def index():811 return flask.url_for('about')812813 @app.route('/<lang_code>/about')814 def about():815 return flask.url_for('index')816817 app.register_blueprint(bp)818819 assert client.get('/de/').data == b'/de/about'820 assert client.get('/de/about').data == b'/de/'