Coverage for tests/test_invalid_sequence_param.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

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

2 

3import pytest 1abcdef

4from fastapi import FastAPI, Query 1abcdef

5from pydantic import BaseModel 1abcdef

6 

7 

8def test_invalid_sequence(): 1abcdef

9 with pytest.raises(AssertionError): 1ghijkl

10 app = FastAPI() 1ghijkl

11 

12 class Item(BaseModel): 1ghijkl

13 title: str 1ghijkl

14 

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

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

17 pass # pragma: no cover 

18 

19 

20def test_invalid_tuple(): 1abcdef

21 with pytest.raises(AssertionError): 1mnopqr

22 app = FastAPI() 1mnopqr

23 

24 class Item(BaseModel): 1mnopqr

25 title: str 1mnopqr

26 

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

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

29 pass # pragma: no cover 

30 

31 

32def test_invalid_dict(): 1abcdef

33 with pytest.raises(AssertionError): 1stuvwx

34 app = FastAPI() 1stuvwx

35 

36 class Item(BaseModel): 1stuvwx

37 title: str 1stuvwx

38 

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

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

41 pass # pragma: no cover 

42 

43 

44def test_invalid_simple_dict(): 1abcdef

45 with pytest.raises(AssertionError): 1yzABCD

46 app = FastAPI() 1yzABCD

47 

48 class Item(BaseModel): 1yzABCD

49 title: str 1yzABCD

50 

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

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

53 pass # pragma: no cover