File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -86,3 +86,35 @@ def post_x(self, body: RequestBody) -> None:
86
86
assert client .post_x (RequestBody (x = 1 , y = "test" )) is None
87
87
assert mocker .called_once
88
88
assert mocker .request_history [0 ].json () == {"x" : 1 , "y" : "test" }
89
+
90
+
91
+ def test_kwonly_param (session : requests .Session , mocker : requests_mock .Mocker ):
92
+ class Api (RequestsClient ):
93
+ @post ("/post/" )
94
+ def post (
95
+ self ,
96
+ * ,
97
+ body : RequestBody ,
98
+ ) -> None :
99
+ raise NotImplementedError
100
+
101
+ @get ("/get/{id}" )
102
+ def get_x (self , * , id : str , param : str = "1" ) -> List [int ]:
103
+ raise NotImplementedError
104
+
105
+ mocker .post (
106
+ url = "http://example.com/post/" ,
107
+ text = "null" ,
108
+ complete_qs = True ,
109
+ )
110
+ mocker .get (
111
+ url = "http://example.com/get/x?param=1" ,
112
+ text = "[0]" ,
113
+ complete_qs = True ,
114
+ )
115
+ client = Api (base_url = "http://example.com" , session = session )
116
+ assert client .post (body = RequestBody (x = 1 , y = "test" )) is None
117
+ assert mocker .called_once
118
+ assert mocker .request_history [0 ].json () == {"x" : 1 , "y" : "test" }
119
+
120
+ assert client .get_x (id = "x" ) == [0 ]
You can’t perform that action at this time.
0 commit comments