예제 #1
0
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": {}}
예제 #2
0
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
예제 #3
0
def test_does_match_with_route(route, match, expected):
    r = routes.Route(route, "test_endpoint")
    assert r.does_match(match) == expected
예제 #4
0
def test_incoming_matches_with_concrete_path_no_match():
    r = routes.Route("/concrete_path", "test_endpoint")
    assert r.incoming_matches("hello") == {}
예제 #5
0
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
예제 #6
0
def test_url():
    r = routes.Route("/{my_path}", "test_endpoint")
    url = r.url(my_path="path")
    assert url == "/path"
예제 #7
0
def test_parameter(route, expected):
    r = routes.Route(route, "test_endpoint")
    assert r.has_parameters is expected
예제 #8
0
def test_weight(path_param, expected_weight):
    r = routes.Route(path_param, "test_endpoint")
    assert r._weight() == expected_weight
예제 #9
0
def test_incoming_matches(path_param, actual, match):
    r = routes.Route(path_param, "test_endpoint")
    assert r.incoming_matches(actual) == match
예제 #10
0
def test_custom_specifiers(route, path, expected_result):
    r = routes.Route(route, "test_endpoint")
    assert r.incoming_matches(path) == expected_result