(tmpdir: Path, test_client_factory: TestClientFactory)
| 17 | |
| 18 | |
| 19 | def test_templates(tmpdir: Path, test_client_factory: TestClientFactory) -> None: |
| 20 | path = os.path.join(tmpdir, "index.html") |
| 21 | with open(path, "w") as file: |
| 22 | file.write("<html>Hello, <a href='{{ url_for('homepage') }}'>world</a></html>") |
| 23 | |
| 24 | async def homepage(request: Request) -> Response: |
| 25 | return templates.TemplateResponse(request, "index.html") |
| 26 | |
| 27 | app = Starlette(debug=True, routes=[Route("/", endpoint=homepage)]) |
| 28 | templates = Jinja2Templates(directory=str(tmpdir)) |
| 29 | |
| 30 | client = test_client_factory(app) |
| 31 | response = client.get("/") |
| 32 | assert response.text == "<html>Hello, <a href='http://testserver/'>world</a></html>" |
| 33 | assert response.template.name == "index.html" # type: ignore |
| 34 | assert set(response.context.keys()) == {"request"} # type: ignore |
| 35 | |
| 36 | |
| 37 | def test_templates_autoescape(tmp_path: Path) -> None: |
nothing calls this directly
no test coverage detected