MCPcopy Create free account
hub / github.com/pallets/quart / test_template_context_processors

Function test_template_context_processors

tests/test_templating.py:55–81  ·  view source on GitHub ↗
(app: Quart, blueprint: Blueprint)

Source from the content-addressed store, hash-verified

53
54
55async def test_template_context_processors(app: Quart, blueprint: Blueprint) -> None:
56 @blueprint.context_processor
57 async def blueprint_context() -> dict:
58 await asyncio.sleep(0.01) # Test the ability to await
59 return {"context": "foo"}
60
61 @blueprint.app_context_processor
62 async def app_blueprint_context() -> dict:
63 return {"global_context": "boo"}
64
65 @app.context_processor
66 async def app_context() -> dict:
67 return {"context": "bar"}
68
69 app.register_blueprint(blueprint)
70
71 async with app.app_context():
72 rendered = await render_template_string("{{ context }}")
73 assert rendered == "bar"
74
75 async with app.test_request_context("/"):
76 rendered = await render_template_string("{{ context }} {{ global_context }}")
77 assert rendered == "foo boo"
78
79 async with app.test_request_context("/other"):
80 rendered = await render_template_string("{{ context }} {{ global_context }}")
81 assert rendered == "bar boo"
82
83
84async def test_template_globals(app: Quart, blueprint: Blueprint) -> None:

Callers

nothing calls this directly

Calls 3

render_template_stringFunction · 0.90
app_contextMethod · 0.80
test_request_contextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…