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 test for duplicate path url but different methods #44

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,44 @@ def handler2():
_, handler, params = router.get("/path/to/bar", "three")
assert handler() == "handler2"
assert params == {"foo": "bar"}


def test_identical_path_routes_with_different_methods(handler):
def handler1():
return "handler1"

def handler2():
return "handler2"

#test root level path with different methods
router1 = Router()
router1.add("/<foo:path>", handler1, methods=["GET", "OPTIONS"])
router1.add("/<foo:path>", handler2, methods=["POST"])
router1.finalize()

_, handler, params = router1.get("/a/random/path", "POST")
assert handler() == "handler2"
assert params == {"foo": "a/random/path"}

_, handler, params = router1.get("/a/random/path", "GET")
assert handler() == "handler1"
assert params == {"foo": "a/random/path"}

#a more complex test
router2 = Router()
router2.add("/<foo:path>", handler1, methods=["OPTIONS"])
router2.add("/api/<version:int>/hello_world/", handler2, methods=["POST"])
router2.add("/api/<version:int>/hello_world/<foo:path>", handler2, methods=["GET"])
router2.finalize()

_, handler, params = router2.get("/a/random/path", "OPTIONS")
assert handler() == "handler1"
assert params == {"foo": "a/random/path"}

_, handler, params = router2.get("/api/3/hello_world/", "POST")
assert handler() == "handler2"
assert params == {"version": 3}

_, handler, params = router2.get("/api/3/hello_world/results/1488", "GET")
assert handler() == "handler2"
assert params == {"version": 3, "foo": "results/1488"}