Coverage for tests/test_forms_from_non_typing_sequences.py: 100%
25 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +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 1abcde
12@app.post("/form/python-set") 1abcde
13def post_form_param_set(items: set = Form()): 1abcde
14 return items 1abcde
17@app.post("/form/python-tuple") 1abcde
18def post_form_param_tuple(items: tuple = Form()): 1abcde
19 return items 1abcde
22client = TestClient(app) 1abcde
25def test_python_list_param_as_form(): 1abcde
26 response = client.post( 1abcde
27 "/form/python-list", data={"items": ["first", "second", "third"]}
28 )
29 assert response.status_code == 200, response.text 1abcde
30 assert response.json() == ["first", "second", "third"] 1abcde
33def test_python_set_param_as_form(): 1abcde
34 response = client.post( 1abcde
35 "/form/python-set", data={"items": ["first", "second", "third"]}
36 )
37 assert response.status_code == 200, response.text 1abcde
38 assert set(response.json()) == {"first", "second", "third"} 1abcde
41def test_python_tuple_param_as_form(): 1abcde
42 response = client.post( 1abcde
43 "/form/python-tuple", data={"items": ["first", "second", "third"]}
44 )
45 assert response.status_code == 200, response.text 1abcde
46 assert response.json() == ["first", "second", "third"] 1abcde