diff --git a/pyproject.toml b/pyproject.toml index 2445631..2f64789 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,7 +82,7 @@ Issues = "https://github.com/kennethreitz/responder/issues" version = {attr = "responder.__version__.__version__"} [tool.setuptools.package-data] -responder = ["py.typed"] +responder = ["py.typed", "ext/openapi/docs/*.html"] [tool.setuptools.packages.find] exclude = ["tests"] diff --git a/responder/__version__.py b/responder/__version__.py index 903a158..a5cfdf5 100644 --- a/responder/__version__.py +++ b/responder/__version__.py @@ -1 +1 @@ -__version__ = "3.4.0" +__version__ = "3.4.1" diff --git a/tests/test_coverage.py b/tests/test_coverage.py index dbf5a5a..331a359 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -660,3 +660,49 @@ def test_templates_context(tmp_path): result = templates.render("test.html") assert "hello" in result assert "world" in result + + +def test_static_file_serving(tmp_path): + """Verify static files are served correctly from the static directory.""" + static_dir = tmp_path / "static" + static_dir.mkdir() + (static_dir / "style.css").write_text("body { color: red; }") + (static_dir / "app.js").write_text("console.log('hello');") + + api = responder.API( + static_dir=str(static_dir), + static_route="/static", + allowed_hosts=[";"], + ) + + # CSS file served with correct content + r = api.requests.get("http://;/static/style.css") + assert r.status_code == 200 + assert "body { color: red; }" in r.text + assert "text/css" in r.headers.get("content-type", "") + + # JS file served with correct content + r = api.requests.get("http://;/static/app.js") + assert r.status_code == 200 + assert "console.log" in r.text + + # Missing file returns 404 + r = api.requests.get("http://;/static/missing.txt") + assert r.status_code == 404 + + +def test_static_index_fallback(tmp_path): + """Verify static index.html is served as default route.""" + static_dir = tmp_path / "static" + static_dir.mkdir() + (static_dir / "index.html").write_text("

SPA

") + + api = responder.API( + static_dir=str(static_dir), + allowed_hosts=[";"], + ) + api.add_route("/", static=True) + + r = api.requests.get("http://;/") + assert r.status_code == 200 + assert "

SPA

" in r.text