|
1 | | -import functools |
2 | | - |
3 | 1 | import pytest |
4 | 2 | from jinja2 import TemplateNotFound |
5 | 3 | from werkzeug.http import parse_cache_control_header |
@@ -253,28 +251,9 @@ def test_templates_list(test_apps): |
253 | 251 | assert templates == ["admin/index.html", "frontend/index.html"] |
254 | 252 |
|
255 | 253 |
|
256 | | -def test_dotted_names(app, client): |
257 | | - frontend = flask.Blueprint("myapp.frontend", __name__) |
258 | | - backend = flask.Blueprint("myapp.backend", __name__) |
259 | | - |
260 | | - @frontend.route("/fe") |
261 | | - def frontend_index(): |
262 | | - return flask.url_for("myapp.backend.backend_index") |
263 | | - |
264 | | - @frontend.route("/fe2") |
265 | | - def frontend_page2(): |
266 | | - return flask.url_for(".frontend_index") |
267 | | - |
268 | | - @backend.route("/be") |
269 | | - def backend_index(): |
270 | | - return flask.url_for("myapp.frontend.frontend_index") |
271 | | - |
272 | | - app.register_blueprint(frontend) |
273 | | - app.register_blueprint(backend) |
274 | | - |
275 | | - assert client.get("/fe").data.strip() == b"/be" |
276 | | - assert client.get("/fe2").data.strip() == b"/fe" |
277 | | - assert client.get("/be").data.strip() == b"/fe" |
| 254 | +def test_dotted_name_not_allowed(app, client): |
| 255 | + with pytest.raises(ValueError): |
| 256 | + flask.Blueprint("app.ui", __name__) |
278 | 257 |
|
279 | 258 |
|
280 | 259 | def test_dotted_names_from_app(app, client): |
@@ -343,62 +322,19 @@ def index(): |
343 | 322 | def test_route_decorator_custom_endpoint_with_dots(app, client): |
344 | 323 | bp = flask.Blueprint("bp", __name__) |
345 | 324 |
|
346 | | - @bp.route("/foo") |
347 | | - def foo(): |
348 | | - return flask.request.endpoint |
349 | | - |
350 | | - try: |
351 | | - |
352 | | - @bp.route("/bar", endpoint="bar.bar") |
353 | | - def foo_bar(): |
354 | | - return flask.request.endpoint |
355 | | - |
356 | | - except AssertionError: |
357 | | - pass |
358 | | - else: |
359 | | - raise AssertionError("expected AssertionError not raised") |
360 | | - |
361 | | - try: |
362 | | - |
363 | | - @bp.route("/bar/123", endpoint="bar.123") |
364 | | - def foo_bar_foo(): |
365 | | - return flask.request.endpoint |
366 | | - |
367 | | - except AssertionError: |
368 | | - pass |
369 | | - else: |
370 | | - raise AssertionError("expected AssertionError not raised") |
371 | | - |
372 | | - def foo_foo_foo(): |
373 | | - pass |
374 | | - |
375 | | - pytest.raises( |
376 | | - AssertionError, |
377 | | - lambda: bp.add_url_rule("/bar/123", endpoint="bar.123", view_func=foo_foo_foo), |
378 | | - ) |
379 | | - |
380 | | - pytest.raises( |
381 | | - AssertionError, bp.route("/bar/123", endpoint="bar.123"), lambda: None |
382 | | - ) |
383 | | - |
384 | | - foo_foo_foo.__name__ = "bar.123" |
| 325 | + with pytest.raises(ValueError): |
| 326 | + bp.route("/", endpoint="a.b")(lambda: "") |
385 | 327 |
|
386 | | - pytest.raises( |
387 | | - AssertionError, lambda: bp.add_url_rule("/bar/123", view_func=foo_foo_foo) |
388 | | - ) |
| 328 | + with pytest.raises(ValueError): |
| 329 | + bp.add_url_rule("/", endpoint="a.b") |
389 | 330 |
|
390 | | - bp.add_url_rule( |
391 | | - "/bar/456", endpoint="foofoofoo", view_func=functools.partial(foo_foo_foo) |
392 | | - ) |
| 331 | + def view(): |
| 332 | + return "" |
393 | 333 |
|
394 | | - app.register_blueprint(bp, url_prefix="/py") |
| 334 | + view.__name__ = "a.b" |
395 | 335 |
|
396 | | - assert client.get("/py/foo").data == b"bp.foo" |
397 | | - # The rule's didn't actually made it through |
398 | | - rv = client.get("/py/bar") |
399 | | - assert rv.status_code == 404 |
400 | | - rv = client.get("/py/bar/123") |
401 | | - assert rv.status_code == 404 |
| 336 | + with pytest.raises(ValueError): |
| 337 | + bp.add_url_rule("/", view_func=view) |
402 | 338 |
|
403 | 339 |
|
404 | 340 | def test_endpoint_decorator(app, client): |
|
0 commit comments