Coverage for tests/test_invalid_path_param.py: 100%

45 statements  

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

1from typing import Dict, List, Tuple 1abcde

2 

3import pytest 1abcde

4from fastapi import FastAPI 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/{id}") 1abcde

16 def read_items(id: List[Item]): 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/{id}") 1abcde

28 def read_items(id: Tuple[Item, Item]): 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/{id}") 1abcde

40 def read_items(id: Dict[str, Item]): 1abcde

41 pass # pragma: no cover 

42 

43 

44def test_invalid_simple_list(): 1abcde

45 with pytest.raises(AssertionError): 1abcde

46 app = FastAPI() 1abcde

47 

48 @app.get("/items/{id}") 1abcde

49 def read_items(id: list): 1abcde

50 pass # pragma: no cover 

51 

52 

53def test_invalid_simple_tuple(): 1abcde

54 with pytest.raises(AssertionError): 1abcde

55 app = FastAPI() 1abcde

56 

57 @app.get("/items/{id}") 1abcde

58 def read_items(id: tuple): 1abcde

59 pass # pragma: no cover 

60 

61 

62def test_invalid_simple_set(): 1abcde

63 with pytest.raises(AssertionError): 1abcde

64 app = FastAPI() 1abcde

65 

66 @app.get("/items/{id}") 1abcde

67 def read_items(id: set): 1abcde

68 pass # pragma: no cover 

69 

70 

71def test_invalid_simple_dict(): 1abcde

72 with pytest.raises(AssertionError): 1abcde

73 app = FastAPI() 1abcde

74 

75 @app.get("/items/{id}") 1abcde

76 def read_items(id: dict): 1abcde

77 pass # pragma: no cover