diff --git a/tests/test_routing.py b/tests/test_routing.py index e3b1e412a..3b7cf54da 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -549,6 +549,60 @@ def test_url_for_with_root_path(test_client_factory): } +async def echo_paths(request, name): + return JSONResponse( + { + "name": name, + "path": request.scope["path"], + "root_path": request.scope["root_path"], + } + ) + + +echo_paths_routes = [ + Route( + "/path", + functools.partial(echo_paths, name="path"), + name="path", + methods=["GET"], + ), + Mount( + "/root", + name="mount", + routes=[ + Route( + "/path", + functools.partial(echo_paths, name="subpath"), + name="subpath", + methods=["GET"], + ) + ], + ), +] + + +def test_paths_with_root_path(test_client_factory): + app = Starlette(routes=echo_paths_routes) + client = test_client_factory( + app, base_url="https://www.example.org/", root_path="/root" + ) + response = client.get("/root/path") + assert response.status_code == 200 + assert response.json() == { + "name": "path", + "path": "/root/path", + "root_path": "/root", + } + + response = client.get("/root/root/path") + assert response.status_code == 200 + assert response.json() == { + "name": "subpath", + "path": "/root/root/path", + "root_path": "/root", + } + + async def stub_app(scope, receive, send): pass # pragma: no cover