Coverage for tests / test_forms_from_non_typing_sequences.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from fastapi import FastAPI, Form 1abcd

2from fastapi.testclient import TestClient 1abcd

3 

4app = FastAPI() 1abcd

5 

6 

7@app.post("/form/python-list") 1abcd

8def post_form_param_list(items: list = Form()): 1abcd

9 return items 1efg

10 

11 

12@app.post("/form/python-set") 1abcd

13def post_form_param_set(items: set = Form()): 1abcd

14 return items 1hij

15 

16 

17@app.post("/form/python-tuple") 1abcd

18def post_form_param_tuple(items: tuple = Form()): 1abcd

19 return items 1klm

20 

21 

22client = TestClient(app) 1abcd

23 

24 

25def test_python_list_param_as_form(): 1abcd

26 response = client.post( 1efg

27 "/form/python-list", data={"items": ["first", "second", "third"]} 

28 ) 

29 assert response.status_code == 200, response.text 1efg

30 assert response.json() == ["first", "second", "third"] 1efg

31 

32 

33def test_python_set_param_as_form(): 1abcd

34 response = client.post( 1hij

35 "/form/python-set", data={"items": ["first", "second", "third"]} 

36 ) 

37 assert response.status_code == 200, response.text 1hij

38 assert set(response.json()) == {"first", "second", "third"} 1hij

39 

40 

41def test_python_tuple_param_as_form(): 1abcd

42 response = client.post( 1klm

43 "/form/python-tuple", data={"items": ["first", "second", "third"]} 

44 ) 

45 assert response.status_code == 200, response.text 1klm

46 assert response.json() == ["first", "second", "third"] 1klm