]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Remove routing decorators in test_templates.py (#1501)
authorAmin Alaee <mohammadamin.alaee@gmail.com>
Thu, 10 Feb 2022 11:25:28 +0000 (12:25 +0100)
committerGitHub <noreply@github.com>
Thu, 10 Feb 2022 11:25:28 +0000 (11:25 +0000)
tests/test_templates.py

index aa8279348216b67b14a6615e18fe9e91a1b5d7ca..ad42488de62e03ee86742068f5992ad6d18ba5d2 100644 (file)
@@ -3,6 +3,7 @@ import os
 import pytest
 
 from starlette.applications import Starlette
+from starlette.routing import Route
 from starlette.templating import Jinja2Templates
 
 
@@ -11,13 +12,15 @@ def test_templates(tmpdir, test_client_factory):
     with open(path, "w") as file:
         file.write("<html>Hello, <a href='{{ url_for('homepage') }}'>world</a></html>")
 
-    app = Starlette(debug=True)
-    templates = Jinja2Templates(directory=str(tmpdir))
-
-    @app.route("/")
     async def homepage(request):
         return templates.TemplateResponse("index.html", {"request": request})
 
+    app = Starlette(
+        debug=True,
+        routes=[Route("/", endpoint=homepage)],
+    )
+    templates = Jinja2Templates(directory=str(tmpdir))
+
     client = test_client_factory(app)
     response = client.get("/")
     assert response.text == "<html>Hello, <a href='http://testserver/'>world</a></html>"