Coverage for tests/test_invalid_sequence_param.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

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

2 

3import pytest 1abcde

4from fastapi import FastAPI, Query 1abcde

5from pydantic import BaseModel 1abcde

6 

7 

8def test_invalid_sequence(): 1abcde

9 with pytest.raises(AssertionError): 1abcde

10 app = FastAPI() 1abcde

11 

12 class Item(BaseModel): 1abcde

13 title: str 1abcde

14 

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

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

17 pass # pragma: no cover 

18 

19 

20def test_invalid_tuple(): 1abcde

21 with pytest.raises(AssertionError): 1abcde

22 app = FastAPI() 1abcde

23 

24 class Item(BaseModel): 1abcde

25 title: str 1abcde

26 

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

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

29 pass # pragma: no cover 

30 

31 

32def test_invalid_dict(): 1abcde

33 with pytest.raises(AssertionError): 1abcde

34 app = FastAPI() 1abcde

35 

36 class Item(BaseModel): 1abcde

37 title: str 1abcde

38 

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

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

41 pass # pragma: no cover 

42 

43 

44def test_invalid_simple_dict(): 1abcde

45 with pytest.raises(AssertionError): 1abcde

46 app = FastAPI() 1abcde

47 

48 class Item(BaseModel): 1abcde

49 title: str 1abcde

50 

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

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

53 pass # pragma: no cover