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
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from typing import Any, List 1abcde
3from dirty_equals import IsOneOf 1abcde
4from fastapi.params import Body, Cookie, Depends, Header, Param, Path, Query 1abcde
6test_data: List[Any] = ["teststr", None, ..., 1, []] 1abcde
9def get_user(): 1abcde
10 return {} # pragma: no cover
13def test_param_repr_str(): 1abcde
14 assert repr(Param("teststr")) == "Param(teststr)" 1abcde
17def test_param_repr_none(): 1abcde
18 assert repr(Param(None)) == "Param(None)" 1abcde
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 )
29def test_param_repr_number(): 1abcde
30 assert repr(Param(1)) == "Param(1)" 1abcde
33def test_param_repr_list(): 1abcde
34 assert repr(Param([])) == "Param([])" 1abcde
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 )
50def test_query_repr_str(): 1abcde
51 assert repr(Query("teststr")) == "Query(teststr)" 1abcde
54def test_query_repr_none(): 1abcde
55 assert repr(Query(None)) == "Query(None)" 1abcde
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 )
66def test_query_repr_number(): 1abcde
67 assert repr(Query(1)) == "Query(1)" 1abcde
70def test_query_repr_list(): 1abcde
71 assert repr(Query([])) == "Query([])" 1abcde
74def test_header_repr_str(): 1abcde
75 assert repr(Header("teststr")) == "Header(teststr)" 1abcde
78def test_header_repr_none(): 1abcde
79 assert repr(Header(None)) == "Header(None)" 1abcde
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 )
90def test_header_repr_number(): 1abcde
91 assert repr(Header(1)) == "Header(1)" 1abcde
94def test_header_repr_list(): 1abcde
95 assert repr(Header([])) == "Header([])" 1abcde
98def test_cookie_repr_str(): 1abcde
99 assert repr(Cookie("teststr")) == "Cookie(teststr)" 1abcde
102def test_cookie_repr_none(): 1abcde
103 assert repr(Cookie(None)) == "Cookie(None)" 1abcde
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 )
114def test_cookie_repr_number(): 1abcde
115 assert repr(Cookie(1)) == "Cookie(1)" 1abcde
118def test_cookie_repr_list(): 1abcde
119 assert repr(Cookie([])) == "Cookie([])" 1abcde
122def test_body_repr_str(): 1abcde
123 assert repr(Body("teststr")) == "Body(teststr)" 1abcde
126def test_body_repr_none(): 1abcde
127 assert repr(Body(None)) == "Body(None)" 1abcde
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 )
138def test_body_repr_number(): 1abcde
139 assert repr(Body(1)) == "Body(1)" 1abcde
142def test_body_repr_list(): 1abcde
143 assert repr(Body([])) == "Body([])" 1abcde
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 )