TestSendfile Class — flask Architecture
Architecture documentation for the TestSendfile class in test_helpers.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD b3e863f6_458a_708a_dfc2_28e32b43300e["TestSendfile"] d5d22f74_a243_4ea9_9dfe_aaec71d26288["test_helpers.py"] b3e863f6_458a_708a_dfc2_28e32b43300e -->|defined in| d5d22f74_a243_4ea9_9dfe_aaec71d26288 a964018d_c51c_456a_4a3b_a3cb1ba9b811["test_send_file()"] b3e863f6_458a_708a_dfc2_28e32b43300e -->|method| a964018d_c51c_456a_4a3b_a3cb1ba9b811 ff2bf99f_2463_5326_ac14_ae01b07f58b2["test_static_file()"] b3e863f6_458a_708a_dfc2_28e32b43300e -->|method| ff2bf99f_2463_5326_ac14_ae01b07f58b2 12a5c2a5_cd88_92c4_c104_005d117cd7ca["test_send_from_directory()"] b3e863f6_458a_708a_dfc2_28e32b43300e -->|method| 12a5c2a5_cd88_92c4_c104_005d117cd7ca
Relationship Graph
Source Code
tests/test_helpers.py lines 33–99
class TestSendfile:
def test_send_file(self, app, req_ctx):
rv = flask.send_file("static/index.html")
assert rv.direct_passthrough
assert rv.mimetype == "text/html"
with app.open_resource("static/index.html") as f:
rv.direct_passthrough = False
assert rv.data == f.read()
rv.close()
def test_static_file(self, app, req_ctx):
# Default max_age is None.
# Test with static file handler.
rv = app.send_static_file("index.html")
assert rv.cache_control.max_age is None
rv.close()
# Test with direct use of send_file.
rv = flask.send_file("static/index.html")
assert rv.cache_control.max_age is None
rv.close()
app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 3600
# Test with static file handler.
rv = app.send_static_file("index.html")
assert rv.cache_control.max_age == 3600
rv.close()
# Test with direct use of send_file.
rv = flask.send_file("static/index.html")
assert rv.cache_control.max_age == 3600
rv.close()
# Test with pathlib.Path.
rv = app.send_static_file(FakePath("index.html"))
assert rv.cache_control.max_age == 3600
rv.close()
class StaticFileApp(flask.Flask):
def get_send_file_max_age(self, filename):
return 10
app = StaticFileApp(__name__)
with app.test_request_context():
# Test with static file handler.
rv = app.send_static_file("index.html")
assert rv.cache_control.max_age == 10
rv.close()
# Test with direct use of send_file.
rv = flask.send_file("static/index.html")
assert rv.cache_control.max_age == 10
rv.close()
def test_send_from_directory(self, app, req_ctx):
app.root_path = os.path.join(
os.path.dirname(__file__), "test_apps", "subdomaintestmodule"
)
rv = flask.send_from_directory("static", "hello.txt")
rv.direct_passthrough = False
assert rv.data.strip() == b"Hello Subdomain"
rv.close()
Defined In
Source
Frequently Asked Questions
What is the TestSendfile class?
TestSendfile is a class in the flask codebase, defined in tests/test_helpers.py.
Where is TestSendfile defined?
TestSendfile is defined in tests/test_helpers.py at line 33.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free