1212 auth_matcher ,
1313 data_matcher ,
1414 enumerate_async ,
15- param_matcher ,
15+ mock_route ,
1616 request_id_matcher ,
1717)
1818from todoist_api_python .models import Attachment
1919
2020if TYPE_CHECKING :
21- from tests .utils .http_mock import RequestsMock
21+ import respx
22+
2223 from todoist_api_python .api import TodoistAPI
2324 from todoist_api_python .api_async import TodoistAPIAsync
2425
2930async def test_get_comment (
3031 todoist_api : TodoistAPI ,
3132 todoist_api_async : TodoistAPIAsync ,
32- requests_mock : RequestsMock ,
33+ respx_mock : respx . MockRouter ,
3334 default_comment_response : dict [str , Any ],
3435 default_comment : Comment ,
3536) -> None :
3637 comment_id = "6X7rM8997g3RQmvh"
3738 endpoint = f"{ DEFAULT_API_URL } /comments/{ comment_id } "
3839
39- requests_mock .add (
40+ mock_route (
41+ respx_mock ,
4042 method = "GET" ,
4143 url = endpoint ,
4244 json = default_comment_response ,
4345 status = 200 ,
44- match = [auth_matcher (), request_id_matcher ()],
46+ matchers = [auth_matcher (), request_id_matcher ()],
4547 )
4648
4749 comment = todoist_api .get_comment (comment_id )
4850
49- assert len (requests_mock .calls ) == 1
51+ assert len (respx_mock .calls ) == 1
5052 assert comment == default_comment
5153
5254 comment = await todoist_api_async .get_comment (comment_id )
5355
54- assert len (requests_mock .calls ) == 2
56+ assert len (respx_mock .calls ) == 2
5557 assert comment == default_comment
5658
5759
5860@pytest .mark .asyncio
5961async def test_get_comments (
6062 todoist_api : TodoistAPI ,
6163 todoist_api_async : TodoistAPIAsync ,
62- requests_mock : RequestsMock ,
64+ respx_mock : respx . MockRouter ,
6365 default_comments_response : list [PaginatedResults ],
6466 default_comments_list : list [list [Comment ]],
6567) -> None :
@@ -68,15 +70,16 @@ async def test_get_comments(
6870
6971 cursor : str | None = None
7072 for page in default_comments_response :
71- requests_mock .add (
73+ mock_route (
74+ respx_mock ,
7275 method = "GET" ,
7376 url = endpoint ,
7477 json = page ,
7578 status = 200 ,
76- match = [
79+ params = {"task_id" : task_id } | ({"cursor" : cursor } if cursor else {}),
80+ matchers = [
7781 auth_matcher (),
7882 request_id_matcher (),
79- param_matcher ({"task_id" : task_id }, cursor ),
8083 ],
8184 )
8285 cursor = page ["next_cursor" ]
@@ -86,14 +89,14 @@ async def test_get_comments(
8689 comments_iter = todoist_api .get_comments (task_id = task_id )
8790
8891 for i , comments in enumerate (comments_iter ):
89- assert len (requests_mock .calls ) == count + 1
92+ assert len (respx_mock .calls ) == count + 1
9093 assert comments == default_comments_list [i ]
9194 count += 1
9295
9396 comments_async_iter = await todoist_api_async .get_comments (task_id = task_id )
9497
9598 async for i , comments in enumerate_async (comments_async_iter ):
96- assert len (requests_mock .calls ) == count + 1
99+ assert len (respx_mock .calls ) == count + 1
97100 assert comments == default_comments_list [i ]
98101 count += 1
99102
@@ -102,7 +105,7 @@ async def test_get_comments(
102105async def test_add_comment (
103106 todoist_api : TodoistAPI ,
104107 todoist_api_async : TodoistAPIAsync ,
105- requests_mock : RequestsMock ,
108+ respx_mock : respx . MockRouter ,
106109 default_comment_response : dict [str , Any ],
107110 default_comment : Comment ,
108111) -> None :
@@ -115,12 +118,13 @@ async def test_add_comment(
115118 file_name = "File.pdf" ,
116119 )
117120
118- requests_mock .add (
121+ mock_route (
122+ respx_mock ,
119123 method = "POST" ,
120124 url = f"{ DEFAULT_API_URL } /comments" ,
121125 json = default_comment_response ,
122126 status = 200 ,
123- match = [
127+ matchers = [
124128 auth_matcher (),
125129 request_id_matcher (),
126130 data_matcher (
@@ -139,7 +143,7 @@ async def test_add_comment(
139143 attachment = attachment ,
140144 )
141145
142- assert len (requests_mock .calls ) == 1
146+ assert len (respx_mock .calls ) == 1
143147 assert new_comment == default_comment
144148
145149 new_comment = await todoist_api_async .add_comment (
@@ -148,65 +152,67 @@ async def test_add_comment(
148152 attachment = attachment ,
149153 )
150154
151- assert len (requests_mock .calls ) == 2
155+ assert len (respx_mock .calls ) == 2
152156 assert new_comment == default_comment
153157
154158
155159@pytest .mark .asyncio
156160async def test_update_comment (
157161 todoist_api : TodoistAPI ,
158162 todoist_api_async : TodoistAPIAsync ,
159- requests_mock : RequestsMock ,
163+ respx_mock : respx . MockRouter ,
160164 default_comment : Comment ,
161165) -> None :
162166 args = {
163167 "content" : "An updated comment" ,
164168 }
165169 updated_comment_dict = default_comment .to_dict () | args
166170
167- requests_mock .add (
171+ mock_route (
172+ respx_mock ,
168173 method = "POST" ,
169174 url = f"{ DEFAULT_API_URL } /comments/{ default_comment .id } " ,
170175 json = updated_comment_dict ,
171176 status = 200 ,
172- match = [auth_matcher (), request_id_matcher (), data_matcher (args )],
177+ matchers = [auth_matcher (), request_id_matcher (), data_matcher (args )],
173178 )
174179
175180 response = todoist_api .update_comment (comment_id = default_comment .id , ** args )
176181
177- assert len (requests_mock .calls ) == 1
182+ assert len (respx_mock .calls ) == 1
178183 assert response == Comment .from_dict (updated_comment_dict )
179184
180185 response = await todoist_api_async .update_comment (
181186 comment_id = default_comment .id , ** args
182187 )
183188
184- assert len (requests_mock .calls ) == 2
189+ assert len (respx_mock .calls ) == 2
185190 assert response == Comment .from_dict (updated_comment_dict )
186191
187192
188193@pytest .mark .asyncio
189194async def test_delete_comment (
190195 todoist_api : TodoistAPI ,
191196 todoist_api_async : TodoistAPIAsync ,
192- requests_mock : RequestsMock ,
197+ respx_mock : respx . MockRouter ,
193198) -> None :
194199 comment_id = "6X7rM8997g3RQmvh"
195200 endpoint = f"{ DEFAULT_API_URL } /comments/{ comment_id } "
196201
197- requests_mock .add (
202+ mock_route (
203+ respx_mock ,
198204 method = "DELETE" ,
199205 url = endpoint ,
200206 status = 204 ,
201- match = [auth_matcher (), request_id_matcher ()],
207+ matchers = [auth_matcher (), request_id_matcher ()],
202208 )
203209
204210 response = todoist_api .delete_comment (comment_id )
205211
206- assert len (requests_mock .calls ) == 1
212+ assert len (respx_mock .calls ) == 1
207213 assert response is True
208214
209215 response = await todoist_api_async .delete_comment (comment_id )
210216
211- assert len (requests_mock .calls ) == 2
217+ assert len (respx_mock .calls ) == 2
212218 assert response is True
0 commit comments