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