Skip to content

Commit

Permalink
Add unit test reproducing bug encode#1336
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 authored and Kludex committed Sep 11, 2022
1 parent bc61505 commit 7ce42bc
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7ce42bc

Please sign in to comment.