diff --git a/src/sblex/saldo_ws/routes/fullform.py b/src/sblex/saldo_ws/routes/fullform.py index e3b29a6..bb0f761 100644 --- a/src/sblex/saldo_ws/routes/fullform.py +++ b/src/sblex/saldo_ws/routes/fullform.py @@ -43,9 +43,9 @@ async def fullform_xml( json_data = jsonlib.loads(await morphology.lookup(fragment)) return templates.TemplateResponse( - "saldo_fullform.xml", + request=request, + name="saldo_fullform.xml", context={ - "request": request, "j": json_data, }, media_type="application/xml", @@ -67,9 +67,10 @@ async def fullform_html( if fragment: json_data = jsonlib.loads(await morphology.lookup(fragment)) return templates.TemplateResponse( - "saldo_fullform.html", + request=request, + name="saldo_fullform.html", context=templating.build_context( - request, + request=request, title=fragment, service="ff", input=fragment, diff --git a/src/sblex/saldo_ws/routes/fullform_lex.py b/src/sblex/saldo_ws/routes/fullform_lex.py index b389c4e..0d585dc 100644 --- a/src/sblex/saldo_ws/routes/fullform_lex.py +++ b/src/sblex/saldo_ws/routes/fullform_lex.py @@ -37,8 +37,9 @@ async def fullform_xml( with PerfMsTracker(scope=request.scope, key="pf_srv"): json_data = await fullform_lex_query.query(segment=segment) return templates.TemplateResponse( - "fullform_lex.xml", - context={"request": request, "j": json_data}, + request=request, + name="fullform_lex.xml", + context={"j": json_data}, media_type="application/xml", ) @@ -58,9 +59,10 @@ async def fullform_lex_html( json_data = await fullform_lex_query.query(segment=segment) return templates.TemplateResponse( - "saldo_fullform_lex.html", + request=request, + name="saldo_fullform_lex.html", context=templating.build_context( - request, + request=request, title="SALDO", show_bar=True, service="fl", diff --git a/src/sblex/saldo_ws/routes/lids.py b/src/sblex/saldo_ws/routes/lids.py index fde66f5..859e007 100644 --- a/src/sblex/saldo_ws/routes/lids.py +++ b/src/sblex/saldo_ws/routes/lids.py @@ -65,13 +65,15 @@ async def lookup_lid_xml( # if isinstance(lid, Lemma): if is_lemma(lid): return templates.TemplateResponse( - "saldo_lid_lemma.xml", - {"request": request, "j": lemma_or_lexeme}, + request=request, + name="saldo_lid_lemma.xml", + context={"j": lemma_or_lexeme}, media_type="application/xml", ) return templates.TemplateResponse( - "saldo_lid_lexeme.xml", - {"request": request, "j": lemma_or_lexeme}, + request=request, + name="saldo_lid_lexeme.xml", + context={"j": lemma_or_lexeme}, media_type="application/xml", ) @@ -93,7 +95,8 @@ async def lookup_lid_html( lemma_or_lexeme = await lookup_lid.get_by_lid(lid) except LemmaNotFound: return templates.TemplateResponse( - "saldo_lid_lemma_saknas.html", + request=request, + name="saldo_lid_lemma_saknas.html", context=templating.build_context( request, title=lid, service="lid", show_bar=False, lid=lid ), @@ -108,7 +111,8 @@ async def lookup_lid_html( # }, except LexemeNotFound: return templates.TemplateResponse( - "saldo_lid_lexeme_saknas.html", + request=request, + name="saldo_lid_lexeme_saknas.html", context=templating.build_context( request, title=lid, service="lid", show_bar=False, lid=lid ), @@ -119,7 +123,8 @@ async def lookup_lid_html( print(f"lemma {lid=}") return templates.TemplateResponse( - "saldo_table.html", + request=request, + name="saldo_table.html", context=templating.build_context( request, title=lid, @@ -142,7 +147,8 @@ async def lookup_lid_html( templates.env.globals["lemma"] = formatting.lemma return templates.TemplateResponse( - "saldo_lid_lexeme.html", + request=request, + name="saldo_lid_lexeme.html", context=templating.build_context( request, title=lid, service="lid", show_bar=False, data=prepared_json ), diff --git a/src/sblex/saldo_ws/templating.py b/src/sblex/saldo_ws/templating.py index 42eead8..92be072 100644 --- a/src/sblex/saldo_ws/templating.py +++ b/src/sblex/saldo_ws/templating.py @@ -11,7 +11,6 @@ def build_context( ) -> dict[str, Any]: settings: config.Settings = request.app.state.settings return { - "request": request, "bar": show_bar, "title": title, "tracking_base_url": settings.frontend.tracking.matomo_url, diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index 57fc59e..749618a 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -5,7 +5,7 @@ import pytest_asyncio from asgi_lifespan import LifespanManager from fastapi import FastAPI -from httpx import AsyncClient +from httpx import ASGITransport, AsyncClient from sblex.fm_server.config import Settings as FmSettings from sblex.fm_server.server import create_fm_server from sblex.saldo_ws.config import Settings as SaldoWsSettings @@ -49,7 +49,9 @@ def override_fm_client() -> AsyncClient: @pytest_asyncio.fixture async def client(webapp: FastAPI) -> AsyncGenerator[AsyncClient, None]: async with LifespanManager(webapp): - async with AsyncClient(app=webapp, base_url="http://testserver") as client: + async with AsyncClient( + transport=ASGITransport(webapp), base_url="http://testserver" + ) as client: yield client @@ -70,5 +72,7 @@ def fixture_fm_server(env: environs.Env) -> FastAPI: @pytest_asyncio.fixture async def fm_client(fm_server: FastAPI) -> AsyncGenerator[AsyncClient, None]: async with LifespanManager(fm_server): - async with AsyncClient(app=fm_server, base_url="http://fmserver") as fm_client: + async with AsyncClient( + transport=ASGITransport(fm_server), base_url="http://fmserver" + ) as fm_client: yield fm_client