Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

todo-list-validation-fix-ag-2855 #2354

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 16 additions & 29 deletions libs/agno/agno/tools/todoist.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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.

Expand All @@ -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)})
Expand Down Expand Up @@ -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,
Expand Down
49 changes: 32 additions & 17 deletions libs/agno/tests/unit/tools/test_todoist_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down