From 9ea705b2ea8318c90f9058d7bdabdefc7f94f50d Mon Sep 17 00:00:00 2001 From: taoufik07 Date: Tue, 12 Mar 2019 17:39:53 +0100 Subject: [PATCH] Specifiers test --- tests/test_routes.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_routes.py b/tests/test_routes.py index 02230d1..7198296 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -131,3 +131,30 @@ def test_does_match_with_route(route, match, expected): def test_weight(path_param, expected_weight): r = routes.Route(path_param, "test_endpoint") assert r._weight() == expected_weight + + +@pytest.mark.parametrize( + "route, path, expected_result", + [ + pytest.param("/{greetings:str}", "/hello", {"greetings": "hello"}), + pytest.param( + "/{greetings:str}/{who}", + "/hello/Laidia", + {"greetings": "hello", "who": "Laidia"}, + ), + pytest.param("/{birth_date:int}", "/1937", {"birth_date": 1937}), + pytest.param( + "/{name:str}/{age:int}", "/Fatna/80", {"name": "Fatna", "age": 80} + ), + pytest.param( + "/{x:float}/{y:float}", "/10.20/75", {"x": float(10.20), "y": float(75)} + ), + pytest.param("/{name:str}/{age:int}", "/Fatna/eighty", {}), + pytest.param("/{greetings:int}", "/hello", {}), + pytest.param("/{name:float}", "/Fatna", {}), + ], +) +def test_custom_specifiers(route, path, expected_result): + r = routes.Route(route, "test_endpoint") + print(r.incoming_matches(path)) + assert r.incoming_matches(path) == expected_result