Skip to content

Commit

Permalink
Add tests for handling root_path in URLRouting
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro R. Sedeño <asedeno@mit.edu>
Signed-off-by: Alejandro R Sedeño <asedeno@google.com>
  • Loading branch information
asedeno authored and carltongibson committed Apr 3, 2024
1 parent ecbf353 commit c84fd58
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ async def test_url_router():
"args": tuple(),
"kwargs": {"default": 42},
}
# Valid root_path in scope
assert (
await router(
{"type": "http", "path": "/root/", "root_path": "/root"}, None, None
)
== 1
)
assert (
await router(
{"type": "http", "path": "/root/foo/", "root_path": "/root"}, None, None
)
== 2
)

# Unmatched root_path in scope
with pytest.raises(ValueError):
await router({"type": "http", "path": "/", "root_path": "/root"}, None, None)

# Invalid matches
with pytest.raises(ValueError):
Expand Down Expand Up @@ -261,6 +278,29 @@ async def test_path_remaining():
== 2
)

assert (
await outermost_router(
{"type": "http", "path": "/root/prefix/stuff/", "root_path": "/root"},
None,
None,
)
== 2
)

with pytest.raises(ValueError):
await outermost_router(
{"type": "http", "path": "/root/root/prefix/stuff/", "root_path": "/root"},
None,
None,
)

with pytest.raises(ValueError):
await outermost_router(
{"type": "http", "path": "/root/prefix/root/stuff/", "root_path": "/root"},
None,
None,
)


def test_invalid_routes():
"""
Expand Down

0 comments on commit c84fd58

Please sign in to comment.