Static DIR and FILE resource types (#2244)
* Explicit static directive for serving file or dir Co-authored-by: anbuhckr <36891836+anbuhckr@users.noreply.github.com> Co-authored-by: anbuhckr <miki.suhendra@gmail.com>
This commit is contained in:
@@ -523,3 +523,56 @@ def test_multiple_statics(app, static_file_directory):
|
||||
assert response.body == get_file_content(
|
||||
static_file_directory, "python.png"
|
||||
)
|
||||
|
||||
|
||||
def test_resource_type_default(app, static_file_directory):
|
||||
app.static("/static", static_file_directory)
|
||||
app.static("/file", get_file_path(static_file_directory, "test.file"))
|
||||
|
||||
_, response = app.test_client.get("/static")
|
||||
assert response.status == 404
|
||||
|
||||
_, response = app.test_client.get("/file")
|
||||
assert response.status == 200
|
||||
assert response.body == get_file_content(
|
||||
static_file_directory, "test.file"
|
||||
)
|
||||
|
||||
|
||||
def test_resource_type_file(app, static_file_directory):
|
||||
app.static(
|
||||
"/file",
|
||||
get_file_path(static_file_directory, "test.file"),
|
||||
resource_type="file",
|
||||
)
|
||||
|
||||
_, response = app.test_client.get("/file")
|
||||
assert response.status == 200
|
||||
assert response.body == get_file_content(
|
||||
static_file_directory, "test.file"
|
||||
)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
app.static("/static", static_file_directory, resource_type="file")
|
||||
|
||||
|
||||
def test_resource_type_dir(app, static_file_directory):
|
||||
app.static("/static", static_file_directory, resource_type="dir")
|
||||
|
||||
_, response = app.test_client.get("/static/test.file")
|
||||
assert response.status == 200
|
||||
assert response.body == get_file_content(
|
||||
static_file_directory, "test.file"
|
||||
)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
app.static(
|
||||
"/file",
|
||||
get_file_path(static_file_directory, "test.file"),
|
||||
resource_type="dir",
|
||||
)
|
||||
|
||||
|
||||
def test_resource_type_unknown(app, static_file_directory, caplog):
|
||||
with pytest.raises(ValueError):
|
||||
app.static("/static", static_file_directory, resource_type="unknown")
|
||||
|
||||
Reference in New Issue
Block a user