From 3fce4898f84531142c6fa8ab34cf9dc4d0cc4e85 Mon Sep 17 00:00:00 2001 From: Randy Liou Date: Tue, 23 May 2017 16:22:58 -0700 Subject: [PATCH] Add test for Blueprint app-wide url processing 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%. --- tests/test_blueprints.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_blueprints.py b/tests/test_blueprints.py index 434fca37..98c5e37c 100644 --- a/tests/test_blueprints.py +++ b/tests/test_blueprints.py @@ -791,3 +791,30 @@ def test_app_request_processing(): resp = app.test_client().get('/').data assert resp == b'request|after' assert evts == ['first'] + ['before', 'after', 'teardown'] * 2 + + +def test_app_url_processors(app, client): + bp = flask.Blueprint('bp', __name__) + + # Register app-wide url defaults and preprocessor on blueprint + @bp.app_url_defaults + def add_language_code(endpoint, values): + values.setdefault('lang_code', flask.g.lang_code) + + @bp.app_url_value_preprocessor + def pull_lang_code(endpoint, values): + flask.g.lang_code = values.pop('lang_code') + + # Register route rules at the app level + @app.route('//') + def index(): + return flask.url_for('about') + + @app.route('//about') + def about(): + return flask.url_for('index') + + app.register_blueprint(bp) + + assert client.get('/de/').data == b'/de/about' + assert client.get('/de/about').data == b'/de/'