Coverage for tests/test_forms_from_non_typing_sequences.py: 100%
25 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1from fastapi import FastAPI, Form 1abcdef
2from fastapi.testclient import TestClient 1abcdef
4app = FastAPI() 1abcdef
7@app.post("/form/python-list") 1abcdef
8def post_form_param_list(items: list = Form()): 1abcdef
9 return items 1ghijkl
12@app.post("/form/python-set") 1abcdef
13def post_form_param_set(items: set = Form()): 1abcdef
14 return items 1mnopqr
17@app.post("/form/python-tuple") 1abcdef
18def post_form_param_tuple(items: tuple = Form()): 1abcdef
19 return items 1stuvwx
22client = TestClient(app) 1abcdef
25def test_python_list_param_as_form(): 1abcdef
26 response = client.post( 1ghijkl
27 "/form/python-list", data={"items": ["first", "second", "third"]}
28 )
29 assert response.status_code == 200, response.text 1ghijkl
30 assert response.json() == ["first", "second", "third"] 1ghijkl
33def test_python_set_param_as_form(): 1abcdef
34 response = client.post( 1mnopqr
35 "/form/python-set", data={"items": ["first", "second", "third"]}
36 )
37 assert response.status_code == 200, response.text 1mnopqr
38 assert set(response.json()) == {"first", "second", "third"} 1mnopqr
41def test_python_tuple_param_as_form(): 1abcdef
42 response = client.post( 1stuvwx
43 "/form/python-tuple", data={"items": ["first", "second", "third"]}
44 )
45 assert response.status_code == 200, response.text 1stuvwx
46 assert response.json() == ["first", "second", "third"] 1stuvwx