Skip to content

Commit

Permalink
Merge pull request #2458 from pgjones/test
Browse files Browse the repository at this point in the history
Add a test to demonstrate leaf rules don't consume branches
  • Loading branch information
davidism committed Jul 22, 2022
2 parents ffb15ea + cf1d82e commit e1bfc33
Showing 1 changed file with 28 additions and 0 deletions.
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

0 comments on commit e1bfc33

Please sign in to comment.