From 3df57761f034d12be9183ca4aace69c8f0d204bf Mon Sep 17 00:00:00 2001 From: Eric Shtivelberg <295836+shedokan@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:19:10 +0200 Subject: [PATCH 1/3] add: Project.to_dict() --- todoist_api_python/models.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/todoist_api_python/models.py b/todoist_api_python/models.py index 186b7a1..653deca 100644 --- a/todoist_api_python/models.py +++ b/todoist_api_python/models.py @@ -42,6 +42,24 @@ def from_dict(cls, obj: dict[str, Any]): view_style=obj["view_style"], ) + def to_dict(self) -> dict[str, Any]: + return { + "color": self.color, + "comment_count": self.comment_count, + "comment_count": self.comment_count, + "id": self.id, + "is_favorite": self.is_favorite, + "is_inbox_project": self.is_inbox_project, + "is_shared": self.is_shared, + "is_team_inbox": self.is_team_inbox, + "can_assign_tasks": self.can_assign_tasks, + "name": self.name, + "order": self.order, + "parent_id": self.parent_id, + "url": self.url, + "view_style": self.view_style, + } + @dataclass class Section: From d38cbd7480bd97f90d66e1e84604123c053989b8 Mon Sep 17 00:00:00 2001 From: Eric Shtivelberg <295836+shedokan@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:26:53 +0200 Subject: [PATCH 2/3] Test: project.to_dict() --- tests/test_models.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 78d2ffa..2cfb1ea 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -44,19 +44,39 @@ def test_project_from_dict(): project = Project.from_dict(sample_data) - assert project.id == sample_data["id"] assert project.color == sample_data["color"] assert project.comment_count == sample_data["comment_count"] + assert project.id == sample_data["id"] assert project.is_favorite == sample_data["is_favorite"] - assert project.name == sample_data["name"] - assert project.is_shared == sample_data["is_shared"] - assert project.url == sample_data["url"] assert project.is_inbox_project == sample_data["is_inbox_project"] + assert project.is_shared == sample_data["is_shared"] assert project.is_team_inbox == sample_data["is_team_inbox"] + assert project.can_assign_tasks == sample_data["can_assign_tasks"] + assert project.name == sample_data["name"] assert project.order == sample_data["order"] assert project.parent_id == sample_data["parent_id"] + assert project.url == sample_data["url"] assert project.view_style == sample_data["view_style"] - assert project.can_assign_tasks == sample_data["can_assign_tasks"] + +def test_project_to_dict(): + sample_data = dict(DEFAULT_PROJECT_RESPONSE) + sample_data.update(unexpected_data) + + project = Project.from_dict(sample_data).to_dict() + + assert project["color"] == sample_data["color"] + assert project["comment_count"] == sample_data["comment_count"] + assert project["id"] == sample_data["id"] + assert project["is_favorite"] == sample_data["is_favorite"] + assert project["is_inbox_project"] == sample_data["is_inbox_project"] + assert project["is_shared"] == sample_data["is_shared"] + assert project["is_team_inbox"] == sample_data["is_team_inbox"] + assert project["can_assign_tasks"] == sample_data["can_assign_tasks"] + assert project["name"] == sample_data["name"] + assert project["order"] == sample_data["order"] + assert project["parent_id"] == sample_data["parent_id"] + assert project["url"] == sample_data["url"] + assert project["view_style"] == sample_data["view_style"] def test_section_from_dict(): From 7ee37a364e775d99b2effce78ce3311d46cbb7d4 Mon Sep 17 00:00:00 2001 From: Eric Shtivelberg <295836+shedokan@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:45:27 +0200 Subject: [PATCH 3/3] duplicate comment_count --- todoist_api_python/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/todoist_api_python/models.py b/todoist_api_python/models.py index 653deca..ab32bd1 100644 --- a/todoist_api_python/models.py +++ b/todoist_api_python/models.py @@ -46,7 +46,6 @@ def to_dict(self) -> dict[str, Any]: return { "color": self.color, "comment_count": self.comment_count, - "comment_count": self.comment_count, "id": self.id, "is_favorite": self.is_favorite, "is_inbox_project": self.is_inbox_project,