test coverage with param change

This commit is contained in:
Adam Hopkins 2021-02-09 16:17:53 +02:00
parent 6b68c3702e
commit b850e49cb3
3 changed files with 41 additions and 42 deletions

View File

@ -405,11 +405,10 @@ class Sanic(BaseSanic):
# find all the parameters we will need to build in the URL
# matched_params = re.findall(self.router.parameter_pattern, uri)
route.finalize()
for params in route.params.values():
for param_info in route.params.values():
# name, _type, pattern = self.router.parse_parameter_string(match)
# we only want to match against each individual parameter
for idx, param_info in enumerate(params):
try:
supplied_param = str(kwargs.pop(param_info.name))
except KeyError:
@ -423,7 +422,6 @@ class Sanic(BaseSanic):
if param_info.pattern:
passes_pattern = param_info.pattern.match(supplied_param)
if not passes_pattern:
if idx + 1 == len(params):
if param_info.cast != str:
msg = (
f'Value "{supplied_param}" '
@ -439,8 +437,6 @@ class Sanic(BaseSanic):
f"pattern {param_info.pattern.pattern}"
)
raise URLBuildError(msg)
else:
continue
# replace the parameter in the URL with the supplied value
replacement_regex = f"(<{param_info.name}.*?>)"

View File

@ -88,18 +88,18 @@ def test_bp_strict_slash(app):
app.blueprint(bp)
# request, response = app.test_client.get("/get")
# assert response.text == "OK"
# assert response.json is None
request, response = app.test_client.get("/get")
assert response.text == "OK"
assert response.json is None
# request, response = app.test_client.get("/get/")
# assert response.status == 404
request, response = app.test_client.get("/get/")
assert response.status == 404
request, response = app.test_client.post("/post/")
assert response.text == "OK"
# request, response = app.test_client.post("/post")
# assert response.status == 404
request, response = app.test_client.post("/post")
assert response.status == 404
def test_bp_strict_slash_default_value(app):

View File

@ -538,6 +538,9 @@ def test_dynamic_route_regex(app):
async def handler(request, folder_id):
return text("OK")
app.router.finalize()
print(app.router.find_route_src)
request, response = app.test_client.get("/folder/test")
assert response.status == 200