Coverage for tests/test_params_repr.py: 100%

63 statements  

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

1from typing import Any, List 1abcde

2 

3from dirty_equals import IsOneOf 1abcde

4from fastapi.params import Body, Cookie, Depends, Header, Param, Path, Query 1abcde

5 

6test_data: List[Any] = ["teststr", None, ..., 1, []] 1abcde

7 

8 

9def get_user(): 1abcde

10 return {} # pragma: no cover 

11 

12 

13def test_param_repr_str(): 1abcde

14 assert repr(Param("teststr")) == "Param(teststr)" 1abcde

15 

16 

17def test_param_repr_none(): 1abcde

18 assert repr(Param(None)) == "Param(None)" 1abcde

19 

20 

21def test_param_repr_ellipsis(): 1abcde

22 assert repr(Param(...)) == IsOneOf( 1abcde

23 "Param(PydanticUndefined)", 

24 # TODO: remove when deprecating Pydantic v1 

25 "Param(Ellipsis)", 

26 ) 

27 

28 

29def test_param_repr_number(): 1abcde

30 assert repr(Param(1)) == "Param(1)" 1abcde

31 

32 

33def test_param_repr_list(): 1abcde

34 assert repr(Param([])) == "Param([])" 1abcde

35 

36 

37def test_path_repr(): 1abcde

38 assert repr(Path()) == IsOneOf( 1abcde

39 "Path(PydanticUndefined)", 

40 # TODO: remove when deprecating Pydantic v1 

41 "Path(Ellipsis)", 

42 ) 

43 assert repr(Path(...)) == IsOneOf( 1abcde

44 "Path(PydanticUndefined)", 

45 # TODO: remove when deprecating Pydantic v1 

46 "Path(Ellipsis)", 

47 ) 

48 

49 

50def test_query_repr_str(): 1abcde

51 assert repr(Query("teststr")) == "Query(teststr)" 1abcde

52 

53 

54def test_query_repr_none(): 1abcde

55 assert repr(Query(None)) == "Query(None)" 1abcde

56 

57 

58def test_query_repr_ellipsis(): 1abcde

59 assert repr(Query(...)) == IsOneOf( 1abcde

60 "Query(PydanticUndefined)", 

61 # TODO: remove when deprecating Pydantic v1 

62 "Query(Ellipsis)", 

63 ) 

64 

65 

66def test_query_repr_number(): 1abcde

67 assert repr(Query(1)) == "Query(1)" 1abcde

68 

69 

70def test_query_repr_list(): 1abcde

71 assert repr(Query([])) == "Query([])" 1abcde

72 

73 

74def test_header_repr_str(): 1abcde

75 assert repr(Header("teststr")) == "Header(teststr)" 1abcde

76 

77 

78def test_header_repr_none(): 1abcde

79 assert repr(Header(None)) == "Header(None)" 1abcde

80 

81 

82def test_header_repr_ellipsis(): 1abcde

83 assert repr(Header(...)) == IsOneOf( 1abcde

84 "Header(PydanticUndefined)", 

85 # TODO: remove when deprecating Pydantic v1 

86 "Header(Ellipsis)", 

87 ) 

88 

89 

90def test_header_repr_number(): 1abcde

91 assert repr(Header(1)) == "Header(1)" 1abcde

92 

93 

94def test_header_repr_list(): 1abcde

95 assert repr(Header([])) == "Header([])" 1abcde

96 

97 

98def test_cookie_repr_str(): 1abcde

99 assert repr(Cookie("teststr")) == "Cookie(teststr)" 1abcde

100 

101 

102def test_cookie_repr_none(): 1abcde

103 assert repr(Cookie(None)) == "Cookie(None)" 1abcde

104 

105 

106def test_cookie_repr_ellipsis(): 1abcde

107 assert repr(Cookie(...)) == IsOneOf( 1abcde

108 "Cookie(PydanticUndefined)", 

109 # TODO: remove when deprecating Pydantic v1 

110 "Cookie(Ellipsis)", 

111 ) 

112 

113 

114def test_cookie_repr_number(): 1abcde

115 assert repr(Cookie(1)) == "Cookie(1)" 1abcde

116 

117 

118def test_cookie_repr_list(): 1abcde

119 assert repr(Cookie([])) == "Cookie([])" 1abcde

120 

121 

122def test_body_repr_str(): 1abcde

123 assert repr(Body("teststr")) == "Body(teststr)" 1abcde

124 

125 

126def test_body_repr_none(): 1abcde

127 assert repr(Body(None)) == "Body(None)" 1abcde

128 

129 

130def test_body_repr_ellipsis(): 1abcde

131 assert repr(Body(...)) == IsOneOf( 1abcde

132 "Body(PydanticUndefined)", 

133 # TODO: remove when deprecating Pydantic v1 

134 "Body(Ellipsis)", 

135 ) 

136 

137 

138def test_body_repr_number(): 1abcde

139 assert repr(Body(1)) == "Body(1)" 1abcde

140 

141 

142def test_body_repr_list(): 1abcde

143 assert repr(Body([])) == "Body([])" 1abcde

144 

145 

146def test_depends_repr(): 1abcde

147 assert repr(Depends()) == "Depends(NoneType)" 1abcde

148 assert repr(Depends(get_user)) == "Depends(get_user)" 1abcde

149 assert repr(Depends(use_cache=False)) == "Depends(NoneType, use_cache=False)" 1abcde

150 assert ( 1abcde

151 repr(Depends(get_user, use_cache=False)) == "Depends(get_user, use_cache=False)" 

152 )