blueprint name may not contain a dot
This commit is contained in:
parent
d8c37f4372
commit
7c5261407d
4 changed files with 28 additions and 85 deletions
|
|
@ -1,5 +1,3 @@
|
|||
import functools
|
||||
|
||||
import pytest
|
||||
from jinja2 import TemplateNotFound
|
||||
from werkzeug.http import parse_cache_control_header
|
||||
|
|
@ -253,28 +251,9 @@ def test_templates_list(test_apps):
|
|||
assert templates == ["admin/index.html", "frontend/index.html"]
|
||||
|
||||
|
||||
def test_dotted_names(app, client):
|
||||
frontend = flask.Blueprint("myapp.frontend", __name__)
|
||||
backend = flask.Blueprint("myapp.backend", __name__)
|
||||
|
||||
@frontend.route("/fe")
|
||||
def frontend_index():
|
||||
return flask.url_for("myapp.backend.backend_index")
|
||||
|
||||
@frontend.route("/fe2")
|
||||
def frontend_page2():
|
||||
return flask.url_for(".frontend_index")
|
||||
|
||||
@backend.route("/be")
|
||||
def backend_index():
|
||||
return flask.url_for("myapp.frontend.frontend_index")
|
||||
|
||||
app.register_blueprint(frontend)
|
||||
app.register_blueprint(backend)
|
||||
|
||||
assert client.get("/fe").data.strip() == b"/be"
|
||||
assert client.get("/fe2").data.strip() == b"/fe"
|
||||
assert client.get("/be").data.strip() == b"/fe"
|
||||
def test_dotted_name_not_allowed(app, client):
|
||||
with pytest.raises(ValueError):
|
||||
flask.Blueprint("app.ui", __name__)
|
||||
|
||||
|
||||
def test_dotted_names_from_app(app, client):
|
||||
|
|
@ -343,62 +322,19 @@ def test_route_decorator_custom_endpoint(app, client):
|
|||
def test_route_decorator_custom_endpoint_with_dots(app, client):
|
||||
bp = flask.Blueprint("bp", __name__)
|
||||
|
||||
@bp.route("/foo")
|
||||
def foo():
|
||||
return flask.request.endpoint
|
||||
with pytest.raises(ValueError):
|
||||
bp.route("/", endpoint="a.b")(lambda: "")
|
||||
|
||||
try:
|
||||
with pytest.raises(ValueError):
|
||||
bp.add_url_rule("/", endpoint="a.b")
|
||||
|
||||
@bp.route("/bar", endpoint="bar.bar")
|
||||
def foo_bar():
|
||||
return flask.request.endpoint
|
||||
def view():
|
||||
return ""
|
||||
|
||||
except AssertionError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("expected AssertionError not raised")
|
||||
view.__name__ = "a.b"
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
bp.add_url_rule(
|
||||
"/bar/456", endpoint="foofoofoo", view_func=functools.partial(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
|
||||
with pytest.raises(ValueError):
|
||||
bp.add_url_rule("/", view_func=view)
|
||||
|
||||
|
||||
def test_endpoint_decorator(app, client):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue