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

View File

@ -88,18 +88,18 @@ def test_bp_strict_slash(app):
app.blueprint(bp) app.blueprint(bp)
# request, response = app.test_client.get("/get") request, response = app.test_client.get("/get")
# assert response.text == "OK" assert response.text == "OK"
# assert response.json is None assert response.json is None
# request, response = app.test_client.get("/get/") request, response = app.test_client.get("/get/")
# assert response.status == 404 assert response.status == 404
request, response = app.test_client.post("/post/") request, response = app.test_client.post("/post/")
assert response.text == "OK" assert response.text == "OK"
# request, response = app.test_client.post("/post") request, response = app.test_client.post("/post")
# assert response.status == 404 assert response.status == 404
def test_bp_strict_slash_default_value(app): 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): async def handler(request, folder_id):
return text("OK") return text("OK")
app.router.finalize()
print(app.router.find_route_src)
request, response = app.test_client.get("/folder/test") request, response = app.test_client.get("/folder/test")
assert response.status == 200 assert response.status == 200