Skip to content

Commit 3a20d8f

Browse files
Merge pull request #199 from Doist/goncalossilva/x-request-id
2 parents b81d945 + ca80baa commit 3a20d8f

17 files changed

+381
-120
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Support for moving tasks, courtesy of @radiant-tangent
13+
- Re-add support for `X-Request-ID`
14+
- Configurable via `request_id_fn` API constructor argument
15+
- Defaults to random UUID v4
1316
- Automatic testing across all supported Python versions
1417

1518
### Fixed

tests/data/test_defaults.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class PaginatedItems(TypedDict):
1818

1919
DEFAULT_TOKEN = "some-default-token"
2020

21+
DEFAULT_REQUEST_ID = "f00dbeef-cafe-4bad-a555-deadc0decafe"
22+
2123
DEFAULT_DUE_RESPONSE = {
2224
"date": "2016-09-01",
2325
"timezone": "Europe/Moscow",

tests/test_api_async.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/test_api_comments.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
data_matcher,
1515
enumerate_async,
1616
param_matcher,
17+
request_id_matcher,
1718
)
1819
from todoist_api_python.models import Attachment
1920

@@ -40,7 +41,7 @@ async def test_get_comment(
4041
url=endpoint,
4142
json=default_comment_response,
4243
status=200,
43-
match=[auth_matcher()],
44+
match=[auth_matcher(), request_id_matcher()],
4445
)
4546

4647
comment = todoist_api.get_comment(comment_id)
@@ -74,6 +75,7 @@ async def test_get_comments(
7475
status=200,
7576
match=[
7677
auth_matcher(),
78+
request_id_matcher(),
7779
param_matcher({"task_id": task_id}, cursor),
7880
],
7981
)
@@ -120,6 +122,7 @@ async def test_add_comment(
120122
status=200,
121123
match=[
122124
auth_matcher(),
125+
request_id_matcher(),
123126
data_matcher(
124127
{
125128
"content": content,
@@ -166,7 +169,7 @@ async def test_update_comment(
166169
url=f"{DEFAULT_API_URL}/comments/{default_comment.id}",
167170
json=updated_comment_dict,
168171
status=200,
169-
match=[auth_matcher(), data_matcher(args)],
172+
match=[auth_matcher(), request_id_matcher(), data_matcher(args)],
170173
)
171174

172175
response = todoist_api.update_comment(comment_id=default_comment.id, **args)
@@ -195,7 +198,7 @@ async def test_delete_comment(
195198
method=responses.DELETE,
196199
url=endpoint,
197200
status=204,
198-
match=[auth_matcher()],
201+
match=[auth_matcher(), request_id_matcher()],
199202
)
200203

201204
response = todoist_api.delete_comment(comment_id)

tests/test_api_completed_tasks.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
import responses
1414

1515
from tests.data.test_defaults import DEFAULT_API_URL, PaginatedItems
16-
from tests.utils.test_utils import auth_matcher, enumerate_async, param_matcher
16+
from tests.utils.test_utils import (
17+
auth_matcher,
18+
enumerate_async,
19+
param_matcher,
20+
request_id_matcher,
21+
)
1722
from todoist_api_python._core.utils import format_datetime
1823

1924
if TYPE_CHECKING:
@@ -51,7 +56,7 @@ async def test_get_completed_tasks_by_due_date(
5156
url=endpoint,
5257
json=page,
5358
status=200,
54-
match=[auth_matcher(), param_matcher(params, cursor)],
59+
match=[auth_matcher(), request_id_matcher(), param_matcher(params, cursor)],
5560
)
5661
cursor = page["next_cursor"]
5762

@@ -111,7 +116,7 @@ async def test_get_completed_tasks_by_completion_date(
111116
url=endpoint,
112117
json=page,
113118
status=200,
114-
match=[auth_matcher(), param_matcher(params, cursor)],
119+
match=[auth_matcher(), request_id_matcher(), param_matcher(params, cursor)],
115120
)
116121
cursor = page["next_cursor"]
117122

tests/test_api_labels.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
data_matcher,
1212
enumerate_async,
1313
param_matcher,
14+
request_id_matcher,
1415
)
1516

1617
if TYPE_CHECKING:
@@ -66,7 +67,7 @@ async def test_get_labels(
6667
url=endpoint,
6768
json=page,
6869
status=200,
69-
match=[auth_matcher(), param_matcher({}, cursor)],
70+
match=[auth_matcher(), request_id_matcher(), param_matcher({}, cursor)],
7071
)
7172
cursor = page["next_cursor"]
7273

@@ -102,7 +103,11 @@ async def test_add_label_minimal(
102103
url=f"{DEFAULT_API_URL}/labels",
103104
json=default_label_response,
104105
status=200,
105-
match=[auth_matcher(), data_matcher({"name": label_name})],
106+
match=[
107+
auth_matcher(),
108+
request_id_matcher(),
109+
data_matcher({"name": label_name}),
110+
],
106111
)
107112

108113
new_label = todoist_api.add_label(name=label_name)
@@ -136,7 +141,11 @@ async def test_add_label_full(
136141
url=f"{DEFAULT_API_URL}/labels",
137142
json=default_label_response,
138143
status=200,
139-
match=[auth_matcher(), data_matcher({"name": label_name} | args)],
144+
match=[
145+
auth_matcher(),
146+
request_id_matcher(),
147+
data_matcher({"name": label_name} | args),
148+
],
140149
)
141150

142151
new_label = todoist_api.add_label(name=label_name, **args)
@@ -167,7 +176,7 @@ async def test_update_label(
167176
url=f"{DEFAULT_API_URL}/labels/{default_label.id}",
168177
json=updated_label_dict,
169178
status=200,
170-
match=[auth_matcher(), data_matcher(args)],
179+
match=[auth_matcher(), request_id_matcher(), data_matcher(args)],
171180
)
172181

173182
response = todoist_api.update_label(label_id=default_label.id, **args)

tests/test_api_projects.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
data_matcher,
1212
enumerate_async,
1313
param_matcher,
14+
request_id_matcher,
1415
)
1516

1617
if TYPE_CHECKING:
@@ -66,7 +67,7 @@ async def test_get_projects(
6667
url=endpoint,
6768
json=page,
6869
status=200,
69-
match=[auth_matcher(), param_matcher({}, cursor)],
70+
match=[auth_matcher(), request_id_matcher(), param_matcher({}, cursor)],
7071
)
7172
cursor = page["next_cursor"]
7273

@@ -102,7 +103,11 @@ async def test_add_project_minimal(
102103
url=f"{DEFAULT_API_URL}/projects",
103104
json=default_project_response,
104105
status=200,
105-
match=[auth_matcher(), data_matcher({"name": project_name})],
106+
match=[
107+
auth_matcher(),
108+
request_id_matcher(),
109+
data_matcher({"name": project_name}),
110+
],
106111
)
107112

108113
new_project = todoist_api.add_project(name=project_name)
@@ -131,7 +136,11 @@ async def test_add_project_full(
131136
url=f"{DEFAULT_API_URL}/projects",
132137
json=default_project_response,
133138
status=200,
134-
match=[auth_matcher(), data_matcher({"name": project_name})],
139+
match=[
140+
auth_matcher(),
141+
request_id_matcher(),
142+
data_matcher({"name": project_name}),
143+
],
135144
)
136145

137146
new_project = todoist_api.add_project(name=project_name)
@@ -164,7 +173,7 @@ async def test_update_project(
164173
url=f"{DEFAULT_API_URL}/projects/{default_project.id}",
165174
json=updated_project_dict,
166175
status=200,
167-
match=[auth_matcher(), data_matcher(args)],
176+
match=[auth_matcher(), request_id_matcher(), data_matcher(args)],
168177
)
169178

170179
response = todoist_api.update_project(project_id=default_project.id, **args)
@@ -198,7 +207,7 @@ async def test_archive_project(
198207
url=endpoint,
199208
json=archived_project_dict,
200209
status=200,
201-
match=[auth_matcher()],
210+
match=[auth_matcher(), request_id_matcher()],
202211
)
203212

204213
project = todoist_api.archive_project(project_id)
@@ -230,7 +239,7 @@ async def test_unarchive_project(
230239
url=endpoint,
231240
json=unarchived_project_dict,
232241
status=200,
233-
match=[auth_matcher()],
242+
match=[auth_matcher(), request_id_matcher()],
234243
)
235244

236245
project = todoist_api.unarchive_project(project_id)
@@ -257,7 +266,7 @@ async def test_delete_project(
257266
method=responses.DELETE,
258267
url=endpoint,
259268
status=204,
260-
match=[auth_matcher()],
269+
match=[auth_matcher(), request_id_matcher()],
261270
)
262271

263272
response = todoist_api.delete_project(project_id)
@@ -289,7 +298,7 @@ async def test_get_collaborators(
289298
url=endpoint,
290299
json=page,
291300
status=200,
292-
match=[auth_matcher(), param_matcher({}, cursor)],
301+
match=[auth_matcher(), request_id_matcher(), param_matcher({}, cursor)],
293302
)
294303
cursor = page["next_cursor"]
295304

tests/test_api_sections.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
data_matcher,
1212
enumerate_async,
1313
param_matcher,
14+
request_id_matcher,
1415
)
1516

1617
if TYPE_CHECKING:
@@ -66,7 +67,7 @@ async def test_get_sections(
6667
url=endpoint,
6768
json=page,
6869
status=200,
69-
match=[auth_matcher(), param_matcher({}, cursor)],
70+
match=[auth_matcher(), request_id_matcher(), param_matcher({}, cursor)],
7071
)
7172
cursor = page["next_cursor"]
7273

@@ -107,6 +108,7 @@ async def test_get_sections_by_project(
107108
status=200,
108109
match=[
109110
auth_matcher(),
111+
request_id_matcher(),
110112
param_matcher({"project_id": project_id}, cursor),
111113
],
112114
)
@@ -150,6 +152,7 @@ async def test_add_section(
150152
status=200,
151153
match=[
152154
auth_matcher(),
155+
request_id_matcher(),
153156
data_matcher({"name": section_name, "project_id": project_id} | args),
154157
],
155158
)
@@ -186,7 +189,7 @@ async def test_update_section(
186189
url=f"{DEFAULT_API_URL}/sections/{default_section.id}",
187190
json=updated_section_dict,
188191
status=200,
189-
match=[auth_matcher(), data_matcher(args)],
192+
match=[auth_matcher(), request_id_matcher(), data_matcher(args)],
190193
)
191194

192195
response = todoist_api.update_section(section_id=default_section.id, **args)
@@ -215,7 +218,7 @@ async def test_delete_section(
215218
method=responses.DELETE,
216219
url=endpoint,
217220
status=204,
218-
match=[auth_matcher()],
221+
match=[auth_matcher(), request_id_matcher()],
219222
)
220223

221224
response = todoist_api.delete_section(section_id)

0 commit comments

Comments
 (0)