Coverage for tests/test_invalid_path_param.py: 100%

45 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-01-13 13:38 +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): 1fghij

10 app = FastAPI() 1fghij

11 

12 class Item(BaseModel): 1fghij

13 title: str 1fghij

14 

15 @app.get("/items/{id}") 1fghij

16 def read_items(id: List[Item]): 1fghij

17 pass # pragma: no cover 

18 

19 

20def test_invalid_tuple(): 1abcde

21 with pytest.raises(AssertionError): 1klmno

22 app = FastAPI() 1klmno

23 

24 class Item(BaseModel): 1klmno

25 title: str 1klmno

26 

27 @app.get("/items/{id}") 1klmno

28 def read_items(id: Tuple[Item, Item]): 1klmno

29 pass # pragma: no cover 

30 

31 

32def test_invalid_dict(): 1abcde

33 with pytest.raises(AssertionError): 1pqrst

34 app = FastAPI() 1pqrst

35 

36 class Item(BaseModel): 1pqrst

37 title: str 1pqrst

38 

39 @app.get("/items/{id}") 1pqrst

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

41 pass # pragma: no cover 

42 

43 

44def test_invalid_simple_list(): 1abcde

45 with pytest.raises(AssertionError): 1uvwxy

46 app = FastAPI() 1uvwxy

47 

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

49 def read_items(id: list): 1uvwxy

50 pass # pragma: no cover 

51 

52 

53def test_invalid_simple_tuple(): 1abcde

54 with pytest.raises(AssertionError): 1zABCD

55 app = FastAPI() 1zABCD

56 

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

58 def read_items(id: tuple): 1zABCD

59 pass # pragma: no cover 

60 

61 

62def test_invalid_simple_set(): 1abcde

63 with pytest.raises(AssertionError): 1EFGHI

64 app = FastAPI() 1EFGHI

65 

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

67 def read_items(id: set): 1EFGHI

68 pass # pragma: no cover 

69 

70 

71def test_invalid_simple_dict(): 1abcde

72 with pytest.raises(AssertionError): 1JKLMN

73 app = FastAPI() 1JKLMN

74 

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

76 def read_items(id: dict): 1JKLMN

77 pass # pragma: no cover