Skip to content

Commit

Permalink
fix: update TemplateResposne
Browse files Browse the repository at this point in the history
  • Loading branch information
kod-kristoff committed Mar 11, 2024
1 parent d1e7268 commit 1f76e51
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/sblex/saldo_ws/routes/fullform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions src/sblex/saldo_ws/routes/fullform_lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand All @@ -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",
Expand Down
22 changes: 14 additions & 8 deletions src/sblex/saldo_ws/routes/lids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand All @@ -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
),
Expand All @@ -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
),
Expand All @@ -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,
Expand All @@ -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
),
Expand Down
1 change: 0 additions & 1 deletion src/sblex/saldo_ws/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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

0 comments on commit 1f76e51

Please sign in to comment.