def test_route_match() -> None: route = Route("/pets/{pet_id}") route = route.match("/pets/11a22") assert route["pet_id"] == "11a22" route = Route("/pets/{pet_id}") route = route.match("/pets/22") assert route._parameters == {"pet_id": 22}
def test_can_copy_route() -> None: # given base_route = Route("/test/{parameter}") # when match_route = base_route.match("/test/test-1") route_copy = copy(match_route) # then assert match_route assert route_copy.attributes == match_route.attributes assert route_copy.route == match_route.route assert route_copy.parameters == match_route.parameters
def test_route_match_multiple_parameters() -> None: route = Route("/pets/{pet_id}/{category}") route = route.match("/pets/11a22/test") assert route["pet_id"] == "11a22" assert route["category"] == "test"
def test_route_parsing_with_wildcards() -> None: route = Route("/example/{a}*") assert route.pattern == re.compile(r"^/example/([^/]+).*?$", re.I | re.M) assert route.match("/example/test/1/2/3") assert route.match("/example/11")
def test_route_parsing() -> None: route = Route("/example/{pattern}") assert route.match("/example/test")