def test_incoming_matches(): # Test Route with one param r = routes.Route("/{greetings}", "test_endpoint") assert r.incoming_matches("/hello") == {"greetings": "hello"} assert r.incoming_matches("/foo") == {"greetings": "foo"} assert r._memo == { "incoming_matches:/hello": {"greetings": "hello"}, "incoming_matches:/foo": {"greetings": "foo"}, } # Test Route with two params r = routes.Route("/{greetings}/{name}", "test_endpoint") assert r.incoming_matches("/hi/john") == {"greetings": "hi", "name": "john"} assert r.incoming_matches("/hello/jane") == {"greetings": "hello", "name": "jane"} # Test Route with no param assert r._memo == { "incoming_matches:/hi/john": {"greetings": "hi", "name": "john"}, "incoming_matches:/hello/jane": {"greetings": "hello", "name": "jane"}, } r = routes.Route("/hello", "test_endpoint") assert r.incoming_matches("/hello") == {} assert r.incoming_matches("/bye") == {} assert r._memo == {"incoming_matches:/hello": {}, "incoming_matches:/bye": {}}
def test_equal(): r = routes.Route("/{path_param}", "test_endpoint") r2 = routes.Route("/{path_param}", "test_endpoint") r3 = routes.Route("/test_path", "test_endpoint") assert r == r2 assert r != r3
def test_does_match_with_route(route, match, expected): r = routes.Route(route, "test_endpoint") assert r.does_match(match) == expected
def test_incoming_matches_with_concrete_path_no_match(): r = routes.Route("/concrete_path", "test_endpoint") assert r.incoming_matches("hello") == {}
def test_incoming_matches_cache(): r = routes.Route("/hello", "test_endpoint") r.incoming_matches("/hello") assert r.incoming_matches.cache_info().hits == 0 r.incoming_matches("/hello") assert r.incoming_matches.cache_info().hits == 1
def test_url(): r = routes.Route("/{my_path}", "test_endpoint") url = r.url(my_path="path") assert url == "/path"
def test_parameter(route, expected): r = routes.Route(route, "test_endpoint") assert r.has_parameters is expected
def test_weight(path_param, expected_weight): r = routes.Route(path_param, "test_endpoint") assert r._weight() == expected_weight
def test_incoming_matches(path_param, actual, match): r = routes.Route(path_param, "test_endpoint") assert r.incoming_matches(actual) == match
def test_custom_specifiers(route, path, expected_result): r = routes.Route(route, "test_endpoint") assert r.incoming_matches(path) == expected_result