Coverage for tests/test_invalid_sequence_param.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1from typing import Dict, List, Optional, Tuple 1abcdefg

2 

3import pytest 1abcdefg

4from fastapi import FastAPI, Query 1abcdefg

5from pydantic import BaseModel 1abcdefg

6 

7 

8def test_invalid_sequence(): 1abcdefg

9 with pytest.raises(AssertionError): 1hijklmn

10 app = FastAPI() 1hijklmn

11 

12 class Item(BaseModel): 1hijklmn

13 title: str 1hijklmn

14 

15 @app.get("/items/") 1hijklmn

16 def read_items(q: List[Item] = Query(default=None)): 1hijklmn

17 pass # pragma: no cover 

18 

19 

20def test_invalid_tuple(): 1abcdefg

21 with pytest.raises(AssertionError): 1opqrstu

22 app = FastAPI() 1opqrstu

23 

24 class Item(BaseModel): 1opqrstu

25 title: str 1opqrstu

26 

27 @app.get("/items/") 1opqrstu

28 def read_items(q: Tuple[Item, Item] = Query(default=None)): 1opqrstu

29 pass # pragma: no cover 

30 

31 

32def test_invalid_dict(): 1abcdefg

33 with pytest.raises(AssertionError): 1vwxyzAB

34 app = FastAPI() 1vwxyzAB

35 

36 class Item(BaseModel): 1vwxyzAB

37 title: str 1vwxyzAB

38 

39 @app.get("/items/") 1vwxyzAB

40 def read_items(q: Dict[str, Item] = Query(default=None)): 1vwxyzAB

41 pass # pragma: no cover 

42 

43 

44def test_invalid_simple_dict(): 1abcdefg

45 with pytest.raises(AssertionError): 1CDEFGHI

46 app = FastAPI() 1CDEFGHI

47 

48 class Item(BaseModel): 1CDEFGHI

49 title: str 1CDEFGHI

50 

51 @app.get("/items/") 1CDEFGHI

52 def read_items(q: Optional[dict] = Query(default=None)): 1CDEFGHI

53 pass # pragma: no cover