diff --git a/tests/test_static_files.py b/tests/test_static_files.py index f79f50b1..fbe8a541 100644 --- a/tests/test_static_files.py +++ b/tests/test_static_files.py @@ -5,7 +5,9 @@ import pytest from pydantic import ValidationError +from esmerald import Include, get from esmerald.config import StaticFilesConfig +from esmerald.config.template import TemplateConfig from esmerald.testclient import create_client @@ -117,3 +119,51 @@ def test_static_substring_of_self(tmpdir: Any) -> None: response = client.get("/static/static_part/static/test.txt") assert response.status_code == 200 assert response.text == "content" + + +@pytest.mark.parametrize("redirect_slashes", [True, False]) +def test_mixing_static_and_include(tmpdir: Any, redirect_slashes) -> None: + @get("/include") + async def get_include() -> str: + return "include" + + path = tmpdir.join("test.txt") + path.write("content") + static_files_config = StaticFilesConfig(path="/static", directory=tmpdir) + + with create_client( + [Include("/", routes=[get_include])], + static_files_config=static_files_config, + redirect_slashes=redirect_slashes, + ) as client: + response = client.get("/static/test.txt") + assert response.status_code == 200 + assert response.text == "content" + + response = client.get("/include") + assert response.status_code == 200 + + +@pytest.mark.parametrize("redirect_slashes", [True, False]) +def test_mixing_static_and_include_template_config(tmpdir: Any, template_dir, redirect_slashes) -> None: + @get("/include") + async def get_include() -> str: + return "include" + + path = tmpdir.join("test.txt") + path.write("content") + static_files_config = StaticFilesConfig(path="/static", directory=tmpdir) + template_config = TemplateConfig(directory=template_dir) + + with create_client( + [Include("/", routes=[get_include])], + static_files_config=static_files_config, + redirect_slashes=redirect_slashes, + template_config=template_config + ) as client: + response = client.get("/static/test.txt") + assert response.status_code == 200 + assert response.text == "content" + + response = client.get("/include") + assert response.status_code == 200