added ZstdMiddleware to ebook_search
treefmt / nix fmt (pull_request) Successful in 11s
pytest / pytest (pull_request) Successful in 36s
build_systems / build-brain (pull_request) Successful in 55s
build_systems / build-bob (pull_request) Successful in 57s
build_systems / build-leviathan (pull_request) Successful in 1m7s
build_systems / build-rhapsody-in-green (pull_request) Successful in 1m8s
build_systems / build-jeeves (pull_request) Successful in 2m45s
treefmt / nix fmt (pull_request) Successful in 11s
pytest / pytest (pull_request) Successful in 36s
build_systems / build-brain (pull_request) Successful in 55s
build_systems / build-bob (pull_request) Successful in 57s
build_systems / build-leviathan (pull_request) Successful in 1m7s
build_systems / build-rhapsody-in-green (pull_request) Successful in 1m8s
build_systems / build-jeeves (pull_request) Successful in 2m45s
This commit is contained in:
@@ -18,6 +18,7 @@ from python.ebook_search.api.routes import admin_router, page_router, search_rou
|
|||||||
from python.ebook_search.api.web import STATIC_DIR
|
from python.ebook_search.api.web import STATIC_DIR
|
||||||
from python.ebook_search.bm25_corpus import ensure_bm25_corpus
|
from python.ebook_search.bm25_corpus import ensure_bm25_corpus
|
||||||
from python.ebook_search.config import load_config
|
from python.ebook_search.config import load_config
|
||||||
|
from python.fastapi_tools import ZstdMiddleware
|
||||||
from python.orm.common import get_postgres_engine
|
from python.orm.common import get_postgres_engine
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -45,6 +46,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|||||||
def create_app() -> FastAPI:
|
def create_app() -> FastAPI:
|
||||||
"""Create the EPUB search web app."""
|
"""Create the EPUB search web app."""
|
||||||
app = FastAPI(title="EPUB Search", lifespan=lifespan)
|
app = FastAPI(title="EPUB Search", lifespan=lifespan)
|
||||||
|
app.add_middleware(ZstdMiddleware)
|
||||||
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||||
app.state.config = load_config()
|
app.state.config = load_config()
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from compression import zstd
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
|
|
||||||
@@ -24,6 +25,19 @@ def fake_get_postgres_engine(**_kwargs):
|
|||||||
return create_engine("sqlite+pysqlite:///:memory:", future=True)
|
return create_engine("sqlite+pysqlite:///:memory:", future=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_search_page_uses_zstd_when_requested(monkeypatch) -> None:
|
||||||
|
patch_app_runtime(monkeypatch)
|
||||||
|
app = create_app()
|
||||||
|
app.state.config = EbookSearchConfig(rerank=RerankConfig(enabled=False))
|
||||||
|
|
||||||
|
with TestClient(app) as client:
|
||||||
|
response = client.get("/", headers={"accept-encoding": "zstd"})
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.headers["content-encoding"] == "zstd"
|
||||||
|
assert b"EPUB Search" in zstd.decompress(response.content)
|
||||||
|
|
||||||
|
|
||||||
def test_ui_form_passes_rerank_flag_to_search_handler(monkeypatch) -> None:
|
def test_ui_form_passes_rerank_flag_to_search_handler(monkeypatch) -> None:
|
||||||
captured: dict[str, object] = {}
|
captured: dict[str, object] = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user