mirror of https://github.com/tiangolo/fastapi.git
✅ Add extra tests for query parameters with list types
This commit is contained in:
parent
3f2d05e120
commit
baccf0f6dd
|
|
@ -1,5 +1,5 @@
|
|||
import http
|
||||
from typing import FrozenSet, Optional
|
||||
from typing import FrozenSet, List, Optional
|
||||
|
||||
from fastapi import FastAPI, Path, Query
|
||||
|
||||
|
|
@ -192,3 +192,13 @@ def get_enum_status_code():
|
|||
@app.get("/query/frozenset")
|
||||
def get_query_type_frozenset(query: FrozenSet[int] = Query(...)):
|
||||
return ",".join(map(str, sorted(query)))
|
||||
|
||||
|
||||
@app.get("/query/list")
|
||||
def get_query_list(device_ids: List[int] = Query()) -> List[int]:
|
||||
return device_ids
|
||||
|
||||
|
||||
@app.get("/query/list-default")
|
||||
def get_query_list_default(device_ids: List[int] = Query(default=[])) -> List[int]:
|
||||
return device_ids
|
||||
|
|
|
|||
|
|
@ -396,3 +396,26 @@ def test_query_frozenset_query_1_query_1_query_2():
|
|||
response = client.get("/query/frozenset/?query=1&query=1&query=2")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == "1,2"
|
||||
|
||||
|
||||
def test_query_list():
|
||||
response = client.get("/query/list/?device_ids=1&device_ids=2")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == [1, 2]
|
||||
|
||||
|
||||
def test_query_list_empty():
|
||||
response = client.get("/query/list/")
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_query_list_default():
|
||||
response = client.get("/query/list-default/?device_ids=1&device_ids=2")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == [1, 2]
|
||||
|
||||
|
||||
def test_query_list_default_empty():
|
||||
response = client.get("/query/list-default/")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == []
|
||||
|
|
|
|||
Loading…
Reference in New Issue