]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
move test from test_base.py to test_routing.py (#1693)
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Wed, 15 Jun 2022 13:22:18 +0000 (08:22 -0500)
committerGitHub <noreply@github.com>
Wed, 15 Jun 2022 13:22:18 +0000 (08:22 -0500)
tests/middleware/test_base.py
tests/middleware/test_middleware.py [new file with mode: 0644]
tests/test_routing.py

index 0d023ddd18fe06672f2e36fc6bece5953ec4c348..976d77b86074b7106c3d9f9c18eded9e12ecdc25 100644 (file)
@@ -6,7 +6,7 @@ from starlette.applications import Starlette
 from starlette.middleware import Middleware
 from starlette.middleware.base import BaseHTTPMiddleware
 from starlette.responses import PlainTextResponse, StreamingResponse
-from starlette.routing import Mount, Route, WebSocketRoute
+from starlette.routing import Route, WebSocketRoute
 from starlette.types import ASGIApp, Receive, Scope, Send
 
 
@@ -139,11 +139,6 @@ def test_app_middleware_argument(test_client_factory):
     assert response.headers["Custom-Header"] == "Example"
 
 
-def test_middleware_repr():
-    middleware = Middleware(CustomMiddleware)
-    assert repr(middleware) == "Middleware(CustomMiddleware)"
-
-
 def test_fully_evaluated_response(test_client_factory):
     # Test for https://github.com/encode/starlette/issues/1022
     class CustomMiddleware(BaseHTTPMiddleware):
@@ -158,16 +153,6 @@ def test_fully_evaluated_response(test_client_factory):
     assert response.text == "Custom"
 
 
-def test_exception_on_mounted_apps(test_client_factory):
-    sub_app = Starlette(routes=[Route("/", exc)])
-    app = Starlette(routes=[Mount("/sub", app=sub_app)])
-
-    client = test_client_factory(app)
-    with pytest.raises(Exception) as ctx:
-        client.get("/sub/")
-    assert str(ctx.value) == "Exc"
-
-
 ctxvar: contextvars.ContextVar[str] = contextvars.ContextVar("ctxvar")
 
 
diff --git a/tests/middleware/test_middleware.py b/tests/middleware/test_middleware.py
new file mode 100644 (file)
index 0000000..f4d7a32
--- /dev/null
@@ -0,0 +1,10 @@
+from starlette.middleware import Middleware
+
+
+class CustomMiddleware:
+    pass
+
+
+def test_middleware_repr():
+    middleware = Middleware(CustomMiddleware)
+    assert repr(middleware) == "Middleware(CustomMiddleware)"
index e2b1c3dfcd40d011890d29ab3005e9784f7fb721..e3b1e412a5304a7199a7a9fdda930874ddd91f4d 100644 (file)
@@ -766,3 +766,16 @@ class Endpoint:
 )
 def test_route_name(endpoint: typing.Callable, expected_name: str):
     assert Route(path="/", endpoint=endpoint).name == expected_name
+
+
+def test_exception_on_mounted_apps(test_client_factory):
+    def exc(request):
+        raise Exception("Exc")
+
+    sub_app = Starlette(routes=[Route("/", exc)])
+    app = Starlette(routes=[Mount("/sub", app=sub_app)])
+
+    client = test_client_factory(app)
+    with pytest.raises(Exception) as ctx:
+        client.get("/sub/")
+    assert str(ctx.value) == "Exc"