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(): diff --git a/todoist_api_python/models.py b/todoist_api_python/models.py index 186b7a1..ab32bd1 100644 --- a/todoist_api_python/models.py +++ b/todoist_api_python/models.py @@ -42,6 +42,23 @@ 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, + "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: