Browse Source

Added tests, removed needless comment from me

pull/2672/head
Julian DeMille 7 years ago
parent
commit
a6000545fa
No known key found for this signature in database
GPG Key ID: 5F1028E38F636961
  1. 3
      flask/blueprints.py
  2. 74
      tests/test_blueprints.py

3
flask/blueprints.py

@ -237,9 +237,6 @@ class Blueprint(_PackageBoundObject):
"""Like :meth:`Flask.add_url_rule` but for a blueprint. The endpoint for
the :func:`url_for` function is prefixed with the name of the blueprint.
"""
# Following block commented out for support of nested blueprints.
# if endpoint:
# assert '.' not in endpoint, "Blueprint endpoints should not contain dots"
if view_func:
assert '.' not in view_func.__name__, "Blueprint view function name should not contain dots"
self.record(lambda s:

74
tests/test_blueprints.py

@ -332,66 +332,6 @@ def test_route_decorator_custom_endpoint(app, client):
assert client.get('/py/bar/foo').data == b'bp.bar_foo'
def test_route_decorator_custom_endpoint_with_dots(app, client):
bp = flask.Blueprint('bp', __name__)
@bp.route('/foo')
def foo():
return flask.request.endpoint
try:
@bp.route('/bar', endpoint='bar.bar')
def foo_bar():
return flask.request.endpoint
except AssertionError:
pass
else:
raise AssertionError('expected AssertionError not raised')
try:
@bp.route('/bar/123', endpoint='bar.123')
def foo_bar_foo():
return flask.request.endpoint
except AssertionError:
pass
else:
raise AssertionError('expected AssertionError not raised')
def foo_foo_foo():
pass
pytest.raises(
AssertionError,
lambda: bp.add_url_rule(
'/bar/123', endpoint='bar.123', view_func=foo_foo_foo
)
)
pytest.raises(
AssertionError,
bp.route('/bar/123', endpoint='bar.123'),
lambda: None
)
foo_foo_foo.__name__ = 'bar.123'
pytest.raises(
AssertionError,
lambda: bp.add_url_rule(
'/bar/123', view_func=foo_foo_foo
)
)
app.register_blueprint(bp, url_prefix='/py')
assert client.get('/py/foo').data == b'bp.foo'
# The rule's didn't actually made it through
rv = client.get('/py/bar')
assert rv.status_code == 404
rv = client.get('/py/bar/123')
assert rv.status_code == 404
def test_endpoint_decorator(app, client):
from werkzeug.routing import Rule
app.url_map.add(Rule('/foo', endpoint='bar'))
@ -840,3 +780,17 @@ def test_app_url_processors(app, client):
assert client.get('/de/').data == b'/de/about'
assert client.get('/de/about').data == b'/de/'
def test_sub_blueprint_route_register(app, client):
bp2 = flask.Blueprint('bp2', __name__)
@bp2.route('/test')
def bp2_test():
return "BP2"
bp1 = flask.Blueprint('bp1', __name__)
bp1.register_blueprint(bp2, url_prefix='/bp2')
app.register_blueprint(bp1, url_prefix='/bp1')
found_route = False
for rule in app.url_map.iter_rules():
if rule.rule == '/bp1/bp2/test': found_route = True
assert found_route is True, "Did not find route /bp1/bp2/test in app!"

Loading…
Cancel
Save