diff --git a/libs/agno/agno/tools/todoist.py b/libs/agno/agno/tools/todoist.py index bc4f55206f..a2224321bd 100644 --- a/libs/agno/agno/tools/todoist.py +++ b/libs/agno/agno/tools/todoist.py @@ -1,6 +1,6 @@ import json import os -from typing import List, Optional +from typing import Any, Dict, List, Optional from agno.tools import Toolkit from agno.utils.log import logger @@ -87,7 +87,7 @@ def create_task( content=content, project_id=project_id, due_string=due_string, priority=priority, labels=labels or [] ) # Convert task to a dictionary and handle the Due object - task_dict = { + task_dict: Dict[str, Any] = { "id": task.id, "content": task.content, "description": task.description, @@ -118,7 +118,7 @@ def get_task(self, task_id: str) -> str: """Get a specific task by ID.""" try: task = self.api.get_task(task_id) - task_dict = { + task_dict: Dict[str, Any] = { "id": task.id, "content": task.content, "description": task.description, @@ -145,7 +145,14 @@ def get_task(self, task_id: str) -> str: logger.error(f"Failed to get task: {str(e)}") return json.dumps({"error": str(e)}) - def update_task(self, task_id: str, **kwargs) -> str: + def update_task( + self, + task_id: str, + content: Optional[str] = None, + due_string: Optional[str] = None, + priority: Optional[int] = None, + labels: Optional[List[str]] = None, + ) -> str: """ Update an existing task. @@ -157,30 +164,10 @@ def update_task(self, task_id: str, **kwargs) -> str: str: JSON string containing the updated task """ try: - task = self.api.update_task(task_id=task_id, **kwargs) - task_dict = { - "id": task.id, - "content": task.content, - "description": task.description, - "project_id": task.project_id, - "section_id": task.section_id, - "parent_id": task.parent_id, - "order": task.order, - "priority": task.priority, - "url": task.url, - "comment_count": task.comment_count, - "creator_id": task.creator_id, - "created_at": task.created_at, - "labels": task.labels, - } - if task.due: - task_dict["due"] = { - "date": task.due.date, - "string": task.due.string, - "datetime": task.due.datetime, - "timezone": task.due.timezone, - } - return json.dumps(task_dict) + task = self.api.update_task( + task_id=task_id, content=content, due_string=due_string, priority=priority, labels=labels + ) + return json.dumps(task.__dict__) except Exception as e: logger.error(f"Failed to update task: {str(e)}") return json.dumps({"error": str(e)}) @@ -209,7 +196,7 @@ def get_active_tasks(self) -> str: tasks = self.api.get_tasks() tasks_list = [] for task in tasks: - task_dict = { + task_dict: Dict[str, Any] = { "id": task.id, "content": task.content, "description": task.description, diff --git a/libs/agno/tests/unit/tools/test_todoist_tools.py b/libs/agno/tests/unit/tools/test_todoist_tools.py index 09ddb9e26f..f6f6cb5de4 100644 --- a/libs/agno/tests/unit/tools/test_todoist_tools.py +++ b/libs/agno/tests/unit/tools/test_todoist_tools.py @@ -130,29 +130,44 @@ def test_get_task_success(todoist_tools, mock_todoist_api): def test_update_task_success(todoist_tools, mock_todoist_api): """Test successful task update.""" - mock_task = Mock() - mock_task.id = "123" - mock_task.content = "Updated Task" - mock_task.description = "Updated Description" - mock_task.project_id = "project_1" - mock_task.section_id = None - mock_task.parent_id = None - mock_task.order = 1 - mock_task.priority = 1 - mock_task.url = "https://todoist.com/task/123" - mock_task.comment_count = 0 - mock_task.creator_id = "user_1" - mock_task.created_at = "2024-01-01T10:00:00Z" - mock_task.labels = [] - mock_task.due = None - + # Create a simple object to represent the task + class MockTask: + def __init__(self): + self.__dict__ = { + "id": "123", + "content": "Updated Task", + "description": "Updated Description", + "project_id": "project_1", + "section_id": None, + "parent_id": None, + "order": 1, + "priority": 1, + "url": "https://todoist.com/task/123", + "comment_count": 0, + "creator_id": "user_1", + "created_at": "2024-01-01T10:00:00Z", + "labels": [], + "due": None + } + + mock_task = MockTask() mock_todoist_api.update_task.return_value = mock_task result = todoist_tools.update_task("123", content="Updated Task") result_data = json.loads(result) assert result_data["id"] == "123" - mock_todoist_api.update_task.assert_called_once_with(task_id="123", content="Updated Task") + assert result_data["content"] == "Updated Task" + assert result_data["project_id"] == "project_1" + + # Verify the API was called with correct parameters + mock_todoist_api.update_task.assert_called_once_with( + task_id="123", + content="Updated Task", + due_string=None, + priority=None, + labels=None + ) def test_close_task_success(todoist_tools, mock_todoist_api):