Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test to demonstrate leaf rules don't consume branches #2458

Merged
merged 1 commit into from Jul 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/test_routing.py
Expand Up @@ -207,6 +207,34 @@ def test_strict_slashes_redirect():
pytest.raises(MethodNotAllowed, adapter.match, "/bar/", method="POST")


def test_strict_slashes_leaves_dont_consume():
# See issue #1074
map = r.Map(
[
r.Rule("/path1", endpoint="leaf"),
r.Rule("/path1/", endpoint="branch"),
r.Rule("/path2", endpoint="leaf", strict_slashes=False),
r.Rule("/path2/", endpoint="branch"),
r.Rule("/path3", endpoint="leaf"),
r.Rule("/path3/", endpoint="branch", strict_slashes=False),
r.Rule("/path4", endpoint="leaf", strict_slashes=False),
r.Rule("/path4/", endpoint="branch", strict_slashes=False),
],
strict_slashes=False,
)

adapter = map.bind("example.org", "/")

assert adapter.match("/path1", method="GET") == ("leaf", {})
assert adapter.match("/path1/", method="GET") == ("branch", {})
assert adapter.match("/path2", method="GET") == ("leaf", {})
assert adapter.match("/path2/", method="GET") == ("branch", {})
assert adapter.match("/path3", method="GET") == ("leaf", {})
assert adapter.match("/path3/", method="GET") == ("branch", {})
assert adapter.match("/path4", method="GET") == ("leaf", {})
assert adapter.match("/path4/", method="GET") == ("branch", {})


def test_environ_defaults():
environ = create_environ("/foo")
assert environ["PATH_INFO"] == "/foo"
Expand Down