test_request.py — flask Source File
Architecture documentation for test_request.py, a python file in the flask codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 1905b6e1_8d46_0e59_4505_e8c353e23e05["test_request.py"] 8c762fc5_c0b6_0d4d_3889_896d80fbf225["flask"] 1905b6e1_8d46_0e59_4505_e8c353e23e05 --> 8c762fc5_c0b6_0d4d_3889_896d80fbf225 2a2a4b0c_ad5b_b59a_8848_4f7c42fd9bbe["flask.testing"] 1905b6e1_8d46_0e59_4505_e8c353e23e05 --> 2a2a4b0c_ad5b_b59a_8848_4f7c42fd9bbe style 1905b6e1_8d46_0e59_4505_e8c353e23e05 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
from flask import Flask
from flask import Request
from flask import request
from flask.testing import FlaskClient
def test_max_content_length(app: Flask, client: FlaskClient) -> None:
app.config["MAX_CONTENT_LENGTH"] = 50
@app.post("/")
def index():
request.form["myfile"]
AssertionError()
@app.errorhandler(413)
def catcher(error):
return "42"
rv = client.post("/", data={"myfile": "foo" * 50})
assert rv.data == b"42"
def test_limit_config(app: Flask):
app.config["MAX_CONTENT_LENGTH"] = 100
app.config["MAX_FORM_MEMORY_SIZE"] = 50
app.config["MAX_FORM_PARTS"] = 3
r = Request({})
# no app context, use Werkzeug defaults
assert r.max_content_length is None
assert r.max_form_memory_size == 500_000
assert r.max_form_parts == 1_000
# in app context, use config
with app.app_context():
assert r.max_content_length == 100
assert r.max_form_memory_size == 50
assert r.max_form_parts == 3
# regardless of app context, use override
r.max_content_length = 90
r.max_form_memory_size = 30
r.max_form_parts = 4
assert r.max_content_length == 90
assert r.max_form_memory_size == 30
assert r.max_form_parts == 4
with app.app_context():
assert r.max_content_length == 90
assert r.max_form_memory_size == 30
assert r.max_form_parts == 4
def test_trusted_hosts_config(app: Flask) -> None:
app.config["TRUSTED_HOSTS"] = ["example.test", ".other.test"]
@app.get("/")
def index() -> str:
return ""
client = app.test_client()
r = client.get(base_url="http://example.test")
assert r.status_code == 200
r = client.get(base_url="http://a.other.test")
assert r.status_code == 200
r = client.get(base_url="http://bad.test")
assert r.status_code == 400
Domain
Subdomains
Dependencies
- flask
- flask.testing
Source
Frequently Asked Questions
What does test_request.py do?
test_request.py is a source file in the flask codebase, written in python. It belongs to the ApplicationCore domain, AppLifeCycle subdomain.
What functions are defined in test_request.py?
test_request.py defines 3 function(s): test_limit_config, test_max_content_length, test_trusted_hosts_config.
What does test_request.py depend on?
test_request.py imports 2 module(s): flask, flask.testing.
Where is test_request.py in the architecture?
test_request.py is located at tests/test_request.py (domain: ApplicationCore, subdomain: AppLifeCycle, directory: tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free