v2 AST router (#2133)
* Update some tests * Update some tests * Resolve #2122 route decorator returning tuple * Use rc sanic-routing version * Update unit tests to <:str>
This commit is contained in:
parent
7c180376d6
commit
108a4a99c7
|
@ -160,7 +160,9 @@ class RouteMixin:
|
|||
if apply:
|
||||
self._apply_route(route)
|
||||
|
||||
return route, handler
|
||||
if static:
|
||||
return route, handler
|
||||
return handler
|
||||
|
||||
return decorator
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ class SignalRouter(BaseRouter):
|
|||
f".{event}",
|
||||
self.DEFAULT_METHOD,
|
||||
self,
|
||||
{"__params__": {}},
|
||||
{"__params__": {}, "__matches__": {}},
|
||||
extra=extra,
|
||||
)
|
||||
except NotFound:
|
||||
|
@ -59,7 +59,13 @@ class SignalRouter(BaseRouter):
|
|||
terms.append(extra)
|
||||
raise NotFound(message % tuple(terms))
|
||||
|
||||
params = param_basket.pop("__params__")
|
||||
params = param_basket["__params__"]
|
||||
if not params:
|
||||
params = {
|
||||
param.name: param_basket["__matches__"][idx]
|
||||
for idx, param in group.params.items()
|
||||
}
|
||||
|
||||
return group, [route.handler for route in group], params
|
||||
|
||||
async def _dispatch(
|
||||
|
|
2
setup.py
2
setup.py
|
@ -83,7 +83,7 @@ ujson = "ujson>=1.35" + env_dependency
|
|||
uvloop = "uvloop>=0.5.3" + env_dependency
|
||||
|
||||
requirements = [
|
||||
"sanic-routing>=0.6.0",
|
||||
"sanic-routing==0.7.0rc1",
|
||||
"httptools>=0.0.10",
|
||||
uvloop,
|
||||
ujson,
|
||||
|
|
|
@ -234,7 +234,7 @@ def test_named_dynamic_route():
|
|||
app.router.routes_all[
|
||||
(
|
||||
"folder",
|
||||
"<name>",
|
||||
"<name:str>",
|
||||
)
|
||||
].name
|
||||
== "app.route_dynamic"
|
||||
|
@ -369,7 +369,8 @@ def test_dynamic_add_named_route():
|
|||
|
||||
app.add_route(handler, "/folder/<name>", name="route_dynamic")
|
||||
assert (
|
||||
app.router.routes_all[("folder", "<name>")].name == "app.route_dynamic"
|
||||
app.router.routes_all[("folder", "<name:str>")].name
|
||||
== "app.route_dynamic"
|
||||
)
|
||||
assert app.url_for("route_dynamic", name="test") == "/folder/test"
|
||||
with pytest.raises(URLBuildError):
|
||||
|
|
|
@ -2246,9 +2246,7 @@ def test_conflicting_body_methods_overload(app):
|
|||
|
||||
|
||||
def test_handler_overload(app):
|
||||
@app.get(
|
||||
"/long/sub/route/param_a/<param_a:string>/param_b/<param_b:string>"
|
||||
)
|
||||
@app.get("/long/sub/route/param_a/<param_a:str>/param_b/<param_b:str>")
|
||||
@app.post("/long/sub/route/")
|
||||
def handler(request, **kwargs):
|
||||
return json(kwargs)
|
||||
|
|
|
@ -258,7 +258,7 @@ def test_route_strict_slash(app):
|
|||
def test_route_invalid_parameter_syntax(app):
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
@app.get("/get/<:string>", strict_slashes=True)
|
||||
@app.get("/get/<:str>", strict_slashes=True)
|
||||
def handler(request):
|
||||
return text("OK")
|
||||
|
||||
|
@ -478,7 +478,7 @@ def test_dynamic_route(app):
|
|||
def test_dynamic_route_string(app):
|
||||
results = []
|
||||
|
||||
@app.route("/folder/<name:string>")
|
||||
@app.route("/folder/<name:str>")
|
||||
async def handler(request, name):
|
||||
results.append(name)
|
||||
return text("OK")
|
||||
|
@ -513,7 +513,7 @@ def test_dynamic_route_int(app):
|
|||
def test_dynamic_route_number(app):
|
||||
results = []
|
||||
|
||||
@app.route("/weight/<weight:number>")
|
||||
@app.route("/weight/<weight:float>")
|
||||
async def handler(request, weight):
|
||||
results.append(weight)
|
||||
return text("OK")
|
||||
|
@ -585,7 +585,6 @@ def test_dynamic_route_path(app):
|
|||
return text("OK")
|
||||
|
||||
app.router.finalize()
|
||||
print(app.router.find_route_src)
|
||||
|
||||
request, response = app.test_client.get("/path/1/info")
|
||||
assert response.status == 200
|
||||
|
@ -824,7 +823,7 @@ def test_dynamic_add_route_string(app):
|
|||
results.append(name)
|
||||
return text("OK")
|
||||
|
||||
app.add_route(handler, "/folder/<name:string>")
|
||||
app.add_route(handler, "/folder/<name:str>")
|
||||
request, response = app.test_client.get("/folder/test123")
|
||||
|
||||
assert response.text == "OK"
|
||||
|
@ -860,7 +859,7 @@ def test_dynamic_add_route_number(app):
|
|||
results.append(weight)
|
||||
return text("OK")
|
||||
|
||||
app.add_route(handler, "/weight/<weight:number>")
|
||||
app.add_route(handler, "/weight/<weight:float>")
|
||||
|
||||
request, response = app.test_client.get("/weight/12345")
|
||||
assert response.text == "OK"
|
||||
|
@ -1067,7 +1066,8 @@ def test_uri_with_different_method_and_different_params(app):
|
|||
return json({"action": action})
|
||||
|
||||
request, response = app.test_client.get("/ads/1234")
|
||||
assert response.status == 405
|
||||
assert response.status == 200
|
||||
assert response.json == {"ad_id": "1234"}
|
||||
|
||||
request, response = app.test_client.post("/ads/post")
|
||||
assert response.status == 200
|
||||
|
|
|
@ -143,7 +143,7 @@ def test_fails_url_build_if_params_not_passed(app):
|
|||
|
||||
COMPLEX_PARAM_URL = (
|
||||
"/<foo:int>/<four_letter_string:[A-z]{4}>/"
|
||||
"<two_letter_string:[A-z]{2}>/<normal_string>/<some_number:number>"
|
||||
"<two_letter_string:[A-z]{2}>/<normal_string>/<some_number:float>"
|
||||
)
|
||||
PASSING_KWARGS = {
|
||||
"foo": 4,
|
||||
|
@ -168,7 +168,7 @@ def test_fails_with_int_message(app):
|
|||
|
||||
expected_error = (
|
||||
r'Value "not_int" for parameter `foo` '
|
||||
r"does not match pattern for type `int`: ^-?\d+"
|
||||
r"does not match pattern for type `int`: ^-?\d+$"
|
||||
)
|
||||
assert str(e.value) == expected_error
|
||||
|
||||
|
@ -223,7 +223,7 @@ def test_fails_with_number_message(app):
|
|||
|
||||
@pytest.mark.parametrize("number", [3, -3, 13.123, -13.123])
|
||||
def test_passes_with_negative_number_message(app, number):
|
||||
@app.route("path/<possibly_neg:number>/another-word")
|
||||
@app.route("path/<possibly_neg:float>/another-word")
|
||||
def good(request, possibly_neg):
|
||||
assert isinstance(possibly_neg, (int, float))
|
||||
return text(f"this should pass with `{possibly_neg}`")
|
||||
|
|
Loading…
Reference in New Issue
Block a user