[pre-commit.ci lite] apply automatic fixes
This commit is contained in:
parent
fb763eaf61
commit
554fad132e
3 changed files with 139 additions and 0 deletions
|
|
@ -26,6 +26,7 @@ require_cpython_gc = pytest.mark.skipif(
|
|||
reason="Requires CPython GC behavior",
|
||||
)
|
||||
|
||||
|
||||
def test_options_work(app, client):
|
||||
@app.route("/", methods=["GET", "POST"])
|
||||
def index():
|
||||
|
|
@ -35,6 +36,7 @@ def test_options_work(app, client):
|
|||
assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]
|
||||
assert rv.data == b""
|
||||
|
||||
|
||||
def test_options_on_multiple_rules(app, client):
|
||||
@app.route("/", methods=["GET", "POST"])
|
||||
def index():
|
||||
|
|
@ -47,6 +49,7 @@ def test_options_on_multiple_rules(app, client):
|
|||
rv = client.open("/", method="OPTIONS")
|
||||
assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST", "PUT"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("method", ["get", "post", "put", "delete", "patch"])
|
||||
def test_method_route(app, client, method):
|
||||
method_route = getattr(app, method)
|
||||
|
|
@ -58,10 +61,12 @@ def test_method_route(app, client, method):
|
|||
|
||||
assert client_method("/").data == b"Hello"
|
||||
|
||||
|
||||
def test_method_route_no_methods(app):
|
||||
with pytest.raises(TypeError):
|
||||
app.get("/", methods=["GET", "POST"])
|
||||
|
||||
|
||||
def test_provide_automatic_options_attr():
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
|
|
@ -83,6 +88,7 @@ def test_provide_automatic_options_attr():
|
|||
rv = app.test_client().open("/", method="OPTIONS")
|
||||
assert sorted(rv.allow) == ["OPTIONS"]
|
||||
|
||||
|
||||
def test_provide_automatic_options_kwarg(app, client):
|
||||
def index():
|
||||
return flask.request.method
|
||||
|
|
@ -119,6 +125,7 @@ def test_provide_automatic_options_kwarg(app, client):
|
|||
rv = client.open("/more", method="OPTIONS")
|
||||
assert rv.status_code == 405
|
||||
|
||||
|
||||
def test_request_dispatching(app, client):
|
||||
@app.route("/")
|
||||
def index():
|
||||
|
|
@ -141,10 +148,12 @@ def test_request_dispatching(app, client):
|
|||
assert rv.status_code == 405
|
||||
assert sorted(rv.allow) == ["GET", "HEAD", "OPTIONS", "POST"]
|
||||
|
||||
|
||||
def test_disallow_string_for_allowed_methods(app):
|
||||
with pytest.raises(TypeError):
|
||||
app.add_url_rule("/", methods="GET POST", endpoint="test")
|
||||
|
||||
|
||||
def test_url_mapping(app, client):
|
||||
random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"
|
||||
|
||||
|
|
@ -180,6 +189,7 @@ def test_url_mapping(app, client):
|
|||
assert rv.status_code == 200
|
||||
assert random_uuid4 in rv.data.decode("utf-8")
|
||||
|
||||
|
||||
def test_werkzeug_routing(app, client):
|
||||
from werkzeug.routing import Rule
|
||||
from werkzeug.routing import Submount
|
||||
|
|
@ -200,6 +210,7 @@ def test_werkzeug_routing(app, client):
|
|||
assert client.get("/foo/").data == b"index"
|
||||
assert client.get("/foo/bar").data == b"bar"
|
||||
|
||||
|
||||
def test_endpoint_decorator(app, client):
|
||||
from werkzeug.routing import Rule
|
||||
from werkzeug.routing import Submount
|
||||
|
|
@ -219,6 +230,7 @@ def test_endpoint_decorator(app, client):
|
|||
assert client.get("/foo/").data == b"index"
|
||||
assert client.get("/foo/bar").data == b"bar"
|
||||
|
||||
|
||||
def test_session(app, client):
|
||||
@app.route("/set", methods=["POST"])
|
||||
def set():
|
||||
|
|
@ -241,6 +253,7 @@ def test_session(app, client):
|
|||
assert client.post("/set", data={"value": "42"}).data == b"value set"
|
||||
assert client.get("/get").data == b"42"
|
||||
|
||||
|
||||
def test_session_path(app, client):
|
||||
app.config.update(APPLICATION_ROOT="/foo")
|
||||
|
||||
|
|
@ -252,6 +265,7 @@ def test_session_path(app, client):
|
|||
rv = client.get("/", "http://example.com:8080/foo")
|
||||
assert "path=/foo" in rv.headers["set-cookie"].lower()
|
||||
|
||||
|
||||
def test_session_using_application_root(app, client):
|
||||
class PrefixPathMiddleware:
|
||||
def __init__(self, app, prefix):
|
||||
|
|
@ -273,6 +287,7 @@ def test_session_using_application_root(app, client):
|
|||
rv = client.get("/", "http://example.com:8080/")
|
||||
assert "path=/bar" in rv.headers["set-cookie"].lower()
|
||||
|
||||
|
||||
def test_session_using_session_settings(app, client):
|
||||
app.config.update(
|
||||
SERVER_NAME="www.example.com:8080",
|
||||
|
|
@ -315,6 +330,7 @@ def test_session_using_session_settings(app, client):
|
|||
assert "samesite" in cookie
|
||||
assert "partitioned" in cookie
|
||||
|
||||
|
||||
def test_session_using_samesite_attribute(app, client):
|
||||
@app.route("/")
|
||||
def index():
|
||||
|
|
@ -341,6 +357,7 @@ def test_session_using_samesite_attribute(app, client):
|
|||
cookie = rv.headers["set-cookie"].lower()
|
||||
assert "samesite=lax" in cookie
|
||||
|
||||
|
||||
def test_missing_session(app):
|
||||
app.secret_key = None
|
||||
|
||||
|
|
@ -353,6 +370,7 @@ def test_missing_session(app):
|
|||
expect_exception(flask.session.__setitem__, "foo", 42)
|
||||
expect_exception(flask.session.pop, "foo")
|
||||
|
||||
|
||||
def test_session_secret_key_fallbacks(app, client) -> None:
|
||||
@app.post("/")
|
||||
def set_session() -> str:
|
||||
|
|
@ -380,6 +398,7 @@ def test_session_secret_key_fallbacks(app, client) -> None:
|
|||
)
|
||||
assert client.get().json == {"a": 1}
|
||||
|
||||
|
||||
def test_session_expiration(app, client):
|
||||
permanent = True
|
||||
|
||||
|
|
@ -411,6 +430,7 @@ def test_session_expiration(app, client):
|
|||
match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])
|
||||
assert match is None
|
||||
|
||||
|
||||
def test_session_stored_last(app, client):
|
||||
@app.after_request
|
||||
def modify_session(response):
|
||||
|
|
@ -424,6 +444,7 @@ def test_session_stored_last(app, client):
|
|||
assert client.get("/").data == b"None"
|
||||
assert client.get("/").data == b"42"
|
||||
|
||||
|
||||
def test_session_special_types(app, client):
|
||||
now = datetime.now(timezone.utc).replace(microsecond=0)
|
||||
the_uuid = uuid.uuid4()
|
||||
|
|
@ -454,6 +475,7 @@ def test_session_special_types(app, client):
|
|||
assert s["di_t_tag"] == {" t__": "not-a-tuple"}
|
||||
assert s["di_tag"] == {" di": "not-a-dict"}
|
||||
|
||||
|
||||
def test_session_cookie_setting(app):
|
||||
is_permanent = True
|
||||
|
||||
|
|
@ -494,6 +516,7 @@ def test_session_cookie_setting(app):
|
|||
app.config["SESSION_REFRESH_EACH_REQUEST"] = False
|
||||
run_test(expect_header=False)
|
||||
|
||||
|
||||
def test_session_vary_cookie(app, client):
|
||||
@app.route("/set")
|
||||
def set_session():
|
||||
|
|
@ -554,6 +577,7 @@ def test_session_vary_cookie(app, client):
|
|||
expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")
|
||||
expect("/no-vary-header", None)
|
||||
|
||||
|
||||
def test_session_refresh_vary(app, client):
|
||||
@app.get("/login")
|
||||
def login():
|
||||
|
|
@ -570,6 +594,7 @@ def test_session_refresh_vary(app, client):
|
|||
rv = client.get("/ignored")
|
||||
assert rv.headers["Vary"] == "Cookie"
|
||||
|
||||
|
||||
def test_flashes(app, req_ctx):
|
||||
assert not flask.session.modified
|
||||
flask.flash("Zap")
|
||||
|
|
@ -578,6 +603,7 @@ def test_flashes(app, req_ctx):
|
|||
assert flask.session.modified
|
||||
assert list(flask.get_flashed_messages()) == ["Zap", "Zip"]
|
||||
|
||||
|
||||
def test_extended_flashing(app):
|
||||
# Be sure app.testing=True below, else tests can fail silently.
|
||||
#
|
||||
|
|
@ -658,6 +684,7 @@ def test_extended_flashing(app):
|
|||
client.get("/")
|
||||
client.get("/test_filters_without_returning_categories/")
|
||||
|
||||
|
||||
def test_request_processing(app, client):
|
||||
evts = []
|
||||
|
||||
|
|
@ -682,6 +709,7 @@ def test_request_processing(app, client):
|
|||
assert "after" in evts
|
||||
assert rv == b"request|after"
|
||||
|
||||
|
||||
def test_request_preprocessing_early_return(app, client):
|
||||
evts = []
|
||||
|
||||
|
|
@ -708,6 +736,7 @@ def test_request_preprocessing_early_return(app, client):
|
|||
assert rv == b"hello"
|
||||
assert evts == [1, 2]
|
||||
|
||||
|
||||
def test_after_request_processing(app, client):
|
||||
@app.route("/")
|
||||
def index():
|
||||
|
|
@ -722,6 +751,7 @@ def test_after_request_processing(app, client):
|
|||
assert resp.status_code == 200
|
||||
assert resp.headers["X-Foo"] == "a header"
|
||||
|
||||
|
||||
def test_teardown_request_handler(app, client):
|
||||
called = []
|
||||
|
||||
|
|
@ -739,6 +769,7 @@ def test_teardown_request_handler(app, client):
|
|||
assert b"Response" in rv.data
|
||||
assert len(called) == 1
|
||||
|
||||
|
||||
def test_teardown_request_handler_debug_mode(app, client):
|
||||
called = []
|
||||
|
||||
|
|
@ -756,6 +787,7 @@ def test_teardown_request_handler_debug_mode(app, client):
|
|||
assert b"Response" in rv.data
|
||||
assert len(called) == 1
|
||||
|
||||
|
||||
def test_teardown_request_handler_error(app, client):
|
||||
called = []
|
||||
app.testing = False
|
||||
|
|
@ -793,6 +825,7 @@ def test_teardown_request_handler_error(app, client):
|
|||
assert b"Internal Server Error" in rv.data
|
||||
assert len(called) == 2
|
||||
|
||||
|
||||
def test_before_after_request_order(app, client):
|
||||
called = []
|
||||
|
||||
|
|
@ -830,6 +863,7 @@ def test_before_after_request_order(app, client):
|
|||
assert rv.data == b"42"
|
||||
assert called == [1, 2, 3, 4, 5, 6]
|
||||
|
||||
|
||||
def test_error_handling(app, client):
|
||||
app.testing = False
|
||||
|
||||
|
|
@ -867,6 +901,7 @@ def test_error_handling(app, client):
|
|||
assert rv.status_code == 403
|
||||
assert b"forbidden" == rv.data
|
||||
|
||||
|
||||
def test_error_handling_processing(app, client):
|
||||
app.testing = False
|
||||
|
||||
|
|
@ -887,6 +922,7 @@ def test_error_handling_processing(app, client):
|
|||
assert resp.mimetype == "text/x-special"
|
||||
assert resp.data == b"internal server error"
|
||||
|
||||
|
||||
def test_baseexception_error_handling(app, client):
|
||||
app.testing = False
|
||||
|
||||
|
|
@ -897,6 +933,7 @@ def test_baseexception_error_handling(app, client):
|
|||
with pytest.raises(KeyboardInterrupt):
|
||||
client.get("/")
|
||||
|
||||
|
||||
def test_before_request_and_routing_errors(app, client):
|
||||
@app.before_request
|
||||
def attach_something():
|
||||
|
|
@ -910,6 +947,7 @@ def test_before_request_and_routing_errors(app, client):
|
|||
assert rv.status_code == 404
|
||||
assert rv.data == b"value"
|
||||
|
||||
|
||||
def test_user_error_handling(app, client):
|
||||
class MyException(Exception):
|
||||
pass
|
||||
|
|
@ -925,6 +963,7 @@ def test_user_error_handling(app, client):
|
|||
|
||||
assert client.get("/").data == b"42"
|
||||
|
||||
|
||||
def test_http_error_subclass_handling(app, client):
|
||||
class ForbiddenSubclass(Forbidden):
|
||||
pass
|
||||
|
|
@ -956,6 +995,7 @@ def test_http_error_subclass_handling(app, client):
|
|||
assert client.get("/2").data == b"apple"
|
||||
assert client.get("/3").data == b"apple"
|
||||
|
||||
|
||||
def test_errorhandler_precedence(app, client):
|
||||
class E1(Exception):
|
||||
pass
|
||||
|
|
@ -988,6 +1028,7 @@ def test_errorhandler_precedence(app, client):
|
|||
rv = client.get("/E3")
|
||||
assert rv.data == b"E2"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("debug", "trap", "expect_key", "expect_abort"),
|
||||
[(False, None, True, True), (True, None, False, True), (False, True, False, False)],
|
||||
|
|
@ -1022,6 +1063,7 @@ def test_trap_bad_request_key_error(app, client, debug, trap, expect_key, expect
|
|||
with pytest.raises(BadRequest):
|
||||
client.get("/abort")
|
||||
|
||||
|
||||
def test_trapping_of_all_http_exceptions(app, client):
|
||||
app.config["TRAP_HTTP_EXCEPTIONS"] = True
|
||||
|
||||
|
|
@ -1032,6 +1074,7 @@ def test_trapping_of_all_http_exceptions(app, client):
|
|||
with pytest.raises(NotFound):
|
||||
client.get("/fail")
|
||||
|
||||
|
||||
def test_error_handler_after_processor_error(app, client):
|
||||
app.testing = False
|
||||
|
||||
|
|
@ -1060,6 +1103,7 @@ def test_error_handler_after_processor_error(app, client):
|
|||
assert rv.status_code == 500
|
||||
assert rv.data == b"Hello Server Error"
|
||||
|
||||
|
||||
def test_enctype_debug_helper(app, client):
|
||||
from flask.debughelpers import DebugFilesKeyError
|
||||
|
||||
|
|
@ -1074,6 +1118,7 @@ def test_enctype_debug_helper(app, client):
|
|||
assert "no file contents were transmitted" in str(e.value)
|
||||
assert "This was submitted: 'index.txt'" in str(e.value)
|
||||
|
||||
|
||||
def test_response_types(app, client):
|
||||
@app.route("/text")
|
||||
def from_text():
|
||||
|
|
@ -1167,6 +1212,7 @@ def test_response_types(app, client):
|
|||
assert rv.json == ["foo", "bar"]
|
||||
assert rv.status_code == 201
|
||||
|
||||
|
||||
def test_response_type_errors():
|
||||
app = flask.Flask(__name__)
|
||||
app.testing = True
|
||||
|
|
@ -1215,6 +1261,7 @@ def test_response_type_errors():
|
|||
with pytest.raises(TypeError):
|
||||
c.get("/bad_wsgi")
|
||||
|
||||
|
||||
def test_make_response(app, req_ctx):
|
||||
rv = flask.make_response()
|
||||
assert rv.status_code == 200
|
||||
|
|
@ -1236,6 +1283,7 @@ def test_make_response(app, req_ctx):
|
|||
assert rv.data == b"Hello"
|
||||
assert rv.mimetype == "text/html"
|
||||
|
||||
|
||||
def test_make_response_with_response_instance(app, req_ctx):
|
||||
rv = flask.make_response(flask.jsonify({"msg": "W00t"}), 400)
|
||||
assert rv.status_code == 400
|
||||
|
|
@ -1256,6 +1304,7 @@ def test_make_response_with_response_instance(app, req_ctx):
|
|||
assert rv.headers["Content-Type"] == "text/html"
|
||||
assert rv.headers["X-Foo"] == "bar"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("compact", [True, False])
|
||||
def test_jsonify_no_prettyprint(app, compact):
|
||||
app.json.compact = compact
|
||||
|
|
@ -1264,12 +1313,14 @@ def test_jsonify_no_prettyprint(app, compact):
|
|||
assert (b" " not in data) is compact
|
||||
assert (b"\n" not in data) is compact
|
||||
|
||||
|
||||
def test_jsonify_mimetype(app, req_ctx):
|
||||
app.json.mimetype = "application/vnd.api+json"
|
||||
msg = {"msg": {"submsg": "W00t"}}
|
||||
rv = flask.make_response(flask.jsonify(msg), 200)
|
||||
assert rv.mimetype == "application/vnd.api+json"
|
||||
|
||||
|
||||
def test_json_dump_dataclass(app, req_ctx):
|
||||
from dataclasses import make_dataclass
|
||||
|
||||
|
|
@ -1278,11 +1329,13 @@ def test_json_dump_dataclass(app, req_ctx):
|
|||
value = app.json.loads(value)
|
||||
assert value == {"name": "Flask"}
|
||||
|
||||
|
||||
def test_jsonify_args_and_kwargs_check(app, req_ctx):
|
||||
with pytest.raises(TypeError) as e:
|
||||
flask.jsonify("fake args", kwargs="fake")
|
||||
assert "args or kwargs" in str(e.value)
|
||||
|
||||
|
||||
def test_url_generation(app, req_ctx):
|
||||
@app.route("/hello/<name>", methods=["POST"])
|
||||
def hello():
|
||||
|
|
@ -1294,6 +1347,7 @@ def test_url_generation(app, req_ctx):
|
|||
== "http://localhost/hello/test%20x"
|
||||
)
|
||||
|
||||
|
||||
def test_build_error_handler(app):
|
||||
# Test base case, a URL which results in a BuildError.
|
||||
with app.test_request_context():
|
||||
|
|
@ -1319,6 +1373,7 @@ def test_build_error_handler(app):
|
|||
with app.test_request_context():
|
||||
assert flask.url_for("spam") == "/test_handler/"
|
||||
|
||||
|
||||
def test_build_error_handler_reraise(app):
|
||||
# Test a custom handler which reraises the BuildError
|
||||
def handler_raises_build_error(error, endpoint, values):
|
||||
|
|
@ -1329,6 +1384,7 @@ def test_build_error_handler_reraise(app):
|
|||
with app.test_request_context():
|
||||
pytest.raises(BuildError, flask.url_for, "not.existing")
|
||||
|
||||
|
||||
def test_url_for_passes_special_values_to_build_error_handler(app):
|
||||
@app.url_build_error_handlers.append
|
||||
def handler(error, endpoint, values):
|
||||
|
|
@ -1343,6 +1399,7 @@ def test_url_for_passes_special_values_to_build_error_handler(app):
|
|||
with app.test_request_context():
|
||||
flask.url_for("/")
|
||||
|
||||
|
||||
def test_static_files(app, client):
|
||||
rv = client.get("/static/index.html")
|
||||
assert rv.status_code == 200
|
||||
|
|
@ -1351,6 +1408,7 @@ def test_static_files(app, client):
|
|||
assert flask.url_for("static", filename="index.html") == "/static/index.html"
|
||||
rv.close()
|
||||
|
||||
|
||||
def test_static_url_path():
|
||||
app = flask.Flask(__name__, static_url_path="/foo")
|
||||
app.testing = True
|
||||
|
|
@ -1361,6 +1419,7 @@ def test_static_url_path():
|
|||
with app.test_request_context():
|
||||
assert flask.url_for("static", filename="index.html") == "/foo/index.html"
|
||||
|
||||
|
||||
def test_static_url_path_with_ending_slash():
|
||||
app = flask.Flask(__name__, static_url_path="/foo/")
|
||||
app.testing = True
|
||||
|
|
@ -1371,18 +1430,21 @@ def test_static_url_path_with_ending_slash():
|
|||
with app.test_request_context():
|
||||
assert flask.url_for("static", filename="index.html") == "/foo/index.html"
|
||||
|
||||
|
||||
def test_static_url_empty_path(app):
|
||||
app = flask.Flask(__name__, static_folder="", static_url_path="")
|
||||
rv = app.test_client().open("/static/index.html", method="GET")
|
||||
assert rv.status_code == 200
|
||||
rv.close()
|
||||
|
||||
|
||||
def test_static_url_empty_path_default(app):
|
||||
app = flask.Flask(__name__, static_folder="")
|
||||
rv = app.test_client().open("/static/index.html", method="GET")
|
||||
assert rv.status_code == 200
|
||||
rv.close()
|
||||
|
||||
|
||||
def test_static_folder_with_pathlib_path(app):
|
||||
from pathlib import Path
|
||||
|
||||
|
|
@ -1391,6 +1453,7 @@ def test_static_folder_with_pathlib_path(app):
|
|||
assert rv.status_code == 200
|
||||
rv.close()
|
||||
|
||||
|
||||
def test_static_folder_with_ending_slash():
|
||||
app = flask.Flask(__name__, static_folder="static/")
|
||||
|
||||
|
|
@ -1401,6 +1464,7 @@ def test_static_folder_with_ending_slash():
|
|||
rv = app.test_client().get("/catch/all")
|
||||
assert rv.data == b"catch/all"
|
||||
|
||||
|
||||
def test_static_route_with_host_matching():
|
||||
app = flask.Flask(__name__, host_matching=True, static_host="example.com")
|
||||
c = app.test_client()
|
||||
|
|
@ -1421,12 +1485,15 @@ def test_static_route_with_host_matching():
|
|||
# but with static_folder=None should not error.
|
||||
flask.Flask(__name__, host_matching=True, static_folder=None)
|
||||
|
||||
|
||||
def test_request_locals():
|
||||
assert repr(flask.g) == "<LocalProxy unbound>"
|
||||
assert not flask.g
|
||||
|
||||
|
||||
werkzeug_3_2 = importlib.metadata.version("werkzeug") >= "3.2."
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("subdomain_matching", "host_matching", "expect_subdomain", "expect_host"),
|
||||
[
|
||||
|
|
@ -1470,6 +1537,7 @@ def test_server_name_matching(
|
|||
else:
|
||||
assert r.text == expect_host
|
||||
|
||||
|
||||
def test_server_name_subdomain():
|
||||
app = flask.Flask(__name__, subdomain_matching=True)
|
||||
client = app.test_client()
|
||||
|
|
@ -1514,6 +1582,7 @@ def test_server_name_subdomain():
|
|||
rv = client.get("/", "http://foo.dev.local")
|
||||
assert rv.data == b"subdomain"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key", ["TESTING", "PROPAGATE_EXCEPTIONS", "DEBUG", None])
|
||||
def test_exception_propagation(app, client, key):
|
||||
app.testing = False
|
||||
|
|
@ -1530,6 +1599,7 @@ def test_exception_propagation(app, client, key):
|
|||
else:
|
||||
assert client.get("/").status_code == 500
|
||||
|
||||
|
||||
@pytest.mark.parametrize("debug", [True, False])
|
||||
@pytest.mark.parametrize("use_debugger", [True, False])
|
||||
@pytest.mark.parametrize("use_reloader", [True, False])
|
||||
|
|
@ -1547,6 +1617,7 @@ def test_werkzeug_passthrough_errors(
|
|||
app.config["PROPAGATE_EXCEPTIONS"] = propagate_exceptions
|
||||
app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)
|
||||
|
||||
|
||||
def test_url_processors(app, client):
|
||||
@app.url_defaults
|
||||
def add_language_code(endpoint, values):
|
||||
|
|
@ -1575,6 +1646,7 @@ def test_url_processors(app, client):
|
|||
assert client.get("/de/about").data == b"/foo"
|
||||
assert client.get("/foo").data == b"/en/about"
|
||||
|
||||
|
||||
def test_inject_blueprint_url_defaults(app):
|
||||
bp = flask.Blueprint("foo", __name__, template_folder="template")
|
||||
|
||||
|
|
@ -1598,6 +1670,7 @@ def test_inject_blueprint_url_defaults(app):
|
|||
expected = "/login"
|
||||
assert url == expected
|
||||
|
||||
|
||||
def test_nonascii_pathinfo(app, client):
|
||||
@app.route("/киртест")
|
||||
def index():
|
||||
|
|
@ -1606,6 +1679,7 @@ def test_nonascii_pathinfo(app, client):
|
|||
rv = client.get("/киртест")
|
||||
assert rv.data == b"Hello World!"
|
||||
|
||||
|
||||
def test_no_setup_after_first_request(app, client):
|
||||
app.debug = True
|
||||
|
||||
|
|
@ -1620,6 +1694,7 @@ def test_no_setup_after_first_request(app, client):
|
|||
|
||||
assert "setup method 'add_url_rule'" in str(exc_info.value)
|
||||
|
||||
|
||||
def test_routing_redirect_debugging(monkeypatch, app, client):
|
||||
app.config["DEBUG"] = True
|
||||
|
||||
|
|
@ -1639,6 +1714,7 @@ def test_routing_redirect_debugging(monkeypatch, app, client):
|
|||
|
||||
assert "canonical URL 'http://localhost/user/'" in str(exc_info.value)
|
||||
|
||||
|
||||
def test_route_decorator_custom_endpoint(app, client):
|
||||
app.debug = True
|
||||
|
||||
|
|
@ -1663,6 +1739,7 @@ def test_route_decorator_custom_endpoint(app, client):
|
|||
assert client.get("/bar/").data == b"bar"
|
||||
assert client.get("/bar/123").data == b"123"
|
||||
|
||||
|
||||
def test_get_method_on_g(app_ctx):
|
||||
assert flask.g.get("x") is None
|
||||
assert flask.g.get("x", 11) == 11
|
||||
|
|
@ -1670,6 +1747,7 @@ def test_get_method_on_g(app_ctx):
|
|||
assert flask.g.get("x") == 42
|
||||
assert flask.g.x == 42
|
||||
|
||||
|
||||
def test_g_iteration_protocol(app_ctx):
|
||||
flask.g.foo = 23
|
||||
flask.g.bar = 42
|
||||
|
|
@ -1677,6 +1755,7 @@ def test_g_iteration_protocol(app_ctx):
|
|||
assert "foos" not in flask.g
|
||||
assert sorted(flask.g) == ["bar", "foo"]
|
||||
|
||||
|
||||
def test_subdomain_basic_support():
|
||||
app = flask.Flask(__name__, subdomain_matching=True)
|
||||
app.config["SERVER_NAME"] = "localhost.localdomain"
|
||||
|
|
@ -1696,6 +1775,7 @@ def test_subdomain_basic_support():
|
|||
rv = client.get("/", "http://test.localhost.localdomain/")
|
||||
assert rv.data == b"test index"
|
||||
|
||||
|
||||
def test_subdomain_matching():
|
||||
app = flask.Flask(__name__, subdomain_matching=True)
|
||||
client = app.test_client()
|
||||
|
|
@ -1708,6 +1788,7 @@ def test_subdomain_matching():
|
|||
rv = client.get("/", "http://mitsuhiko.localhost.localdomain/")
|
||||
assert rv.data == b"index for mitsuhiko"
|
||||
|
||||
|
||||
def test_subdomain_matching_with_ports():
|
||||
app = flask.Flask(__name__, subdomain_matching=True)
|
||||
app.config["SERVER_NAME"] = "localhost.localdomain:3000"
|
||||
|
|
@ -1720,6 +1801,7 @@ def test_subdomain_matching_with_ports():
|
|||
rv = client.get("/", "http://mitsuhiko.localhost.localdomain:3000/")
|
||||
assert rv.data == b"index for mitsuhiko"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("matching", (False, True))
|
||||
def test_subdomain_matching_other_name(matching):
|
||||
app = flask.Flask(__name__, subdomain_matching=matching)
|
||||
|
|
@ -1743,6 +1825,7 @@ def test_subdomain_matching_other_name(matching):
|
|||
rv = client.get("/", "http://www.localhost.localdomain:3000/")
|
||||
assert rv.status_code == 404 if matching else 204
|
||||
|
||||
|
||||
def test_multi_route_rules(app, client):
|
||||
@app.route("/")
|
||||
@app.route("/<test>/")
|
||||
|
|
@ -1754,6 +1837,7 @@ def test_multi_route_rules(app, client):
|
|||
rv = client.open("/b/")
|
||||
assert rv.data == b"b"
|
||||
|
||||
|
||||
def test_multi_route_class_views(app, client):
|
||||
class View:
|
||||
def __init__(self, app):
|
||||
|
|
@ -1769,6 +1853,7 @@ def test_multi_route_class_views(app, client):
|
|||
rv = client.open("/b/")
|
||||
assert rv.data == b"b"
|
||||
|
||||
|
||||
def test_run_defaults(monkeypatch, app):
|
||||
rv = {}
|
||||
|
||||
|
|
@ -1780,6 +1865,7 @@ def test_run_defaults(monkeypatch, app):
|
|||
app.run()
|
||||
assert rv["result"] == "running..."
|
||||
|
||||
|
||||
def test_run_server_port(monkeypatch, app):
|
||||
rv = {}
|
||||
|
||||
|
|
@ -1792,6 +1878,7 @@ def test_run_server_port(monkeypatch, app):
|
|||
app.run(hostname, port, debug=True)
|
||||
assert rv["result"] == f"running on {hostname}:{port} ..."
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"host,port,server_name,expect_host,expect_port",
|
||||
(
|
||||
|
|
@ -1815,6 +1902,7 @@ def test_run_from_config(
|
|||
app.config["SERVER_NAME"] = server_name
|
||||
app.run(host, port)
|
||||
|
||||
|
||||
def test_max_cookie_size(app, client, recwarn):
|
||||
app.config["MAX_COOKIE_SIZE"] = 100
|
||||
|
||||
|
|
@ -1844,6 +1932,7 @@ def test_max_cookie_size(app, client, recwarn):
|
|||
client.get("/")
|
||||
assert len(recwarn) == 0
|
||||
|
||||
|
||||
@require_cpython_gc
|
||||
def test_app_freed_on_zero_refcount():
|
||||
# A Flask instance should not create a reference cycle that prevents CPython
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue