Browse Source

Merge cbc10396c9 into 460f8d2cc8

pull/14883/merge
Dawit Worku 12 hours ago
committed by GitHub
parent
commit
8d839dccc7
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      fastapi/utils.py
  2. 12
      tests/test_starlette_urlconvertors.py

3
fastapi/utils.py

@ -41,7 +41,8 @@ def is_body_allowed_for_status_code(status_code: int | str | None) -> bool:
def get_path_param_names(path: str) -> set[str]:
return set(re.findall("{(.*?)}", path))
params = re.findall("{(.*?)}", path)
return {param.split(":", 1)[0] for param in params}
_invalid_args_message = (

12
tests/test_starlette_urlconvertors.py

@ -19,6 +19,11 @@ def path_convertor(param: str = Path()):
return {"path": param}
@app.get("/path-implicit/{param:path}")
def path_convertor_implicit(param: str):
return {"path": param}
@app.get("/query/")
def query_convertor(param: str = Query()):
return {"query": param}
@ -50,6 +55,13 @@ def test_route_converters_path():
assert response.json() == {"path": "some/example"}
def test_route_converters_path_implicit():
# Test path conversion without explicit Path()
response = client.get("/path-implicit/some/example")
assert response.status_code == 200, response.text
assert response.json() == {"path": "some/example"}
def test_route_converters_query():
# Test query conversion
response = client.get("/query", params={"param": "Qué tal!"})

Loading…
Cancel
Save