Skip to content

Commit 5a1cfc3

Browse files
committed
Standardize query assertions with param_matcher in tests
Restore parameter checks to the same matcher-based structure as auth and payload checks. mock_route now derives deterministic respx route selection from param_matcher while still running all matcher assertions at request time.
1 parent 0921833 commit 5a1cfc3

10 files changed

Lines changed: 95 additions & 38 deletions

tests/test_api_comments.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
data_matcher,
1414
enumerate_async,
1515
mock_route,
16+
param_matcher,
1617
request_id_matcher,
1718
)
1819
from todoist_api_python.models import Attachment
@@ -76,10 +77,12 @@ async def test_get_comments(
7677
url=endpoint,
7778
json=page,
7879
status=200,
79-
params={"task_id": task_id} | ({"cursor": cursor} if cursor else {}),
8080
matchers=[
8181
auth_matcher(),
8282
request_id_matcher(),
83+
param_matcher(
84+
{"task_id": task_id} | ({"cursor": cursor} if cursor else {})
85+
),
8386
],
8487
)
8588
cursor = page["next_cursor"]

tests/test_api_completed_tasks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
auth_matcher,
1717
enumerate_async,
1818
mock_route,
19+
param_matcher,
1920
request_id_matcher,
2021
)
2122
from todoist_api_python._core.utils import format_datetime
@@ -58,10 +59,10 @@ async def test_get_completed_tasks_by_due_date(
5859
url=endpoint,
5960
json=page,
6061
status=200,
61-
params=params | ({"cursor": cursor} if cursor else {}),
6262
matchers=[
6363
auth_matcher(),
6464
request_id_matcher(),
65+
param_matcher(params | ({"cursor": cursor} if cursor else {})),
6566
],
6667
)
6768
cursor = page["next_cursor"]
@@ -123,10 +124,10 @@ async def test_get_completed_tasks_by_completion_date(
123124
url=endpoint,
124125
json=page,
125126
status=200,
126-
params=params | ({"cursor": cursor} if cursor else {}),
127127
matchers=[
128128
auth_matcher(),
129129
request_id_matcher(),
130+
param_matcher(params | ({"cursor": cursor} if cursor else {})),
130131
],
131132
)
132133
cursor = page["next_cursor"]

tests/test_api_labels.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
data_matcher,
1111
enumerate_async,
1212
mock_route,
13+
param_matcher,
1314
request_id_matcher,
1415
)
1516

@@ -70,8 +71,11 @@ async def test_get_labels(
7071
url=endpoint,
7172
json=page,
7273
status=200,
73-
params={"cursor": cursor} if cursor else {},
74-
matchers=[auth_matcher(), request_id_matcher()],
74+
matchers=[
75+
auth_matcher(),
76+
request_id_matcher(),
77+
param_matcher({"cursor": cursor} if cursor else {}),
78+
],
7579
)
7680
cursor = page["next_cursor"]
7781

@@ -111,10 +115,12 @@ async def test_search_labels(
111115
url=endpoint,
112116
json=page,
113117
status=200,
114-
params={"query": query} | ({"cursor": cursor} if cursor else {}),
115118
matchers=[
116119
auth_matcher(),
117120
request_id_matcher(),
121+
param_matcher(
122+
{"query": query} | ({"cursor": cursor} if cursor else {})
123+
),
118124
],
119125
)
120126
cursor = page["next_cursor"]
@@ -267,5 +273,3 @@ async def test_delete_label(
267273

268274
assert len(respx_mock.calls) == 2
269275
assert response is True
270-
271-

tests/test_api_projects.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
data_matcher,
1111
enumerate_async,
1212
mock_route,
13+
param_matcher,
1314
request_id_matcher,
1415
)
1516

@@ -70,8 +71,11 @@ async def test_get_projects(
7071
url=endpoint,
7172
json=page,
7273
status=200,
73-
params={"cursor": cursor} if cursor else {},
74-
matchers=[auth_matcher(), request_id_matcher()],
74+
matchers=[
75+
auth_matcher(),
76+
request_id_matcher(),
77+
param_matcher({"cursor": cursor} if cursor else {}),
78+
],
7579
)
7680
cursor = page["next_cursor"]
7781

@@ -111,10 +115,12 @@ async def test_search_projects(
111115
url=endpoint,
112116
json=page,
113117
status=200,
114-
params={"query": query} | ({"cursor": cursor} if cursor else {}),
115118
matchers=[
116119
auth_matcher(),
117120
request_id_matcher(),
121+
param_matcher(
122+
{"query": query} | ({"cursor": cursor} if cursor else {})
123+
),
118124
],
119125
)
120126
cursor = page["next_cursor"]
@@ -360,8 +366,11 @@ async def test_get_collaborators(
360366
url=endpoint,
361367
json=page,
362368
status=200,
363-
params={"cursor": cursor} if cursor else {},
364-
matchers=[auth_matcher(), request_id_matcher()],
369+
matchers=[
370+
auth_matcher(),
371+
request_id_matcher(),
372+
param_matcher({"cursor": cursor} if cursor else {}),
373+
],
365374
)
366375
cursor = page["next_cursor"]
367376

tests/test_api_sections.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
data_matcher,
1111
enumerate_async,
1212
mock_route,
13+
param_matcher,
1314
request_id_matcher,
1415
)
1516

@@ -70,8 +71,11 @@ async def test_get_sections(
7071
url=endpoint,
7172
json=page,
7273
status=200,
73-
params={"cursor": cursor} if cursor else {},
74-
matchers=[auth_matcher(), request_id_matcher()],
74+
matchers=[
75+
auth_matcher(),
76+
request_id_matcher(),
77+
param_matcher({"cursor": cursor} if cursor else {}),
78+
],
7579
)
7680
cursor = page["next_cursor"]
7781

@@ -111,10 +115,12 @@ async def test_get_sections_by_project(
111115
url=endpoint,
112116
json=page,
113117
status=200,
114-
params={"project_id": project_id} | ({"cursor": cursor} if cursor else {}),
115118
matchers=[
116119
auth_matcher(),
117120
request_id_matcher(),
121+
param_matcher(
122+
{"project_id": project_id} | ({"cursor": cursor} if cursor else {})
123+
),
118124
],
119125
)
120126
cursor = page["next_cursor"]
@@ -155,10 +161,12 @@ async def test_search_sections(
155161
url=endpoint,
156162
json=page,
157163
status=200,
158-
params={"query": query} | ({"cursor": cursor} if cursor else {}),
159164
matchers=[
160165
auth_matcher(),
161166
request_id_matcher(),
167+
param_matcher(
168+
{"query": query} | ({"cursor": cursor} if cursor else {})
169+
),
162170
],
163171
)
164172
cursor = page["next_cursor"]
@@ -200,11 +208,13 @@ async def test_search_sections_by_project(
200208
url=endpoint,
201209
json=page,
202210
status=200,
203-
params={"query": query, "project_id": project_id}
204-
| ({"cursor": cursor} if cursor else {}),
205211
matchers=[
206212
auth_matcher(),
207213
request_id_matcher(),
214+
param_matcher(
215+
{"query": query, "project_id": project_id}
216+
| ({"cursor": cursor} if cursor else {})
217+
),
208218
],
209219
)
210220
cursor = page["next_cursor"]

tests/test_api_shared_labels.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
auth_matcher,
1010
data_matcher,
1111
mock_route,
12+
param_matcher,
1213
request_id_matcher,
1314
)
1415

@@ -34,10 +35,10 @@ async def test_rename_shared_label(
3435
method="POST",
3536
url=endpoint,
3637
status=204,
37-
params={"name": name},
3838
matchers=[
3939
auth_matcher(),
4040
request_id_matcher(),
41+
param_matcher({"name": name}),
4142
data_matcher({"new_name": new_name}),
4243
],
4344
)

tests/test_api_tasks.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
data_matcher,
1818
enumerate_async,
1919
mock_route,
20+
param_matcher,
2021
request_id_matcher,
2122
)
2223

@@ -76,8 +77,11 @@ async def test_get_tasks(
7677
url=endpoint,
7778
json=page,
7879
status=200,
79-
params={"cursor": cursor} if cursor else {},
80-
matchers=[auth_matcher(), request_id_matcher()],
80+
matchers=[
81+
auth_matcher(),
82+
request_id_matcher(),
83+
param_matcher({"cursor": cursor} if cursor else {}),
84+
],
8185
)
8286
cursor = page["next_cursor"]
8387

@@ -132,10 +136,10 @@ async def test_get_tasks_with_filters(
132136
url=endpoint,
133137
json=page,
134138
status=200,
135-
params=params | ({"cursor": cursor} if cursor else {}),
136139
matchers=[
137140
auth_matcher(),
138141
request_id_matcher(),
142+
param_matcher(params | ({"cursor": cursor} if cursor else {})),
139143
],
140144
)
141145
cursor = page["next_cursor"]
@@ -196,10 +200,10 @@ async def test_filter_tasks(
196200
url=endpoint,
197201
json=page,
198202
status=200,
199-
params=params | ({"cursor": cursor} if cursor else {}),
200203
matchers=[
201204
auth_matcher(),
202205
request_id_matcher(),
206+
param_matcher(params | ({"cursor": cursor} if cursor else {})),
203207
],
204208
)
205209
cursor = page["next_cursor"]

tests/test_authentication.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from tests.data.test_defaults import DEFAULT_OAUTH_URL
9-
from tests.utils.test_utils import data_matcher, mock_route
9+
from tests.utils.test_utils import data_matcher, mock_route, param_matcher
1010
from todoist_api_python._core.endpoints import API_URL # Use new base URL
1111
from todoist_api_python.authentication import (
1212
get_auth_token,
@@ -84,12 +84,16 @@ async def test_revoke_auth_token(
8484
respx_mock,
8585
"DELETE",
8686
f"{API_URL}/access_tokens",
87-
params={
88-
"client_id": client_id,
89-
"client_secret": client_secret,
90-
"access_token": token,
91-
},
9287
status=200,
88+
matchers=[
89+
param_matcher(
90+
{
91+
"client_id": client_id,
92+
"client_secret": client_secret,
93+
"access_token": token,
94+
}
95+
)
96+
],
9397
)
9498

9599
result = revoke_auth_token(client_id, client_secret, token)

tests/test_http_requests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
auth_matcher,
1111
data_matcher,
1212
mock_route,
13+
param_matcher,
1314
request_id_matcher,
1415
)
1516
from todoist_api_python._core.http_requests import delete, get, post
@@ -30,10 +31,10 @@ def test_get_with_params(respx_mock: respx.MockRouter) -> None:
3031
url=EXAMPLE_URL,
3132
json=EXAMPLE_RESPONSE,
3233
status=200,
33-
params=EXAMPLE_PARAMS,
3434
matchers=[
3535
auth_matcher(),
3636
request_id_matcher(DEFAULT_REQUEST_ID),
37+
param_matcher(EXAMPLE_PARAMS),
3738
],
3839
)
3940

@@ -151,10 +152,10 @@ def test_delete_with_params(respx_mock: respx.MockRouter) -> None:
151152
method="DELETE",
152153
url=EXAMPLE_URL,
153154
status=204,
154-
params=EXAMPLE_PARAMS,
155155
matchers=[
156156
auth_matcher(),
157157
request_id_matcher(DEFAULT_REQUEST_ID),
158+
param_matcher(EXAMPLE_PARAMS),
158159
],
159160
)
160161

0 commit comments

Comments
 (0)