Add extra tests for query parameters with list types

This commit is contained in:
Sebastián Ramírez 2024-04-18 16:32:58 -05:00
parent 3f2d05e120
commit baccf0f6dd
2 changed files with 34 additions and 1 deletions

View File

@ -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

View File

@ -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() == []